Clear() public méthode

public Clear ( ) : void
Résultat void
Exemple #1
0
 public static void ClearCrossThread(this TextBoxBase textBox)
 {
     if (textBox.InvokeRequired)
     {
         Action <TextBoxBase> action = new Action <TextBoxBase>(ClearCrossThread);
         textBox.Invoke(action, new object[] { textBox });
     }
     else
     {
         textBox.Clear();
     }
 }
Exemple #2
0
        static void ProcessBackspace(TextBoxBase txt, ref String m)
        {
            while (true)
            {
                var p = m.IndexOf('\b');
                if (p < 0)
                {
                    break;
                }

                // 计算一共有多少个字符
                var count = 1;
                while (p + count < m.Length && m[p + count] == '\b')
                {
                    count++;
                }

                // 前面的字符不足,消去前面历史字符
                if (p < count)
                {
                    count -= p;
                    // 选中最后字符,然后干掉它
                    if (txt.TextLength > count)
                    {
                        txt.Select(txt.TextLength - count, count);
                        txt.SelectedText = null;
                    }
                    else
                    {
                        txt.Clear();
                    }
                }
                else if (p > count)
                {
                    // 少输出一个
                    txt.AppendText(m.Substring(0, p - count));
                }

                if (p == m.Length - count)
                {
                    m = null;
                    break;
                }
                m = m.Substring(p + count);
            }
        }
Exemple #3
0
        /*private string getAditionalFilter()
         * {
         * if (Qry.Cfg.AditionalFilter != null && Adv.AditionalFilter != "")
         * { return " AND " + Adv.AditionalFilter; }
         * else
         * { return ""; }
         * }*/

        private void Pesquisa(string Cod, bool ExecPesquisa)
        {
            if (BeforeResearch != null)
            {
                BeforeResearch(this);
            }

            // Limpa Controls
            Text.Clear();
            for (int i = 0; i < Rets.Count; i++)
            {
                Rets[i].RetField.Clear();
            }

            // Pesquisa
            if (IsEmpty(Cod) && ExecPesquisa)
            {
                if (Qry.Exec())
                {
                    Cod = Qry.GetField(PrimaryKey).ToString();
                }
            }

            if (!IsEmpty(Cod))
            {
                DataSource ds = new DataSource(this.cnn.GetDataSet(Qry.Cfg.Sql + " Where " + PrimaryKey + " = " + SqlValue(Cod)));
                for (int i = 0; i < Rets.Count; i++)
                {
                    Rets[i].RetField.Text = ds.GetField(Rets[i].SqlField).ToString();
                }

                if (AfterResearch != null)
                {
                    AfterResearch(this, ds);
                }
            }
        }
		public static void LoadText (TextBoxBase sourceRichEdit, string fileName, bool excludeEmptyLines)
		{
			if (sourceRichEdit == null)	throw new NolmeArgumentNullException ();

			sourceRichEdit.Clear ();
			
			//Win32RichEditUtility.BeginUpdate (sourceRichEdit);
			if (File.Exists (fileName))
			{
				string [] aszAllLines = FileUtility.ReadAllLines (fileName, excludeEmptyLines,true);
				string szBuffer = String.Concat (aszAllLines);
				sourceRichEdit.AppendText (szBuffer);
			}
			//Win32RichEditUtility.EndUpdate (sourceRichEdit);
		}
		public static void LoadText (TextBoxBase sourceRichEdit, Stream stream)
		{
			if (sourceRichEdit == null)	throw new NolmeArgumentNullException ();
			if (stream == null)		throw new NolmeArgumentNullException ();

			byte []aBytes;
			sourceRichEdit.Clear ();

			aBytes = new byte [stream.Length + 1];
			stream.Read (aBytes, 0, (int)stream.Length);

			ASCIIEncoding	oObj	= new ASCIIEncoding ();
			string			szBuffer= oObj.GetString (aBytes,0,aBytes.GetLength(0));

			sourceRichEdit.AppendText (szBuffer);
		}
		public static void LoadText (TextBoxBase sourceRichEdit, string []lineArray)
		{
			if (sourceRichEdit == null)	throw new NolmeArgumentNullException ();
			if (lineArray == null)		throw new NolmeArgumentNullException ();

			sourceRichEdit.Clear ();

			for (int i = 0; i < lineArray.Length; i++)
			{
				sourceRichEdit.AppendText (lineArray[i]);
				sourceRichEdit.AppendText (StringUtility.CreateLinefeedString ());
			}
		}
		public static void LoadText (TextBoxBase sourceRichEdit, ArrayList arrayList)
		{
			if (sourceRichEdit == null)	throw new NolmeArgumentNullException ();
			if (arrayList == null)		throw new NolmeArgumentNullException ();

			sourceRichEdit.Clear ();

			//Win32RichEditUtility.BeginUpdate (sourceRichEdit);
			for (int i = 0; i < arrayList.Count; i++)
			{
				sourceRichEdit.AppendText (arrayList[i].ToString ());
				sourceRichEdit.AppendText (StringUtility.CreateLinefeedString ());
				//Win32RichEditUtility.AddTextLine (sourceRichEdit, arrayList[i].ToString (), Color.Black, 8, false, false, false, false);
			}
			//Win32RichEditUtility.EndUpdate (sourceRichEdit);
		}
Exemple #8
0
 private void ClrText(TextBoxBase ctl)
 {
     if(ctl.InvokeRequired)
       {
     ClrTextCallback d = new ClrTextCallback(ClrText);
     this.Invoke(d, new object[] { ctl });
       }
       else
       {
     ctl.Clear();
       }
 }
Exemple #9
0
        /// <summary>附加文本到文本控件末尾。主要解决非UI线程以及滚动控件等问题</summary>
        /// <param name="txt">控件</param>
        /// <param name="msg">消息</param>
        /// <param name="maxLines">最大行数。超过该行数讲清空控件</param>
        /// <returns></returns>
        public static TextBoxBase Append(this TextBoxBase txt, String msg, Int32 maxLines = 1000)
        {
            if (txt.IsDisposed)
            {
                return(txt);
            }

            var func = new Action <String>(m =>
            {
                try
                {
                    if (txt.Lines.Length >= maxLines)
                    {
                        txt.Clear();
                    }

                    // 记录原选择
                    var selstart = txt.SelectionStart;
                    var sellen   = txt.SelectionLength;

                    // 输出日志
                    if (m != null)
                    {
                        //txt.AppendText(m);
                        // 需要考虑处理特殊符号
                        //ProcessBell(ref m);
                        //ProcessBackspace(txt, ref m);
                        //ProcessReturn(txt, ref m);

                        m = m.Trim('\0');
                        // 针对非Windows系统到来的数据,处理一下换行
                        if (txt is RichTextBox && Environment.NewLine == "\r\n")
                        {
                            // 合并多个回车
                            while (m.Contains("\r\r"))
                            {
                                m = m.Replace("\r\r", "\r");
                            }
                            //while (m.Contains("\n\r")) m = m.Replace("\n\r", "\r\n");
                            //m = m.Replace("\r\n", "<TagOfLine>");
                            m = m.Replace("\r\n", "\n");
                            //m = m.Replace("\r", "\r\n");
                            m = m.Replace("\n\r", "\n");
                            // 单独的\r换成\n
                            //if (_line.IsMatch(m))
                            //    m = _line.Replace(m, "\n");
                            m = m.Replace("\r", "\n");
                            //m = m.Replace("\r", null);
                            //m = m.Replace("<TagOfLine>", "\r\n");
                        }
                        if (String.IsNullOrEmpty(m))
                        {
                            return;
                        }
                        txt.AppendText(m);
                    }

                    // 如果有选择,则不要滚动
                    if (sellen > 0)
                    {
                        // 恢复选择
                        if (selstart < txt.TextLength)
                        {
                            sellen = Math.Min(sellen, txt.TextLength - selstart - 1);
                            txt.Select(selstart, sellen);
                            txt.ScrollToCaret();
                        }

                        return;
                    }

                    txt.Scroll();
                }
                catch { }
            });

            //txt.Invoke(func, msg);
            var ar = txt.BeginInvoke(func, msg);

            //ar.AsyncWaitHandle.WaitOne(100);
            //if (!ar.AsyncWaitHandle.WaitOne(10))
            //    txt.EndInvoke(ar);

            return(txt);
        }
Exemple #10
0
        /// <summary>附加文本到文本控件末尾。主要解决非UI线程以及滚动控件等问题</summary>
        /// <param name="txt">控件</param>
        /// <param name="msg">消息</param>
        /// <param name="maxLines">最大行数。超过该行数讲清空控件</param>
        /// <returns></returns>
        public static TextBoxBase Append(this TextBoxBase txt, String msg, Int32 maxLines = 1000)
        {
            if (txt.IsDisposed)
            {
                return(txt);
            }

            var func = new Action <String>(m =>
            {
                try
                {
                    if (txt.Lines.Length >= maxLines)
                    {
                        txt.Clear();
                    }

                    // 记录原选择
                    var selstart = txt.SelectionStart;
                    var sellen   = txt.SelectionLength;

                    // 输出日志
                    if (m != null)
                    {
                        //txt.AppendText(m);
                        // 需要考虑处理特殊符号
                        //ProcessBell(ref m);
                        //ProcessBackspace(txt, ref m);
                        //ProcessReturn(txt, ref m);

                        m = m.Trim('\0');
                        if (String.IsNullOrEmpty(m))
                        {
                            return;
                        }
                        txt.AppendText(m);
                    }

                    // 如果有选择,则不要滚动
                    if (sellen > 0)
                    {
                        // 恢复选择
                        if (selstart < txt.TextLength)
                        {
                            sellen = Math.Min(sellen, txt.TextLength - selstart - 1);
                            txt.Select(selstart, sellen);
                            txt.ScrollToCaret();
                        }

                        return;
                    }

                    txt.Scroll();
                }
                catch { }
            });

            //txt.Invoke(func, msg);
            var ar = txt.BeginInvoke(func, msg);

            //ar.AsyncWaitHandle.WaitOne(100);
            //if (!ar.AsyncWaitHandle.WaitOne(10))
            //    txt.EndInvoke(ar);

            return(txt);
        }