当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.Focus方法代码示例

本文整理汇总了C#中System.Windows.Forms.TextBox.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.Focus方法的具体用法?C# TextBox.Focus怎么用?C# TextBox.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.TextBox的用法示例。


在下文中一共展示了TextBox.Focus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateHostSiteForm

        public static void ValidateHostSiteForm(TextBox txtPath, TextBox txtPort, TextBox txtVirRoot, Form form, Action successHandler)
        {
            if (!Directory.Exists(txtPath.Text))
            {
                TaskDialog.Show("Specified path does not exist.", form.Text, string.Empty, TaskDialogButton.OK,
                                TaskDialogIcon.Information);

                txtPath.Focus();
                return;
            }


            int port = 0;

            if (!int.TryParse(txtPort.Text, out port) || port < 0 || port > 65535)
            {
                TaskDialog.Show("Specified port is not possible.", form.Text, "Valid input: 0-65535", TaskDialogButton.OK,
                                TaskDialogIcon.Information);

                txtPort.Focus();
                return;
            }

            if (txtVirRoot.Text.Length == 0 || !txtVirRoot.Text.StartsWith("/"))
            {
                TaskDialog.Show("Invalid virtual root.", form.Text, "It should start with a forward slash (Default: /).", TaskDialogButton.OK,
                TaskDialogIcon.Information);

                txtVirRoot.Focus();
                return;
            }

            successHandler();
        }
开发者ID:ccasalicchio,项目名称:Cassini-Original-Project,代码行数:34,代码来源:FormValidationUtility.cs

示例2: isPresentTextBox

        //data validation for textbox presence
        //extra logic for if the textbox is the color textbox
        public bool isPresentTextBox(TextBox textbox, string name)
        {
            if (textbox == txtColor)
            {
                if (textbox.Text == "")
                {
                    MessageBox.Show(name + " is a required field.  Enter N/A if not applicable.", "Error");
                    textbox.Clear();
                    textbox.Focus();
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                if (textbox.Text == "")
                {
                    MessageBox.Show(name + " is a required field", "Error");
                    textbox.Clear();
                    textbox.Focus();
                    return false;
                }
            }

            return true;
        }
开发者ID:jlarson497,项目名称:InventoryManagement,代码行数:31,代码来源:Form1.cs

示例3: IsDecimal

 // TODO: improve this IsDecimal method
 public bool IsDecimal(TextBox textBox, string name)
 {
     string s = textBox.Text;
     int decimalCount = 0;
     bool validDecimal = true;
     foreach (char c in s)
     {
         if (!(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5'
             || c == '6' || c == '7' || c == '8' || c == '9' || c == '.' || c == '$'
             || c == '%' || c == ',' || c == ' '))
         {
             validDecimal = false;
             break;
         }
         if (c == '.')
         {
             decimalCount++;
         }
     }
     if (validDecimal && decimalCount <= 1)
     {
         return true;
     }
     else
     {
         MessageBox.Show(name + " must be a decimal value.", "Entry Error");
         textBox.Focus();
         return false;
     }
 }
开发者ID:charlesamacon,项目名称:SampleWork,代码行数:31,代码来源:Form1.cs

示例4: SetUp

		public void SetUp()
		{
			m_TextBox = new TextBox();
			m_TextBox.CreateControl();
			m_TextBox.Focus();
			Application.DoEvents();
			m_Handler = new IbusDefaultEventHandler(m_TextBox);
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:8,代码来源:IbusDefaultEventHandlerTests.cs

示例5: CheckNullValue

        public static void CheckNullValue(TextBox textBox)
        {
            //textBox.ForeColor = Color.Red;
            //textBox.CharacterCasing = CharacterCasing.Normal;
            //textBox.Text = message;
            textBox.Focus();

        }
开发者ID:cuongpv88,项目名称:work,代码行数:8,代码来源:ValidationTextBox.cs

示例6: IsPresent

 public static bool IsPresent(TextBox textBox, string name)
 {
     if (textBox.Text == "") {
         MessageBox.Show(name + " is a required field", "Input Error");
         textBox.Focus();
         return false;
     }
     return true;
 }
开发者ID:NicholasLambell,项目名称:AS2_StudentScores,代码行数:9,代码来源:Validator.cs

示例7: CheckTextBoxEmpty

 public static bool CheckTextBoxEmpty(TextBox tb)
 {
     if (string.IsNullOrWhiteSpace(tb.Text.Trim()))
     {
         tb.Focus();
          return false;
     }
     return true;
 }
开发者ID:hongbao66,项目名称:ERP,代码行数:9,代码来源:global.cs

示例8: 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;
        }
开发者ID:EAGLE-I,项目名称:HandKNN,代码行数:57,代码来源:InputBox.cs

示例9: Parse

 public void Parse(TextBox tb)
 {
     int number;
     if (!Int32.TryParse(tb.Text, out number)) {
         MessageBox.Show("Vul een getal in!");
         tb.Text = "";
         tb.Focus();
     }
 }
开发者ID:Quantum1233,项目名称:VTM-frontend,代码行数:9,代码来源:FrontEnd.cs

示例10: IsValidTextBox

 /// <summary>
 /// Indicates whether the all Specified TextBoxes are not Empty/Null.
 /// </summary>
 /// <param name="Textbox">Textbox</param>
 /// <returns>
 /// Boolean Value
 /// </returns>
 public static bool IsValidTextBox(TextBox Textbox)
 {
     if (string.IsNullOrEmpty(Textbox.Text))
     {
         Textbox.Focus();
         return false;
     }
     return true;
 }
开发者ID:QasimAshraf18,项目名称:ControlValidation,代码行数:16,代码来源:Validation.cs

示例11: NextFocus

 public static void NextFocus(TextBox tb, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter && !bEnter)
     {
         bEnter = true;
         tb.Focus();
         tb.SelectAll();
     }
 }
开发者ID:vuchannguyen,项目名称:lg-py,代码行数:9,代码来源:SubFuntion.cs

示例12: EditTextbox

 public TextBox EditTextbox(TextBox txt)
 {
     if (txt.Text.ToUpper() != "VIC")
     {
         txt.Text = "Not the name I was expecting!";
         txt.Focus();
     }
     return txt;
 }
开发者ID:vicdaniel,项目名称:DelegatesAndClasses,代码行数:9,代码来源:Form1.cs

示例13: Show

        /// <summary>
        /// Muestra el 'InputTextBox'
        /// </summary>
        /// <param name="strTexto"> Texto a mostrar en el mensaje </param>
        /// <param name="strEncabezado"> Título del InputTextBox </param>
        /// <param name="strValor"> Texto ingresado </param>
        /// <param name="itbValidacion"> Delegado que valida lo ingresado en el InputTextBox </param>
        /// <returns>DialogResult</returns>
        public static DialogResult Show(string strTexto, string strEncabezado, ref string strValor, InputBoxValidation itbValidacion)
        {
            Form frmFormulario = new Form();
            Label lblEtiqueta = new Label();
            TextBox txtCajaTexto = new TextBox();
            Button btnOK = new Button();
            Button btnCancel = new Button();

            frmFormulario.Text = strEncabezado;
            lblEtiqueta.Text = strTexto;
            txtCajaTexto.Text = strValor;

            btnOK.Text = "OK";
            btnCancel.Text = "Cancel";
            btnOK.DialogResult = DialogResult.OK;
            btnCancel.DialogResult = DialogResult.Cancel;

            lblEtiqueta.SetBounds(9, 20, 372, 13);
            txtCajaTexto.SetBounds(12, 36, 372, 20);
            btnOK.SetBounds(228, 72, 75, 23);
            btnCancel.SetBounds(309, 72, 75, 23);

            lblEtiqueta.AutoSize = true;
            txtCajaTexto.Anchor = txtCajaTexto.Anchor | AnchorStyles.Right;
            btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            btnCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            frmFormulario.ClientSize = new Size(396, 107);
            frmFormulario.Controls.AddRange(new Control[] { lblEtiqueta, txtCajaTexto, btnOK, btnCancel });
            frmFormulario.ClientSize = new Size(Math.Max(300, lblEtiqueta.Right + 10), frmFormulario.ClientSize.Height);
            frmFormulario.FormBorderStyle = FormBorderStyle.FixedDialog;
            frmFormulario.StartPosition = FormStartPosition.CenterScreen;
            frmFormulario.MinimizeBox = false;
            frmFormulario.MaximizeBox = false;
            frmFormulario.AcceptButton = btnOK;
            frmFormulario.CancelButton = btnCancel;
            if (itbValidacion != null)
            {
                frmFormulario.FormClosing += delegate(object sender, FormClosingEventArgs e)
                {
                    if (frmFormulario.DialogResult == DialogResult.OK)
                    {
                        string errorText = itbValidacion(txtCajaTexto.Text);
                        if (e.Cancel = (errorText != ""))
                        {
                            MessageBox.Show(frmFormulario, errorText, "Mensaje",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtCajaTexto.Focus();
                        }
                    }
                };
            }
            DialogResult dialogResult = frmFormulario.ShowDialog();
            strValor = txtCajaTexto.Text;
            return dialogResult;
        }
开发者ID:sandtiago,项目名称:tesispucp,代码行数:64,代码来源:clsInputTextBox.cs

示例14: IsPresent

 public static bool IsPresent(TextBox textBox)
 {
     if (textBox.Text == "")
     {
         MessageBox.Show(textBox.Tag + " is a required field.", Title);
         textBox.Focus();
         return false;
     }
     return true;
 }
开发者ID:fakeshark,项目名称:CSharpProjects,代码行数:10,代码来源:Validator.cs

示例15: MileageDollarsContainsData

 //method to check for blank mileage total box
 public static bool MileageDollarsContainsData(TextBox textBox)
 {
     if (textBox.Text == "")
     {
         MessageBox.Show("You must click on the calculate button to get your mileage total before submitting.", Title);
         textBox.Focus();
         return false;
     }
     return true;
 }
开发者ID:houckster,项目名称:Expense-Summary-App,代码行数:11,代码来源:Validation.cs


注:本文中的System.Windows.Forms.TextBox.Focus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。