本文整理汇总了C#中TextBox.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.Focus方法的具体用法?C# TextBox.Focus怎么用?C# TextBox.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextBox
的用法示例。
在下文中一共展示了TextBox.Focus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Show
public static DialogResult Show(string title, string promptText, ref string value, InputBoxValidation validation)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button button = new Button();
Button button1 = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
button.Text = "OK";
button1.Text = "Cancel";
button.DialogResult = DialogResult.OK;
button1.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
button.SetBounds(228, 72, 75, 23);
button1.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
button.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
Control.ControlCollection controls = form.Controls;
Control[] controlArray = new Control[] { label, textBox, button, button1 };
controls.AddRange(controlArray);
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = button;
form.CancelButton = button1;
if (validation != null)
{
form.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => {
if (form.DialogResult == DialogResult.OK)
{
string text = validation(textBox.Text);
bool flag = text != "";
bool flag1 = flag;
e.Cancel = flag;
if (flag1)
{
MessageBox.Show(form, text, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
textBox.Focus();
}
}
});
}
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
示例2: Show
public static DialogResult Show(string title, string promptText, ref string value,
InputBoxValidation validation)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300,label.Right+10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
if (validation != null) {
form.FormClosing += delegate(object sender, FormClosingEventArgs e) {
if (form.DialogResult == DialogResult.OK) {
string errorText = validation(textBox.Text);
if (e.Cancel = (errorText != "")) {
MessageBox.Show(form, errorText, "Validation Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox.Focus();
}
}
};
}
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
示例3: TestHighlightOfValueWhenFocused
public void TestHighlightOfValueWhenFocused()
{
NumericUpDown nud = DefaultNumericUpDownToTest;
nud.IsEnabled = true;
nud.Maximum = 500;
nud.Value = 244;
TextBox tb = new TextBox();
TestAsync(
nud,
() => tb = (TextBox)TestExtensions.GetChildrenByType(nud, typeof(TextBox)),
() => tb.Focus(),
() => Assert.AreEqual(nud.Value, Convert.ToDouble(tb.SelectedText, CultureInfo.CurrentCulture)));
}
示例4: TestTabbingOutNumericUpDown
public void TestTabbingOutNumericUpDown()
{
NumericUpDown nud = DefaultNumericUpDownToTest;
nud.DecimalPlaces = 1;
nud.Value = 50.8;
TextBox tb = new TextBox();
RepeatButton rb = new RepeatButton();
TestAsync(
nud,
() => tb = (TextBox)TestExtensions.GetChildrenByType(nud, typeof(TextBox)),
() => tb.Focus(),
() => rb = (RepeatButton)TestExtensions.GetChildrenByType(nud, typeof(RepeatButton)),
() => rb.Focus(),
() => Assert.IsFalse(rb.IsFocused));
}
示例5: IsDouble
/**
* Tarkistaa, onko syöte desimaalisluku ja olemassa.
*/
protected Boolean IsDouble(String input, TextBox sender)
{
if (sender == null)
{
return false;
}
if (input == null)
{
sender.Focus();
return false;
}
double number = 0;
if (input.Length > 0 && Double.TryParse(input, out number))
{
return true;
}
else
{
sender.Focus();
return false;
}
}
示例6: IsDecimal
public bool IsDecimal(TextBox textBox)
{
decimal number = 0m;
if (Decimal.TryParse(textBox.Text, out number))
{
return true;
}
MessageBox.Show("Går ej att konvertera");
textBox.Focus();
return false;
}
开发者ID:Zaitzewsky,项目名称:Informatik-B--Objektorienterad-programmering-med-C-,代码行数:11,代码来源:ValidatorTests.cs
示例7: CoerceInputTextOnLostFocus
public virtual void CoerceInputTextOnLostFocus()
{
NumericUpDown nud = new NumericUpDown { Maximum = 100, Minimum = 0, Value = 50 };
TextBox part = null;
TextBox other = new TextBox();
StackPanel panel = new StackPanel();
panel.Children.Add(nud);
panel.Children.Add(other);
TestAsync(
100,
panel,
() => part = nud.GetVisualDescendents().OfType<TextBox>().FirstOrDefault(),
() => Assert.IsNotNull(part, "Could not find TextBox template part!"),
() => part.Focus(),
() => part.Text = "999",
() => other.Focus(),
() => Assert.AreEqual(100, nud.Value, "NumericUpDown did not coerce the value to 100!"));
}
示例8: IsPresent
public bool IsPresent(TextBox textBox)
{
if (textBox.Text == "")
{
MessageBox.Show("ej tomma fält");
textBox.Focus();
return false;
}
return true;
}
开发者ID:Zaitzewsky,项目名称:Informatik-B--Objektorienterad-programmering-med-C-,代码行数:11,代码来源:ValidatorTests.cs
示例9: IsRSS
public bool IsRSS(TextBox textBox)
{
if (textBox.Text != "" && textBox.Text.Contains("/rss"))
{
return true;
}
MessageBox.Show("Fältet får inte vara tomt och måste innhehålla /Rss");
textBox.Focus();
return false;
}
开发者ID:Zaitzewsky,项目名称:Informatik-B--Objektorienterad-programmering-med-C-,代码行数:11,代码来源:ValidatorTests.cs
示例10: DoWellError
/// <summary>
/// 错误处理
/// </summary>
/// <param name="lblError">错误标签</param>
/// <param name="strError">错误信息</param>
/// <param name="txtFocus">错误的文本框</param>
private void DoWellError(Label lblError, AccountState state, TextBox txtFocus)
{
string strError = String.Empty;
strError = ShineKJ.Model.Power.Account.GetEnumValue.GetDescription((ShineKJ.Model.Power.Account.AccountState)state);
lblError.Text = strError;
txtPassword.Text = "";
txtFocus.Focus();
}
示例11: IsNotEmpty
/**
* Tarkistaa, että tekstisyöte on annettu.
*/
protected Boolean IsNotEmpty(String input, TextBox sender)
{
if (sender == null)
{
return false;
}
if (input == null)
{
sender.Focus();
return false;
}
if (input.Length > 0)
{
return true;
}
else
{
sender.Focus();
return false;
}
}
示例12: JumpToTextBox
void JumpToTextBox(TextBox textbox)
{
textbox.Focus();
textbox.SelectionLength = 0;
textbox.SelectionStart = textbox.Text.Length;
}
示例13: loadDatafromZipcode
private void loadDatafromZipcode(TextBox txtzipcode, HiddenField hdnZipCode, TextBox txtCity, DropDownList ddlcountry, DropDownList ddlprovince, TextBox txtfirstName, Label lblZipCode)
{
DataTable dt;
dt = OrganizationInfo.GetCityStateAndCountryByZipCode(txtzipcode.Text.Trim(), GlobalCountryID);
if (dt.Rows.Count > 0)
{
hdnZipCode.Value = Convert.ToString(dt.Rows[0]["ZipcodeID"]);
txtCity.Text = Convert.ToString(dt.Rows[0]["CityName"]);
if (ddlcountry.Items.FindByValue(Convert.ToString(dt.Rows[0]["CountryId"])) != null)
ddlcountry.SelectedValue = Convert.ToString(dt.Rows[0]["CountryId"]);
System.Data.SqlClient.SqlParameter[] prm;
prm = new System.Data.SqlClient.SqlParameter[1];
prm[0] = new System.Data.SqlClient.SqlParameter("@CountryId", ddlcountry.SelectedValue);
Utils.GetLookUpData<DropDownList>(ref ddlprovince, LookUps.State, prm);
prm = null;
if (ddlprovince.Items.FindByValue(Convert.ToString(dt.Rows[0]["StateId"])) != null)
ddlprovince.SelectedValue = Convert.ToString(dt.Rows[0]["StateId"]);
txtfirstName.Focus();
txtfirstName.Text = "";
lblZipCode.Text = "";
}
else
{
txtfirstName.Text = "";
lblZipCode.Text = ResourceMgr.GetError("* Zipcode does not exist.");
}
}
示例14: IsInteger
/**
* Tarkistaa, onko syöte kokonaisluku ja olemassa.
*/
protected Boolean IsInteger(String input, TextBox sender)
{
if (sender == null)
{
return false;
}
if (input == null)
{
sender.Focus();
return false;
}
int number = 0;
if (input.Length > 0 && Int32.TryParse(input, out number))
{
return true;
}
else
{
sender.Focus();
return false;
}
}
示例15: IsItInt
public bool IsItInt(TextBox textBox)
{
int number = 0;
if (Int32.TryParse(textBox.Text, out number))
{
return true;
}
MessageBox.Show("Går inte att konvertera till Int");
textBox.Focus();
return false;
}
开发者ID:Zaitzewsky,项目名称:Informatik-B--Objektorienterad-programmering-med-C-,代码行数:11,代码来源:ValidatorTests.cs