public void checkNumeric(System.Windows.Controls.TextBox txt, System.Windows.Controls.Label lbl, bool isRequired)
        {
            try
            {
                if (txt.Text == "")
                {
                    lbl.Content = "";
                    return;
                }
                bool err = false;
                int res;
                String str = txt.Text;
                err = !int.TryParse(str, out res);
                int n = 0;
                n = int.Parse(str);

                if (isRequired == true)
                {
                    if (String.IsNullOrWhiteSpace(str))
                        err = true;
                }

                if (err == true)
                {

                    lbl.Content = "?";
                    lbl.ToolTip = "Please enter numeric values only";
                    lbl.Focus();
                    lbl.Foreground = System.Windows.Media.Brushes.Red;
                    lbl.FontWeight = FontWeights.ExtraBold;
                }
                else
                {
                    n = int.Parse(str);
                    if (n <= 0)
                    {
                        lbl.Content = "?";
                        lbl.ToolTip = "Value must be greater than 1";
                        lbl.Focus();
                        lbl.Foreground = System.Windows.Media.Brushes.Red;
                        lbl.FontWeight = FontWeights.ExtraBold;
                        return;
                    }
                    lbl.Content = "✔";
                    lbl.Foreground = System.Windows.Media.Brushes.Green;
                }
            }
            catch (Exception ex)
            {

            }
        }
示例#2
0
        public static void Find1(string strRegex, bool isRegex, bool caseSensive,
            System.Windows.Forms.TextBox txtEdit, string ArticleName)
        {
            string ArticleText = txtEdit.Text;

            RegexOptions regOptions;

            if (caseSensive)
                regOptions = RegexOptions.None;
            else
                regOptions = RegexOptions.IgnoreCase;

            strRegex = Tools.ApplyKeyWords(ArticleName, strRegex);

            if (!isRegex)
                strRegex = Regex.Escape(strRegex);

            if (MatchObj == null || RegexObj == null)
            {
                int findStart = txtEdit.SelectionStart;

                RegexObj = new Regex(strRegex, regOptions);
                MatchObj = RegexObj.Match(ArticleText, findStart);
                txtEdit.SelectionStart = MatchObj.Index;
                txtEdit.SelectionLength = MatchObj.Length;
                txtEdit.Focus();
                txtEdit.ScrollToCaret();
                return;
            }
            else
            {
                if (MatchObj.NextMatch().Success)
                {
                    MatchObj = MatchObj.NextMatch();
                    txtEdit.SelectionStart = MatchObj.Index;
                    txtEdit.SelectionLength = MatchObj.Length;
                    txtEdit.Focus();
                    txtEdit.ScrollToCaret();
                }
                else
                {
                    txtEdit.SelectionStart = 0;
                    txtEdit.SelectionLength = 0;
                    txtEdit.Focus();
                    txtEdit.ScrollToCaret();
                    ResetFind();
                }
            }
        }
示例#3
0
 public static bool SomenteNumeros(System.Windows.Forms.TextBox ttb)
 {
     if (!NumeralValido(ttb.Text))
     {
         MessageBox.Show(ttb.Name.Substring(3) + " invalido, digite somente numeros", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ttb.Focus();
         return false;
     }
     return true;
 }
示例#4
0
 public static bool StringVazia(System.Windows.Forms.TextBox ttb,string msg)
 {
     if (ttb.Text.Trim() == "")
     {
         MessageBox.Show(msg, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ttb.Focus();
         return true;
     }
     return false;
 }
示例#5
0
 public static bool CheckFileName(System.Windows.Forms.Control Control, string message)
 {
     // 返回值
     bool returnValue = true;
     string fileName = Control.Text;
     if (!ValidateUtil.CheckFileName(fileName))
     {
         MessageBox.Show(message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
         Control.Focus();
         returnValue = false;
     }
     return returnValue;
 }
示例#6
0
 /// <summary>
 /// 判断字符串是否为电子邮件地址
 /// </summary>
 /// <param name="Control">输入控件</param>
 /// <param name="message">提示信息</param>
 /// <returns>是否电子邮件地址</returns>
 public static bool CheckEmail(System.Windows.Forms.Control Control, string message)
 {
     // 返回值
     bool returnValue = true;
     string email = Control.Text;
     // 文件夹名字验证,需要多一些才可以
     if (!ValidateUtil.IsEmail(email))
     {
         MessageBox.Show(message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
         Control.Focus();
         returnValue = false;
     }
     return returnValue;
 }
    // If textbox data is an alpha string
    /* Author: Pooja Jairath */
    // Defining the function to check if city name is valid, contains only alphabets and spaces
    public static bool IsCity(System.Web.UI.WebControls.TextBox textBox, string name)
    {
        Regex r = new Regex("^[a-zA-Z -.]|[A-Za-z -.]+$");
        if (r.IsMatch(textBox.Text))
        {
            message = "";
            return true;
        }
        else
            message = name + " should be contain characters only.";

        textBox.Focus();
        return false;
    }
示例#8
0
 /// <summary>
 /// 判断字符串是否为空
 /// </summary>
 /// <param name="Control">输入控件</param>
 /// <param name="message">提示信息</param>
 /// <returns>是否为空</returns>
 public static bool CheckEmpty(System.Windows.Forms.Control Control, string message)
 {
     // 返回值
     bool returnValue = true;
     if (Control.Text.Length == 0)
     {
         returnValue = false;
         Control.Focus();
         Control.Select();
         if (message.Length > 0)
         {
             System.Windows.Forms.MessageBox.Show(message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     return returnValue;
 }
        public void checkEmail(System.Windows.Controls.TextBox txt, System.Windows.Controls.Label lbl, bool isRequired)
        {
            try
            {
                if (txt.Text == "")
                {
                    lbl.Content = "";
                    return;
                }
                bool err = false;
                String str = txt.Text;
                str = str.Replace(" ", "");
                str = str.Trim();
                str = str.ToLower();
                txt.Text = str;
                if (!Regex.IsMatch(str, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
                    err = true;

                if (isRequired == true)
                {
                    if (String.IsNullOrWhiteSpace(str))
                        err = true;
                }

                if (err == true)
                {
                    lbl.Content = "?";
                    lbl.ToolTip = "Please enter the correct email format([email protected])";
                    lbl.Focus();
                    lbl.Foreground = System.Windows.Media.Brushes.Red;
                    lbl.FontWeight = FontWeights.ExtraBold;
                }
                else
                {
                    lbl.Content = "✔";
                    lbl.Foreground = System.Windows.Media.Brushes.Green;
                }
            }
            catch (Exception ex)
            {

            }
        }
示例#10
0
 public static bool CheckPasswordStrength(System.Windows.Forms.Control Control)
 {
     // 返回值
     bool returnValue = true;
     string password = Control.Text;
     if (!ValidateUtil.CheckPasswordStrength(password))
     {
         MessageBox.Show(AppMessage.MSG8000, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
         Control.Focus();
         returnValue = false;
     }
     return returnValue;
 }
示例#11
0
 public void AssignControlUntilFocusChange(System.Windows.Forms.Control control)
 {
     MethodInvoker method = delegate {
         if (!control.Focus())
         {
             control.Focus();
         }
         control.LostFocus += delegate {
             this.Control = null;
             control.Dispose();
         };
     };
     control.HandleCreated += delegate {
         control.BeginInvoke(method);
     };
     this.Control = control;
 }
        private void ChangeTextProperty(System.Windows.Controls.RichTextBox rtbuse,DependencyProperty dp, string value)
        {
            if (rtbuse == null) return;

            TextSelection ts = rtbuse.Selection;
            if (ts != null)
                ts.ApplyPropertyValue(dp, value);
            rtbuse.Focus();
        }
示例#13
0
        // Based upon http://www.knowdotnet.com/articles/listviewmoveitem.html
        public static void MoveSelectedItem(System.Windows.Forms.ListView lv, int idx, bool moveUp)
        {
            // Gotta have >1 item in order to move
            if (lv.Items.Count > 1)
            {
                int offset = 0;
                if (idx >= 0)
                {
                    if (moveUp)
                    {
                        // ignore moveup of row(0)
                        offset = -1;
                    }
                    else
                    {
                        // ignore movedown of last item
                        if (idx < (lv.Items.Count - 1))
                            offset = 1;
                    }
                }

                if (offset != 0)
                {
                    lv.BeginUpdate();

                    int selitem = idx + offset;
                    if (selitem >= 0)
                    {
                        for (int i = 0; i < lv.Items[idx].SubItems.Count; i++)
                        {
                            string cache = lv.Items[selitem].SubItems[i].Text;
                            lv.Items[selitem].SubItems[i].Text = lv.Items[idx].SubItems[i].Text;
                            lv.Items[idx].SubItems[i].Text = cache;
                        }

                        var tagIdx = lv.Items[selitem].Tag;
                        var tagSel = lv.Items[idx].Tag;
                        lv.Items[selitem].Tag = tagSel;
                        lv.Items[idx].Tag = tagIdx;

                        lv.Focus();
                        lv.Items[selitem].Selected = true;
                        lv.EnsureVisible(selitem);
                    }
                    lv.EndUpdate();
                }
            }
        }
示例#14
0
文件: Utils.cs 项目: MrSiir/WpfsApp
        public static void addEmojiRichTextBox(System.Windows.Window owner, System.Windows.Controls.RichTextBox txtMessage)
        {
            Emojis em = new Emojis();
            em.Owner = owner;
            em.ShowDialog();

            string emo = em.emoji;
            em = null;

            if (!emo.Equals(""))
            {

                bool EmoAdded = false;
                var caretPosition = txtMessage.Selection.Start;
                var p = caretPosition.Paragraph;

                var bi = new BitmapImage(new Uri(@"emoji\" + emo + ".png", UriKind.Relative));
                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Source = bi;
                image.Width = 24;
                image.Height = 24;
                image.Tag = emo;
                var emoticonUIContainer = new System.Windows.Documents.InlineUIContainer(image);

                if (p == null)
                {
                    var paragraph = new System.Windows.Documents.Paragraph();
                    paragraph.Inlines.Add(emoticonUIContainer);
                    txtMessage.Document.Blocks.Add(paragraph);
                    EmoAdded = true;
                }
                else if (p.Inlines.FirstInline == null)
                {
                    p.Inlines.Add(emoticonUIContainer);
                    EmoAdded = true;
                }
                else
                {
                    foreach (var currInline in p.Inlines)
                    {
                        if (caretPosition.CompareTo(currInline.ContentStart) > 0 && caretPosition.CompareTo(currInline.ContentEnd) < 0 && currInline.GetType() != typeof(System.Windows.Documents.InlineUIContainer))
                        {
                            try
                            {
                                var spanBefore = new System.Windows.Documents.Span(currInline.ContentStart, caretPosition);
                                var spanAfter = new System.Windows.Documents.Span(caretPosition, currInline.ContentEnd);
                                if (spanBefore != null) p.Inlines.InsertAfter(currInline, spanBefore);
                                p.Inlines.InsertAfter(currInline, emoticonUIContainer);
                                if (spanBefore != spanAfter) p.Inlines.InsertAfter(currInline, spanAfter);
                                p.Inlines.Remove(currInline);
                                EmoAdded = true;
                                break;
                            }
                            catch (Exception)
                            {
                                EmoAdded = false;
                                break;
                            }
                        }
                        else if (caretPosition.CompareTo(currInline.ContentStart) == 0)
                        {
                            p.Inlines.InsertBefore(currInline, emoticonUIContainer);
                            EmoAdded = true;
                            break;
                        }
                        else if (caretPosition.CompareTo(currInline.ContentEnd) == 0)
                        {
                            p.Inlines.InsertAfter(currInline, emoticonUIContainer);
                            EmoAdded = true;
                            break;
                        }
                    }
                }

                if (!EmoAdded)
                {
                    p.Inlines.Add(emoticonUIContainer);
                }

                try
                {
                    txtMessage.CaretPosition = emoticonUIContainer.ContentEnd;
                }
                catch (Exception) { }

                txtMessage.Focus();

            }

            em = null;
        }
示例#15
0
 private void ShowForm(System.Windows.Forms.Form form)
 {
     form.set_Font(this.Font);
     if (this.forms.ContainsKey(form.GetType()))
     {
         form = this.forms[form.GetType()];
         form.Focus();
     }
     else
     {
         System.Windows.Forms.Cursor.set_Current(System.Windows.Forms.Cursors.WaitCursor);
         form.Show(this);
         this.forms.Add(form.GetType(), form);
         form.add_Closed(new System.EventHandler(this.form_Closed));
         System.Windows.Forms.Cursor.set_Current(System.Windows.Forms.Cursors.Default);
     }
 }
示例#16
0
 private void Dtg_Frm_Foc(System.Windows.Forms.Form myctl)
 {
     myctl.Focus();
 }
 /* Author: Pooja Jairath */
 // Defining the function to check if phone number is in the correct format
 //public static bool IsPhoneNumber(System.Web.UI.WebControls.TextBox textBox, string name)
 //{
 //    Regex r = new Regex("\\p{N}{3}-\\p{N}{3}-\\p{N}{4}\\b");//"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}"
 //    if (r.IsMatch(textBox.Text))
 //    {
 //        message = "";
 //        return true;
 //    }
 //    else
 //        message = name + " should be a valid phone number.";
 //    textBox.Focus();
 //    return false;
 //}
 /* Author: Pooja Jairath */
 // Defining the function to check if postal code is in the correct format
 public static bool IsPostal(System.Web.UI.WebControls.TextBox textBox, string name)
 {
     Regex r = new Regex("[A-Za-z][0-9][A-Za-z] ?[0-9][A-Za-z][0-9]");
     if (r.IsMatch(textBox.Text))
     {
         message = "";
         return true;
     }
     else
         message = name + " should be a valid postal code in the format: A1A 1A1";
     textBox.Focus();
     return false;
 }
 // If textbox data is an alpha string
 /* Author: Pooja Jairath */
 // Defining the function to check if province is in the correct format
 public static bool IsProvince(System.Web.UI.WebControls.TextBox textBox, string name)
 {
     Regex r = new Regex("^[A-Za-z]{2}$");
     if (r.IsMatch(textBox.Text))
     {
         message = "";
         return true;
     }
     else
         message = name + " should contain only 2 characters. Example AB";
     textBox.Focus();
     return false;
 }
 /* Author: Pooja Jairath */
 // Defining the function to check if data is present in the textbox
 public static bool IsPresent(System.Web.UI.WebControls.TextBox textbox, string name)
 {
     if (textbox.Text == "")
     {
         message = name + " is a required field.";
         textbox.Focus();
         return false;
     }
     message = "";
     return true;
 }
示例#20
0
        /// <summary>
        /// Focus the control with a lowest tab index in the given container.
        /// </summary>
        /// <param name="container">A Control object to pe processed.</param>
        private void FocusFirstTabIndex(System.Windows.Forms.Control container)
        {
            // init search result varialble
            Control searchResult = null;

            // find the control with the lowest tab index
            foreach (Control control in container.Controls)
            {
                if (control.CanFocus && (searchResult == null || control.TabIndex < searchResult.TabIndex))
                {
                    searchResult = control;
                }
            }

            // check if anything searchResult
            if (searchResult != null)
            {
                // focus found control
                searchResult.Focus();
            }
            else
            {
                // focus the container
                container.Focus();
            }
        }
        public void checkString(System.Windows.Controls.TextBox txt, System.Windows.Controls.Label lbl, bool isRequired)
        {
            try
            {
                if (txt.Text == "")
                {
                    lbl.Content = "";
                    return;
                }
                bool err = false;
                String str = txt.Text;
                str = System.Text.RegularExpressions.Regex.Replace(str, @"\s+", " ");
                str = str.Trim();
                //str = str.ToLower();
                str = Regex.Replace(str, "(?:^|\\s)\\w", new MatchEvaluator(delegate(Match m) { return m.Value.ToUpper(); }));
                txt.Text = str;
                if (!Regex.IsMatch(str, @"^[a-zA-Z0-9 @.]*$"))
                    err = true;

                if (isRequired == true)
                {
                    if (String.IsNullOrWhiteSpace(str))
                        err = true;
                }

                if (err == true)
                {
                    lbl.Content = "?";
                    lbl.ToolTip = "Please enter alphanumeric & symbol values only";
                    lbl.Focus();
                    lbl.Foreground = System.Windows.Media.Brushes.Red;
                    lbl.FontWeight = FontWeights.ExtraBold;
                }
                else
                {
                    lbl.Content = "✔";
                    lbl.Foreground = System.Windows.Media.Brushes.Green;
                }
            }
            catch (Exception ex)
            {

            }
        }