public static bool validateTime(MaskedTextBox MTB)
        {
            if (MTB.Text.Trim().Length == 1)
            {
                return(true);
            }

            if (!MTB.MaskFull)
            {
                GF.Error("กรุณากรอก 'เวลา' ให้ครบ !!");
                MTB.Select();
                return(false);
            }

            string[] tmp   = MTB.Text.Split(':');
            int      hours = Convert.ToInt32(tmp[0]);
            int      mins  = Convert.ToInt32(tmp[1]);

            if (hours < 0 || hours > 23)
            {
                GF.Error("ชั่วโมง ต้องอยู่ระหว่าง 00 ถึง 23 !!");
                MTB.Select();
                return(false);
            }

            if (mins < 0 || mins > 59)
            {
                GF.Error("นาที ต้องอยู่ระหว่าง 00 ถึง 59 !!");
                MTB.Select();
                return(false);
            }

            return(true);
        }
Example #2
0
 public bool J_IsBlankDateCheck(ref MaskedTextBox dateMaskedTextBox, string DisplayMessage, J_ShowMessage enmShowMessage)
 {
     if (dateMaskedTextBox.Text == "  /  /")
     {
         if (enmShowMessage == J_ShowMessage.YES)
         {
             commonService.J_UserMessage(DisplayMessage);
             dateMaskedTextBox.Select();
         }
         return(true);
     }
     else if (dateMaskedTextBox.Text == "  /  /    ")
     {
         if (enmShowMessage == J_ShowMessage.YES)
         {
             commonService.J_UserMessage(DisplayMessage);
             dateMaskedTextBox.Select();
         }
         return(true);
     }
     else if (dateMaskedTextBox.Text == "/  /")
     {
         if (enmShowMessage == J_ShowMessage.YES)
         {
             commonService.J_UserMessage(DisplayMessage);
             dateMaskedTextBox.Select();
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public static bool validateDateTime(MaskedTextBox MTB)
        {
            if (MTB.Text.Trim().Length == 4)
            {
                return(true);
            }

            if (!MTB.MaskFull)
            {
                GF.Error("กรุณากรอก 'วันที่' ให้ครบ !!");
                MTB.Select();
                return(false);
            }

            string[] tmp   = MTB.Text.Split('/');
            int      day   = Convert.ToInt32(tmp[0]);
            int      month = Convert.ToInt32(tmp[1]);
            int      year  = Convert.ToInt32(tmp[2]) - 543;

            if (day <= 0)
            {
                GF.Error("วันที่ ต้องมากกว่า 1 !!");
                MTB.Select();
                return(false);
            }

            if (month <= 0 || month > 12)
            {
                GF.Error("เดือน ต้องอยู่ระหว่าง 1-12 !!");
                MTB.Select();
                return(false);
            }

            if (year <= 0 || year > 9999)
            {
                GF.Error("ปี ต้องอยู่ระหว่าง 1-9999 !!");
                MTB.Select();
                return(false);
            }

            if (day > DateTime.DaysInMonth(year, month))
            {
                GF.Error("ปี " + (year + 543).ToString() + " เดือน " + month.ToString("00") + " มี " + DateTime.DaysInMonth(year, month).ToString("00") + " วัน !!");
                MTB.Select();
                return(false);
            }
            return(true);
        }
Example #4
0
 /// <summary>
 /// Prevent the cursor from being positioned in the middle of a masked textbox when
 /// the user clicks in it, if the control is empty
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public static void enter_MaskedTextBox(MaskedTextBox maskedtextbox_Target)
 {
     if (maskedtextbox_Target.Text == "  /  /")
     {
         maskedtextbox_Target.Select(0, 0);
     }
 }
 public TranslationWindow(int id)
 {
     openFD = new FolderBrowserDialog();
     table  = DBHilper.GetTable(id);
     Init();
     Word.Select();
 }
Example #6
0
 public void starttext(MaskedTextBox txt)
 {
     if (txt.Text.Length <= 0)
     {
         txt.Select(0, 0);
     }
 }
Example #7
0
        public static void NovoTextoMask(MaskedTextBox texto)
        {
            if (texto.Text.Length > 0)
            {
                char letra;
                //captura a última letra digitada
                letra = Convert.ToChar(texto.Text.Substring(texto.Text.Length - 1, 1));
                //verifica se há acento e remove
                char   novaLetra = RemoveAcentos(letra);
                string novoTexto = texto.Text.Substring(0, texto.Text.Length - 1);
                novoTexto += novaLetra;
                texto.Text = novoTexto;
                //verifica se o texto será convertido para maiúsculo ou minúsculo
                if (true)
                {
                    //converte para maiúsculo
                    texto.Text = texto.Text.ToUpper();
                }
                else
                {
                    //converte para minúsculo
                    //texto.Text = texto.Text.ToLower().Trim();
                }

                texto.Select(texto.Text.Length, 0);
            }
        }
Example #8
0
        public override void Register(Form form, int rowNumber)
        {
            base.Register(form, rowNumber);

            var newTextBox = new MaskedTextBox
            {
                Name               = FieldName,
                BeepOnError        = true,
                Left               = form.Width / 2,
                Top                = rowNumber * RowHeight + RowsTopMargin,
                Mask               = ValidationMask,
                AllowPromptAsInput = true,
                PromptChar         = ' ',
                HidePromptOnLeave  = true,
                Text               = InitialValue,
                ValidatingType     = ValidationType,
                ReadOnly           = !IsEnabled
            };

            // ReSharper disable PossibleNullReferenceException
            newTextBox.GotFocus += (sender, args) => (sender as MaskedTextBox).SelectAll();
            // ReSharper restore PossibleNullReferenceException

            form.Controls.Add(newTextBox);

            if (0 == rowNumber)
            {
                newTextBox.Select();
            }
        }
Example #9
0
 private void MaskedTextBox_Click(object sender, EventArgs e)
 {
     MaskedTextBox mtb = (MaskedTextBox)sender;
     string blankTimeMask = "  :";
     if (mtb.Text == blankTimeMask)
     {
         mtb.Select(0, 1000);
     }
 }
Example #10
0
        private static void FormatMaskedTextBox_AoClicar(object sender, EventArgs e)
        {
            MaskedTextBox mask = sender as MaskedTextBox;

            if (string.IsNullOrEmpty(mask.Text))
            {
                mask.Select(0, 0);
            }
        }
Example #11
0
 public bool J_IsMonthGreater(ref MaskedTextBox FromMonthMaskedTextBox, ref MaskedTextBox ToMonthMaskedTextBox, string DisplayText)
 {
     if (this.J_ConvertToIntYYYYMM(ToMonthMaskedTextBox.Text) < this.J_ConvertToIntYYYYMM(FromMonthMaskedTextBox.Text))
     {
         commonService.J_UserMessage(DisplayText);
         FromMonthMaskedTextBox.Select();
         return(false);
     }
     return(true);
 }
Example #12
0
        private void LeftAdjustCursor(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(MaskedTextBox))
            {
                MaskedTextBox snd = (MaskedTextBox)sender;

                snd.Text = "";
                snd.Select(0, 0);
            }
        }
Example #13
0
 private void PositionCursorInMaskedTextBox(MaskedTextBox mtb)
 {
     if (mtb != null)
     {
         mtb.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
         if (mtb.Text.Length <= 3)
         {
             mtb.Select(mtb.Text.Length + 1, 0);
         }
         if ((mtb.Text.Length > 3) && (mtb.Text.Length <= 6))
         {
             mtb.Select(mtb.Text.Length + 3, 0);
         }
         if (mtb.Text.Length > 6)
         {
             mtb.Select(mtb.Text.Length + 4, 0);
         }
     }
 }
Example #14
0
        public bool J_IsDateGreater(string FromDate, ref MaskedTextBox ToDateMaskedTextBox, string FromDateCaption, string ToDateCaption, string DisplayText, J_ShowMessage enmShowMessage)
        {
            if (this.J_IsBlankDateCheck(FromDate, "Please enter " + FromDateCaption + " !!", enmShowMessage) == true)
            {
                return(false);
            }
            else if (this.J_IsDateValid(FromDate) == false)
            {
                if (enmShowMessage == J_ShowMessage.YES)
                {
                    commonService.J_UserMessage("Please enter valid " + FromDateCaption + " !!");
                    ToDateMaskedTextBox.Select();
                }
                return(false);
            }

            if (this.J_IsBlankDateCheck(ref ToDateMaskedTextBox, "Please enter " + ToDateCaption + " !!", enmShowMessage) == true)
            {
                return(false);
            }
            else if (this.J_IsDateValid(ToDateMaskedTextBox) == false)
            {
                if (enmShowMessage == J_ShowMessage.YES)
                {
                    commonService.J_UserMessage("Please enter valid " + ToDateCaption + " !!");
                    ToDateMaskedTextBox.Select();
                }
                return(false);
            }

            if (this.J_ConvertToIntYYYYMMDD(ToDateMaskedTextBox) < this.J_ConvertToIntYYYYMMDD(FromDate))
            {
                if (enmShowMessage == J_ShowMessage.YES)
                {
                    commonService.J_UserMessage(DisplayText);
                    ToDateMaskedTextBox.Select();
                }
                return(false);
            }
            return(true);
        }
Example #15
0
        // Ensures user clicking in textbox is always at the current index
        private void CurserIndexCheck(object sender, EventArgs e)
        {
            MaskedTextBox box = sender as MaskedTextBox;

            try
            {
                box.Select(box.Text.Length, 0);
            }
            catch (Exception)
            {
            }
        }
        public static bool validateCardExpiry(MaskedTextBox MTB)
        {
            if (!MTB.MaskFull)
            {
                GF.Error("กรุณากรอก 'วันหมดอายุบัตร' ให้ครบ !!");
                MTB.Select();
                return(false);
            }

            string[] tmp   = MTB.Text.Split('/');
            var      month = Convert.ToInt32(tmp[0]);

            if (month <= 0 || month > 12)
            {
                GF.Error("เดือน ต้องอยู่ระหว่าง 1-12 !!");
                MTB.Select();
                return(false);
            }

            return(true);
        }
Example #17
0
        private void MaskedTextBox_Enter(object sender, EventArgs e)
        {
            MaskedTextBox mtb = (MaskedTextBox)sender;
            
            selectedControl = currentControl.IndexOf(mtb);
            RaiseInputRowSelectedEvent();

            BeginInvoke((MethodInvoker)(() =>
            {
                mtb.Select(0, 100);
            }
            ));
            changeBackgroundColour(true);
        }
Example #18
0
        public static void PositionCursorInMaskedTextBox(Form f, MaskedTextBox mtb)
        {
            if (mtb == null)
            {
                return;
            }

            int pos = mtb.SelectionStart;

            if (pos > mtb.Text.Length)
            {
                f.BeginInvoke((MethodInvoker) delegate() { mtb.Select(mtb.Text.Length, 0); });
            }
        }
Example #19
0
 private void ShortcutToInput(KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F1)
     {
         try
         {
             Panel         p = (Panel)this.Controls.Find("Panel1", true).FirstOrDefault();
             MaskedTextBox t = (MaskedTextBox)p.Controls.Find("txtYearin", true).FirstOrDefault();
             e.Handled = true;
             t.Select();
         }
         catch { }
     }
     else if (e.KeyCode == Keys.F2)
     {
         // txtID8.Select();
         try
         {
             Panel         p = (Panel)this.Controls.Find("Panel1", true).FirstOrDefault();
             MaskedTextBox t = (MaskedTextBox)p.Controls.Find("txtID8", true).FirstOrDefault();
             e.Handled = true;
             t.Select();
         }
         catch { }
     }
     else if (e.KeyCode == Keys.F3)
     {
         // txtName.Select();
         try
         {
             Panel   p = (Panel)this.Controls.Find("Panel1", true).FirstOrDefault();
             TextBox t = (TextBox)p.Controls.Find("txtName", true).FirstOrDefault();
             e.Handled = true;
             t.Select();
         }
         catch { }
     }
     else if (e.KeyCode == Keys.F4)
     {
         // txtSName.Select();
         try
         {
             Panel   p = (Panel)this.Controls.Find("Panel1", true).FirstOrDefault();
             TextBox t = (TextBox)p.Controls.Find("txtSName", true).FirstOrDefault();
             e.Handled = true;
             t.Select();
         }
         catch { }
     }
 }
Example #20
0
        public static void SetCursor(MaskedTextBox textBox)
        {
            if (textBox == null)
            {
                return;
            }

            int pos = textBox.SelectionStart;

            if (pos > textBox.Text.Length)
            {
                pos = textBox.Text.Length;
            }

            textBox.Select(pos, 0);
        }
Example #21
0
        private void ArgInputEntered(object sender, EventArgs e)
        {
            //This method will prevent the cursor from being positioned in the middle
            //of a textbox when the user clicks in it.
            MaskedTextBox textBox = sender as MaskedTextBox;

            if (textBox != null)
            {
                this.BeginInvoke((MethodInvoker) delegate()
                {
                    int pos = textBox.SelectionStart;
                    if (pos > textBox.Text.Length)
                    {
                        pos = textBox.Text.Length;
                    }

                    textBox.Select(pos, 0);
                });
            }
        }
Example #22
0
        public static void sb_control_gotFocused(object sender, EventArgs e)
        {
            if (sender is TextBox)
            {
                TextBox txt = (TextBox)sender;
                txt.SelectAll();
            }
            else if (sender is MaskedTextBox)
            {
                MaskedTextBox mskTxt = (MaskedTextBox)sender;
                //mskTxt.SelectAll();
                if (mskTxt.Text != "")
                {
                    mskTxt.Select(0, mskTxt.Text.Length);
                    mskTxt.SelectionStart  = 0;
                    mskTxt.SelectionLength = mskTxt.Text.Length;
                    mskTxt.SelectedText    = mskTxt.Text;
                }
            }
            else if (sender is ComboBox)
            {
                ComboBox cmbx = (ComboBox)sender;
                cmbx.SelectAll();
            }
            else if (sender is NumericUpDown)
            {
                NumericUpDown numeric = (NumericUpDown)sender;
                numeric.Select(0, numeric.Value.ToString().Length);
            }
            else if (sender is DateTimePicker)
            {
                DateTimePicker date = (DateTimePicker)sender;
                date.Select();
            }

            else
            {
                Control ctrl = (Control)sender;
                ctrl.Select();
            }
        }
Example #23
0
 private void Mark(int start, int lenght, MaskedTextBox txtDay)
 {
     txtDay.Focus();
     txtDay.Select(start, lenght);
 }
Example #24
0
        private void MaskedTextBox_Click(object sender, EventArgs e)
        {
            MaskedTextBox mtb = (MaskedTextBox)sender;

            mtb.Select(0, 0);
        }
Example #25
0
        static int Main(string[] args)
        {
            // Based on code by Gorkem Gencay on StackOverflow.com:
            // http://stackoverflow.com/questions/97097/what-is-the-c-sharp-version-of-vb-nets-inputdialog#17546909

            #region Initialize variables

            const string deftitle = "Title";
            const string deftext  = "Prompt";

            bool   heightset           = false;
            bool   showpassword        = false;
            bool   timeoutset          = false;
            bool   widthset            = false;
            string input               = string.Empty;
            string mask                = String.Empty;
            string showpasswordprompt  = "Show password";
            string text                = deftext;
            string title               = deftitle;
            int    height              = defheight;
            int    timeout             = 0;
            int    width               = defwidth;
            string cancelcaption       = "&Cancel";
            string okcaption           = "&OK";
            string localizationstring  = String.Empty;
            bool   localizedcaptionset = false;

            #endregion Initialize variables


            #region Command Line Parsing

            if (args.Length == 0)
            {
                return(ErrorMessage( ));
            }

            foreach (string arg in args)
            {
                if (arg == "/?")
                {
                    return(ErrorMessage( ));
                }
            }

            text      = String.Empty;
            title     = String.Empty;
            defanswer = String.Empty;

            foreach (string arg in args)
            {
                if (arg[0] == '/')
                {
                    if (arg.Length == 1)
                    {
                        return(ErrorMessage( ));
                    }
                    else if (arg.Length == 2)
                    {
                        switch (arg.ToString( ).ToUpper( ))
                        {
                        case "/A":
                            if (ASCIIonly)
                            {
                                return(ErrorMessage("Duplicate command line switch /A"));
                            }
                            ASCIIonly = true;
                            break;

                        case "/B":
                            if (bw)
                            {
                                return(ErrorMessage("Duplicate command line switch /B"));
                            }
                            bw   = true;
                            bold = Console.ForegroundColor;
                            break;

                        case "/L":
                            if (localizedcaptionset)
                            {
                                return(ErrorMessage("Duplicate command line switch /L"));
                            }
                            localizedcaptionset = true;
                            break;

                        case "/M":
                            return(HelpMessage("mask"));

                        case "/N":
                            if (!filtered)
                            {
                                return(ErrorMessage("Duplicate command line switch /N"));
                            }
                            filtered = false;
                            break;

                        case "/P":
                            if (password)
                            {
                                return(ErrorMessage("Duplicate command line switch /P"));
                            }
                            password = true;
                            break;

                        case "/S":
                            if (showpassword)
                            {
                                return(ErrorMessage("Duplicate command line switch /S"));
                            }
                            showpassword = true;
                            break;

                        case "/T":
                            if (timeoutset)
                            {
                                return(ErrorMessage("Duplicate command line switch /T"));
                            }
                            timeout    = deftimeout;
                            timeoutset = true;
                            break;

                        default:
                            return(ErrorMessage("Invalid command line switch {0}", arg));
                        }
                    }
                    else if (arg.Length == 3)
                    {
                        switch (arg.ToUpper( ))
                        {
                        case "/M:":
                            ErrorMessage("No mask specified with /M");
                            Console.WriteLine("\n\n");
                            return(HelpMessage("mask"));

                        default:
                            return(ErrorMessage("Invalid command line switch \"{0}\"", arg.ToUpper( )));
                        }
                    }
                    else
                    {
                        switch (arg.Substring(0, 3).ToUpper( ))
                        {
                        case "/H:":
                            if (heightset)
                            {
                                return(ErrorMessage("Duplicate command line switch /H"));
                            }
                            try
                            {
                                height = Convert.ToInt32(arg.Substring(3));
                                if (height < defheight || height > Screen.PrimaryScreen.Bounds.Height)
                                {
                                    return(ErrorMessage("Invalid screen height: \"{0}\"\n\tHeight must be an integer between {1} and {2} (screen height)", arg.Substring(3), defheight.ToString( ), Screen.PrimaryScreen.Bounds.Height.ToString( )));
                                }
                                heightset = true;
                            }
                            catch (FormatException e)
                            {
                                return(ErrorMessage("Invalid height: \"{0}\"\n\t{1}", arg.Substring(3), e.Message));
                            }
                            break;

                        case "/L:":
                            if (localizedcaptionset)
                            {
                                return(ErrorMessage("Duplicate command line switch /L"));
                            }
                            localizedcaptionset = true;
                            localizationstring  = arg.Substring(3);
                            break;

                        case "/M:":
                            if (usemask)
                            {
                                return(ErrorMessage("Duplicate command line switch /M"));
                            }
                            mask = arg.Substring(3).Trim("\"".ToCharArray( ));
                            if (String.IsNullOrWhiteSpace(mask))
                            {
                                ErrorMessage("No mask specified with /M");
                                Console.WriteLine("\n\n");
                                return(HelpMessage("mask"));
                            }
                            usemask = true;
                            break;

                        case "/R:":
                            if (regexset)
                            {
                                return(ErrorMessage("Duplicate command line switch /R"));
                            }
                            pattern  = arg.Substring(3);
                            regexset = true;
                            break;

                        case "/S:":
                            if (showpassword)
                            {
                                return(ErrorMessage("Duplicate command line switch /S"));
                            }
                            showpassword       = true;
                            showpasswordprompt = arg.Substring(3);
                            break;

                        case "/T:":
                            if (timeoutset)
                            {
                                return(ErrorMessage("Duplicate command line switch /T"));
                            }
                            try
                            {
                                timeout = Convert.ToInt32(arg.Substring(3)) * 1000;
                                if (timeout < 1000)
                                {
                                    return(ErrorMessage("Invalid timeout: \"{0}\"\n\tTimeout value must be a positive integer, at least 1.", arg.Substring(3)));
                                }
                                timeoutset = true;
                            }
                            catch (FormatException e)
                            {
                                return(ErrorMessage("Invalid timeout: \"{0}\"\n\t{1}", arg.Substring(3), e.Message));
                            }
                            break;

                        case "/W:":
                            if (widthset)
                            {
                                return(ErrorMessage("Duplicate command line switch /W"));
                            }
                            try
                            {
                                width = Convert.ToInt32(arg.Substring(3));
                                if (width < defwidth || width > Screen.PrimaryScreen.Bounds.Width)
                                {
                                    return(ErrorMessage("Invalid screen width: \"{0}\"\n\tWidth must be an integer between {1} and {2} (screen width)", arg.Substring(3), defwidth.ToString( ), Screen.PrimaryScreen.Bounds.Width.ToString( )));
                                }
                                widthset = true;
                            }
                            catch (FormatException e)
                            {
                                return(ErrorMessage("Invalid width: \"{0}\"\n\t{1}", arg.Substring(3), e.Message));
                            }
                            break;

                        default:
                            return(ErrorMessage("Invalid command line switch \"{0}\"", arg));
                        }
                    }
                }
                else
                {
                    if (String.IsNullOrWhiteSpace(text))
                    {
                        text = arg;
                    }
                    else if (String.IsNullOrWhiteSpace(title))
                    {
                        title = arg;
                    }
                    else if (String.IsNullOrWhiteSpace(defanswer))
                    {
                        defanswer = arg;
                    }
                    else
                    {
                        return(ErrorMessage("Invalid command line argument \"{0}\"", arg));
                    }
                }
            }

            // Default title if none specified
            if (String.IsNullOrWhiteSpace(title))
            {
                title = "© 2014 Rob van der Woude";
            }

            // "Bold" color depends on /BW
            if (bw)
            {
                bold = Console.ForegroundColor;
            }
            else
            {
                bold = ConsoleColor.White;
            }

            // Switch /A requires /M
            if (ASCIIonly && !usemask)
            {
                return(ErrorMessage("Command line switch /A (ASCII only) can only be used together with /M"));
            }

            // Switch /S implies /P
            if (showpassword)
            {
                password = true;
            }

            // Set timer if /T:timeout was specified
            if (timeoutset)
            {
                System.Timers.Timer timer = new System.Timers.Timer( );
                timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
                timer.Interval = timeout;
                timer.Start( );
            }

            // For /S (Show password checkbox) add 25 px to window height unless height is specified
            if (showpassword && !heightset)
            {
                height += 25;
            }

            #endregion Command Line Parsing


            #region Set Localized Captions

            if (localizedcaptionset)
            {
                cancelcaption = Load("user32.dll", 801, cancelcaption);
                okcaption     = Load("user32.dll", 800, okcaption);
                if (!String.IsNullOrWhiteSpace(localizationstring))
                {
                    string pattern = @"^((OK|Cancel)=[^;\""]*;)*((OK|Cancel)=[^;\""]*);?$";
                    Regex  regex   = new Regex(pattern, RegexOptions.IgnoreCase);
                    if (regex.IsMatch(localizationstring))
                    {
                        string[] locstrings = localizationstring.Split(";".ToCharArray( ));
                        foreach (string locstring in locstrings)
                        {
                            string key = locstring.Substring(0, locstring.IndexOf('='));
                            string val = locstring.Substring(Math.Min(locstring.IndexOf('=') + 1, locstring.Length - 1));
                            if (!String.IsNullOrWhiteSpace(val))
                            {
                                switch (key.ToUpper( ))
                                {
                                case "OK":
                                    okcaption = val;
                                    break;

                                case "CANCEL":
                                    cancelcaption = val;
                                    break;

                                default:
                                    return(ErrorMessage("Invalid localization key \"{0}\"", key));
                                }
                            }
                        }
                    }
                    else
                    {
                        return(ErrorMessage("Invalid localization string:\n\t{0}", localizationstring));
                    }
                }
            }

            #endregion Set Localized Captions


            #region Define Form

            Size size     = new Size(width, height);
            Form inputBox = new Form( );

            inputBox.FormBorderStyle = FormBorderStyle.FixedDialog;
            inputBox.MaximizeBox     = false;
            inputBox.MinimizeBox     = false;
            inputBox.StartPosition   = FormStartPosition.CenterParent;
            inputBox.ClientSize      = size;
            inputBox.Text            = title;

            Label labelPrompt = new Label( );
            labelPrompt.Size     = new Size(width - 20, height - 90);
            labelPrompt.Location = new Point(10, 10);
            labelPrompt.Text     = text.Replace("\\n", "\n");
            inputBox.Controls.Add(labelPrompt);

            textBox      = new TextBox( );
            textBox.Size = new Size(width - 20, 25);
            if (showpassword)
            {
                textBox.Location = new Point(10, height - 100);
            }
            else
            {
                textBox.Location = new Point(10, height - 75);
            }
            if (password)
            {
                textBox.PasswordChar = '*';
                if (showpassword)
                {
                    // Insert a checkbox with label "Show password" 25 px below the textbox
                    CheckBox checkbox = new CheckBox( );
                    checkbox.Checked  = false;
                    checkbox.Location = new Point(11, textBox.Location.Y + 25);
                    checkbox.Width    = inputBox.Width - 22;
                    checkbox.Click   += new EventHandler(checkbox_Click);
                    checkbox.Text     = showpasswordprompt;
                    inputBox.Controls.Add(checkbox);
                }
            }
            else
            {
                textBox.Text = defanswer;
            }

            maskedTextBox              = new MaskedTextBox( );
            maskedTextBox.Mask         = mask;
            maskedTextBox.Location     = textBox.Location;
            maskedTextBox.PasswordChar = textBox.PasswordChar;
            maskedTextBox.Text         = textBox.Text;
            maskedTextBox.Size         = textBox.Size;
            maskedTextBox.AsciiOnly    = ASCIIonly;

            if (usemask)
            {
                inputBox.Controls.Add(maskedTextBox);
            }
            else
            {
                inputBox.Controls.Add(textBox);
            }

            Button okButton = new Button( );
            okButton.DialogResult = DialogResult.OK;
            okButton.Name         = "okButton";
            okButton.Size         = new Size(80, 25);
            okButton.Text         = okcaption;
            okButton.Location     = new Point(width / 2 - 10 - 80, height - 40);
            inputBox.Controls.Add(okButton);

            Button cancelButton = new Button( );
            cancelButton.DialogResult = DialogResult.Cancel;
            cancelButton.Name         = "cancelButton";
            cancelButton.Size         = new Size(80, 25);
            cancelButton.Text         = cancelcaption;
            cancelButton.Location     = new Point(width / 2 + 10, height - 40);
            inputBox.Controls.Add(cancelButton);

            inputBox.AcceptButton = okButton;              // OK on Enter
            inputBox.CancelButton = cancelButton;          // Cancel on Esc
            inputBox.Activate( );
            inputBox.BringToFront( );
            inputBox.Focus( );

            if (usemask)
            {
                maskedTextBox.BringToFront( );                // Bug workaround
                maskedTextBox.Select(0, 0);                   // Move cursor to begin
                maskedTextBox.Focus( );
            }
            else
            {
                textBox.BringToFront( );                // Bug workaround
                textBox.Select(0, 0);                   // Move cursor to begin
                textBox.Focus( );
            }

            #endregion Define Form


            #region Show Dialog and Return Result

            DialogResult result = inputBox.ShowDialog( );
            if (result == DialogResult.OK)
            {
                int rc = ValidateAndShowResult( );
                return(rc);
            }
            else
            {
                if (timeoutelapsed)
                {
                    ValidateAndShowResult( );
                    return(3);
                }
                else
                {
                    return(2);
                }
            }

            #endregion Show Dialog and Return Result
        }
Example #26
0
        private static void FormatMaskedTextBox_Click(object sender, EventArgs e)
        {
            MaskedTextBox mask = sender as MaskedTextBox;

            mask.Select(0, 0);
        }
Example #27
0
 public void Select(int start, int length)
 {
     baseTextBox.Select(start, length);
 }
Example #28
0
        public void MaskedTextBoxSetCursor(object sender, EventArgs e)
        {
            MaskedTextBox masked = (MaskedTextBox)sender;

            masked.Select(0, 0);
        }