示例#1
0
        public static int GetMTBData(MaskedTextBox p_mtb, string p_memo, out double ret_value)
        {
            if (p_mtb.Text.Trim() == ".")
            {
                MessageBox.Show(p_memo + "输入框未填写数据", "漏填数据");
                p_mtb.SelectAll();
                p_mtb.Focus();
                ret_value = 0;
                return(-1);
            }
            double tmp;

            try
            {
                tmp = Convert.ToDouble(p_mtb.Text.Trim());
            }
            catch (Exception)
            {
                MessageBox.Show(p_memo + "输入框填写的数据不正确", "数据不规范");

                p_mtb.Focus();
                p_mtb.SelectAll();
                ret_value = 0;
                return(-1);
            }
            ret_value = tmp;
            return(0);//正确则返回0
        }
示例#2
0
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            try
            {
                string ColName = dataGridView1.Columns[e.ColumnIndex].Name;
                if (ColName.Equals("Column2"))
                {
                    maskedTextBox.Mask = "00\\/00\\/0000";
                    Rectangle rect = dataGridView1.GetCellDisplayRectangle(Column2.Index, e.RowIndex, true);
                    maskedTextBox.Location = rect.Location;
                    maskedTextBox.Size     = rect.Size;
                    maskedTextBox.Text     = "";
                    maskedTextBox.Focus();

                    if (dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                        maskedTextBox.Text = dataGridView1[Column2.Index, e.RowIndex].Value.ToString();
                    }
                    if (dataGridView1.CurrentRow.Cells[Column2.Name].Selected)
                    {
                        maskedTextBox.Visible = true;
                        maskedTextBox.Focus();
                    }
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("يرجى تصوير الخطأ ومراجعة المبرمج ، شكرا" + ee.Message, "ERROR 1007 Orders_Parchases", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
 // When the user clicks the list
 void list_Click(object sender, EventArgs e)
 {
     // Go back to filter if the list is empty
     if (list.Items.Count == 0)
     {
         filter.Focus();
     }
 }
        private bool validarNoDocumento(MaskedTextBox maskedTextBox, Label label)
        {
            bool valor = false;

            if (maskedTextBox.Text != ("") && maskedTextBox.Text != ("   -       -"))
            {
                string maskara    = maskedTextBox.Mask;
                string sinMaskara = maskedTextBox.Mask = "";
                int    len        = maskedTextBox.TextLength;

                if (len < 11)
                {
                    label.Text         = "El Número De Documento esta incompleto.";
                    label.ForeColor    = Color.Red;
                    maskedTextBox.Mask = maskara;
                    maskedTextBox.Focus();
                    valor = false;
                }
                else
                {
                    label.Text         = "Número De Documento";
                    label.ForeColor    = Color.LightSlateGray;
                    maskedTextBox.Mask = maskara;
                    valor = true;
                }
            }
            return(valor);
        }
示例#5
0
 public static void FocusMaskedTextBox(MaskedTextBox txt, string sLabel)
 {
     MessageBox.Show(sLabel + " is empty. Pls check the field.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     txt.BackColor = Color.Yellow;
     txt.ForeColor = Color.Red;
     txt.Focus();
 }
        public void TextBox_CaretIndex_Persists_When_Focus_Lost()
        {
            using (Start(FocusServices))
            {
                var target1 = new MaskedTextBox
                {
                    Template = CreateTemplate(),
                    Text     = "1234"
                };
                var target2 = new MaskedTextBox
                {
                    Template = CreateTemplate(),
                    Text     = "5678"
                };
                var sp = new StackPanel();
                sp.Children.Add(target1);
                sp.Children.Add(target2);

                target1.ApplyTemplate();
                target2.ApplyTemplate();

                var root = new TestRoot {
                    Child = sp
                };

                target2.Focus();
                target2.CaretIndex = 2;
                Assert.False(target1.IsFocused);
                Assert.True(target2.IsFocused);

                target1.Focus();

                Assert.Equal(2, target2.CaretIndex);
            }
        }
        private void mtxt_class_begin_time_TextChanged(object sender, EventArgs e)
        {
            MaskedTextBox msender = (MaskedTextBox)sender;

            DealWithColor(msender);
            if (msender.Text.Length == 5 && msender.ForeColor == Color.Black && GetControlCount <Label>() <= 19 && Convert.ToInt32(msender.Tag.ToString()) == GetControlCount <MaskedTextBox>())
            {
                MaskedTextBox newMtxt = new MaskedTextBox
                {
                    Mask      = "90:00",
                    Size      = new Size(68, 34),
                    TextAlign = System.Windows.Forms.HorizontalAlignment.Center,
                    Font      = new Font(new FontFamily("微软雅黑"), (float)12.10084),
                    Tag       = GetControlCount <MaskedTextBox>() + 1
                };
                groupBox1.Controls.Add(newMtxt);
                newMtxt.Location     = GetControlLocation(newMtxt.GetType());
                newMtxt.TextChanged += mtxt_class_begin_time_TextChanged;

                Label newLabel = new Label
                {
                    AutoSize = true,
                    Text     = "第" + (GetControlCount <Label>() - OTHER_LABLE_IN_GRUOP + 1).ToString() + "节课开始时间",
                    Font     = new Font(new FontFamily("微软雅黑"), (float)12.10084)
                };
                groupBox1.Controls.Add(newLabel);
                newLabel.Location = GetControlLocation(newLabel.GetType());

                newMtxt.Focus();
            }
        }
        private bool isValidTime(MaskedTextBox textbox, string ctrlName)
        {
            try
            {
                Regex checktime =
                    new Regex(@"^(([0-1][0-9])|([2][0-3])|(0)|(00)):(([0-5][0-9])|(0)|(00))$");

                if (checktime.IsMatch(textbox.Text.Trim()))
                {
                    return(true);
                }
                else
                {
                    textbox.Focus();
                    new MessageBox.MessageBoxBA().Show(ctrlName + " không hợp lệ", "Thông báo lỗi",
                                                       Taxi.MessageBox.MessageBoxButtonsBA.OK,
                                                       Taxi.MessageBox.MessageBoxIconBA.Error);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public void TextBox_Reveal_Password_Reset_When_Lost_Focus()
        {
            using (Start(FocusServices))
            {
                var target1 = new MaskedTextBox
                {
                    Template     = CreateTemplate(),
                    Text         = "1234",
                    PasswordChar = '*'
                };
                var target2 = new MaskedTextBox
                {
                    Template = CreateTemplate(),
                    Text     = "5678"
                };
                var sp = new StackPanel();
                sp.Children.Add(target1);
                sp.Children.Add(target2);

                target1.ApplyTemplate();
                target2.ApplyTemplate();

                var root = new TestRoot {
                    Child = sp
                };

                target1.Focus();
                target1.RevealPassword = true;

                target2.Focus();

                Assert.False(target1.RevealPassword);
            }
        }
示例#10
0
        /// <summary>
        /// Kiểm tra MaskedTextBox có dữ liệu nhập vào hay không có hỗ trợ MessageBox
        /// <code>
        /// <paramref name="format"/> Có thể là 1 pattern: VD: @"^[\w]{3}[-][\w]{7}$" (điền đúng, nhập sai)
        /// </code>
        /// <code>
        /// VD: Utils.MaskedTextBoxMSG(MaskedTextBox, @"^[\w]{3}[-][\w]{7}$", "Phone is invalid.", "Error");
        /// </code>
        /// <code>
        /// Cách dùng: if(Utils.MaskedTextBoxMSG(...)) { return; }
        /// </code>
        /// </summary>
        public static bool MaskedTextBoxMSG(MaskedTextBox input, string format, string msg, string title = "Error",
                                            MessageBoxButtons messageBoxButtons = MessageBoxButtons.OK,
                                            MessageBoxIcon messageBoxIcon       = MessageBoxIcon.Error)
        {
            string strInput = input.Text;
            bool   flag     = false;

            if (format.Contains("^") && format.Contains("$"))
            {
                if (!Regex.IsMatch(strInput, format))
                {
                    flag = true;
                }
            }
            else
            {
                if (format.Equals(strInput))
                {
                    flag = true;
                }
            }

            if (flag)
            {
                MSG(msg, title, messageBoxButtons, messageBoxIcon);
                input.Focus();
                return(flag);
                //return false; // Ngăn chăn xử lý trong if
            }

            return(flag);
        }
示例#11
0
        private void btnEntrar_Click(object sender, EventArgs e)
        {
            if (txtUser.Text != "")
            {
                if (!string.IsNullOrEmpty(txtPwd.Text.Replace(" ", "")))
                {
                    if (txtPwd.Text.Length > 3)
                    {
                        if (Sistema.VerificaLogin(txtUser.Text, txtPwd.Text))
                        {
                            string comando = "select id from tbl_usuarios where user = '******';";
                            Sistema.IDUsuarioLogado = int.Parse(Sistema.ConsultaSimples(comando));

                            Log.Login();

                            Hide();
                            ShowInTaskbar = false;

                            TInicial telaInicial = new TInicial();
                            telaInicial.ShowDialog();
                        }
                        else
                        {
                            txtPwd.Clear();
                            txtUser.Focus();
                        }
                    }
                    else
                    {
                        ListaErro.RetornaErro(27);
                        txtPwd.Clear();
                        txtPwd.Focus();
                    }
                }
                else
                {
                    ListaErro.RetornaErro(26);
                    txtPwd.Focus();
                }
            }
            else
            {
                ListaErro.RetornaErro(25);
                txtUser.Focus();
            }
        }
示例#12
0
 public void Limpiar(Control.ControlCollection Coleccion)
 {
     foreach (Control a in Coleccion)
     {
         if (a.Enabled == true && a is TextBox)
         {
             TextBox tx = (TextBox)a;
             tx.BackColor = Color.White;
             tx.Text      = "";
             tx.Enabled   = false;
             tx.Focus();
         }
         if (a.Enabled == true && a is RichTextBox)
         {
             RichTextBox tx = (RichTextBox)a;
             tx.BackColor = Color.White;
             tx.Text      = "";
             tx.Enabled   = false;
             tx.Focus();
         }
         if (a.Enabled == true && a is MaskedTextBox)
         {
             MaskedTextBox tx = (MaskedTextBox)a;
             tx.BackColor = Color.White;
             tx.Text      = "";
             tx.Enabled   = false;
             tx.Focus();
         }
         if (a.Enabled == true && a is ComboBox)
         {
             ComboBox cb = (ComboBox)a;
             cb.SelectedIndex = -1;
             cb.Text          = "";
             cb.Enabled       = false;
         }
         if (a.Enabled == true && a is DateTimePicker)
         {
             DateTimePicker dt = (DateTimePicker)a;
             dt.Format       = DateTimePickerFormat.Long;
             dt.CustomFormat = "";
             dt.Enabled      = false;
         }
         if (a.Enabled == true && a is CheckedListBox)
         {
             CheckedListBox chk = (CheckedListBox)a;
             while (chk.CheckedIndices.Count > 0)
             {
                 chk.SetItemChecked(chk.CheckedIndices[0], false);
             }
             chk.Enabled = false;
         }
         if (a.HasChildren)
         {
             Limpiar(a.Controls);
         }
     }
 }
示例#13
0
 public void CambiarTxt(ComboBox Actual, MaskedTextBox Nuevo)
 {
     Actual.Enabled   = false;
     Actual.BackColor = System.Drawing.Color.White;
     Nuevo.Enabled    = true;
     Nuevo.BackColor  = System.Drawing.Color.Turquoise;
     Nuevo.Focus();
     Nuevo.SelectAll();
 }
 protected /*override*/ void CustomEditor_Click(object sender, EventArgs e)
 {
     if (null == RunExtEditor)
     {
         return;
     }
     _maskedTextBox.Text = RunExtEditor(EditNode, _maskedTextBox.Text, _editMethod);
     _maskedTextBox.Focus();
 }
示例#15
0
 // Phone Number validator
 public static void IsValidPhone(MaskedTextBox txtInput, int size)
 {
     if (txtInput.TextLength != size)
     {
         // tirar depois
         MessageBox.Show("The Phone Number number must have *number digits.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtInput.Clear();
         txtInput.Focus();
     }
 }
示例#16
0
 public bool vazio(MaskedTextBox txb)
 {
     if (string.IsNullOrEmpty(txb.Text))
     {
         Mensagem("Atenção! Informe todos os campos necessários para o cálculo!", false);
         txb.Focus();
         return(true);
     }
     return(false);
 }
示例#17
0
 /// <summary>
 /// Checks Serial number box to make sure it is completed
 /// </summary>
 /// <param name="textBox"></param>
 /// <returns></returns>
 public static bool IsPresentMask(MaskedTextBox textBox)
 {
     if (!textBox.MaskCompleted)
     {
         MessageBox.Show(textBox.Tag + " is a required field",
                         "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         textBox.Focus();
         return(false);
     }
     return(true);
 }
示例#18
0
 public static bool IsMaskPresent(MaskedTextBox mask)
 {
     theTruth = true;
     if (!mask.MaskFull)
     {
         MessageBox.Show(mask.Tag.ToString() + " must be completely filled out", "Input Error");
         mask.Focus();
         return(false);
     }
     return(theTruth);
 }
示例#19
0
        public static bool IsPresent(Control control)
        {
            if (control.GetType().ToString() == "MetroFramework.Controls.MetroTextBox")
            {
                var textBox = (MetroTextBox)control;
                if (textBox.Text == "")
                {
                    // MessageBox.Show(textBox.Tag + @" is a required field.", Title);

                    errProvider.SetError(textBox, textBox.Tag + @" is a required field.");
                    textBox.Focus();
                    textBox.SelectAll();
                    return(false);
                }
                else
                {
                    errProvider.SetError(textBox, "");
                    return(true);
                }
            }
            else if (control.GetType().ToString() == "MetroFramework.Controls.MetroComboBox")
            {
                var comboBox = (MetroComboBox)control;
                if (comboBox.Text == "")
                {
                    //MessageBox.Show(comboBox.Tag.ToString() + " is a required field.", Title);
                    errProvider.SetError(comboBox, comboBox.Tag + @" is a required field.");
                    comboBox.Focus();
                    comboBox.SelectAll();
                    return(false);
                }
                else
                {
                    errProvider.SetError(comboBox, "");
                    return(true);
                }
            }
            else if (control.GetType().ToString() == "System.Windows.Forms.MaskedTextBox")
            {
                MaskedTextBox makBox = (MaskedTextBox)control;
                if (makBox.Text == "")
                {
                    errProvider.SetError(makBox, makBox.Tag + @" is a required field ");
                    makBox.Focus();
                    makBox.SelectAll();
                }
                else
                {
                    errProvider.SetError(makBox, "");
                    return(true);
                }
            }
            return(true);
        }
示例#20
0
 public void txtIsNotFullFilledValidation(MaskedTextBox txtToValidate, String txtName)
 {
     if (!txtToValidate.MaskFull)
     {
         if (MessageBox.Show("Kolom " + txtName + "Harus diisi Penuh", "Peringatan Kolom Tidak Terisi Penuh",
                             MessageBoxButtons.OK, MessageBoxIcon.Stop) == DialogResult.OK)
         {
             txtToValidate.Focus();
         }
     }
 }
示例#21
0
        public static bool DateFormat(MaskedTextBox maskedTextBox)
        {
            DateTime dt;

            if (!DateTime.TryParseExact(maskedTextBox.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
            {
                MessageBox.Show($"{maskedTextBox} Date is not formated dd/mm/yyyy", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                maskedTextBox.Focus();
                return(true);
            }
            return(false);
        }
示例#22
0
        /// <summary>
        /// Inserts new customer to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            //Check input isn't blank
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    TextBox t = (TextBox)c;
                    if (t.Text == "")
                    {
                        lblStatus.Text = t.Tag + " can't be blank";
                        t.Focus();
                        return;
                    }
                }
                if (c is MaskedTextBox)
                {
                    MaskedTextBox mt = (MaskedTextBox)c;
                    if (mt.MaskFull == false)
                    {
                        lblStatus.Text = mt.Tag + " can't be blank";
                        mt.Focus();
                        return;
                    }
                }
            }
            //Set fields
            string firstName   = txtFirstName.Text;
            string lastName    = txtLastName.Text;
            string phoneNumber = txtPhoneNumber.Text;
            string address     = txtAddress.Text;
            string city        = txtCity.Text;
            string state       = txtState.Text;
            string zipCode     = txtZipCode.Text;
            string email       = txtEmail.Text;

            //Add new customer to database
            try
            {
                adapter.Insert(firstName, lastName, phoneNumber, address, city, state, zipCode, email);
            }
            catch
            {
                lblStatus.Text = "Error adding customer";
            }

            //Close form, open Customer form
            this.Hide();
            CustomerForm formCustomer = new CustomerForm();

            formCustomer.ShowDialog();
        }
 //  internal methods
 // 输入焦点应当从当前的列表项转移到前一个列表项
 private void textTitle_PreviousControl(object sender, TabbedControlNavigateEventArgs e)
 {
     e.Processed = false;
     if (((this.SelectedIndex != -1) &&
          (this.SelectedIndex > 0)))
     {
         this.SelectedIndex--;
         //  set focus to date field since moving 'back'
         _textDate.Focus();
         _textDate.SelectAll();
         e.Processed = true;
     }
 }
示例#24
0
        /// <summary>
        /// Kiểm tra MaskedTextBox đúng định dạng DateTime hay không có hỗ trợ MessageBox
        /// </summary>
        public static bool MaskedTextBoxDateTimeMSG(MaskedTextBox input, string msg, string title = "Error",
                                                    MessageBoxButtons messageBoxButtons           = MessageBoxButtons.OK,
                                                    MessageBoxIcon messageBoxIcon = MessageBoxIcon.Error)
        {
            if (!CheckIsDateTime(input.Text))
            {
                MSG(msg, title, messageBoxButtons, messageBoxIcon);
                input.Focus();
                return(false); // Ngăn chăn xử lý trong if
            }

            return(true);
        }
示例#25
0
        public static bool Campo(MaskedTextBox mskBox, string msg, int comp)
        {
            string txt = mskBox.Text.Trim();

            if ((string.IsNullOrEmpty(txt)) || (txt.Length != comp))
            {
                mskBox.BackColor = System.Drawing.Color.Yellow;
                Util.MensagemErro("Campo " + msg + " Vazio ou inválido!");
                mskBox.BackColor = System.Drawing.Color.White;
                mskBox.Focus();
                return(false);
            }
            return(true);
        }
 public static bool ControlValidate(MaskedTextBox txtBox, string message, ErrorProvider ep)
 {
     if (Convert.ToString(txtBox.Text).Contains("_"))
     {
         ep.SetError(txtBox, $"{message}");
         txtBox.Focus();
         txtBox.SelectAll();
         return(false);
     }
     else
     {
         return(true);
     }
 }
示例#27
0
 public static bool IsDate(MaskedTextBox textBox)
 {
     try
     {
         DateTime.Parse(textBox.Text);
         return(true);
     }
     catch (FormatException)
     {
         MessageBox.Show(textBox.Tag.ToString() + " is not a valid date.");
         textBox.Focus();
         return(false);
     }
 }
示例#28
0
 private void Login()
 {
     if (pwBox.Text == "system11")
     {
         // The password is ok.
         this.DialogResult = DialogResult.OK;
     }
     else
     {
         // The password is invalid.
         pwBox.Clear();
         MessageBox.Show("Inivalid password.");
         pwBox.Focus();
     }
 }
示例#29
0
        /// <summary>
        /// Indicates whether the Specified single TextBox is not Empty/Null.
        /// </summary>
        /// <param name="maskedTextBox">MaskedTextBox</param>
        /// <returns>
        /// Boolean Value
        /// </returns>
        public static bool IsValidMaskedTextBox(MaskedTextBox maskedTextBox)
        {
            bool result = false;

            if (!maskedTextBox.MaskCompleted)
            {
                maskedTextBox.Focus();
                result = false;
            }
            else
            {
                result = true;
            }
            return(result);
        }
示例#30
0
        /// <summary>
        /// Updates a given customer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //Check input isn't blank
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    TextBox t = (TextBox)c;
                    if (t.Text == "")
                    {
                        lblStatus.Text = t.Tag + " can't be blank";
                        return;
                    }
                }
                if (c is MaskedTextBox)
                {
                    MaskedTextBox mt = (MaskedTextBox)c;
                    if (mt.MaskFull == false)
                    {
                        lblStatus.Text = mt.Tag + " can't be blank";
                        mt.Focus();
                        return;
                    }
                }
            }

            //Set to given customer ID
            int cID = customerID;

            //Set fields to entered data
            string firstName   = txtFirstName.Text;
            string lastName    = txtLastName.Text;
            string phoneNumber = txtPhoneNumber.Text;
            string address     = txtAddress.Text;
            string city        = txtCity.Text;
            string state       = txtState.Text;
            string zipCode     = txtZipCode.Text;
            string email       = txtEmail.Text;

            //Update Customer
            customerAdapter.UpdateCust(firstName, lastName, phoneNumber, address, city, state, zipCode, email, customerID);

            //Close form and display Customer form
            this.Hide();
            CustomerForm cf = new CustomerForm();

            cf.ShowDialog();
        }