Example #1
0
        public async Task Load(string path, TextBoxBase into)
        {
            into.Clear();

            using (var fileStream = new StreamReader(path, true))
            {
                StringBuilder builder = new StringBuilder(3000);
                int           i       = 0;

                while (!fileStream.EndOfStream)
                {
                    builder.Append(await fileStream.ReadLineAsync() + Environment.NewLine);
                    i++;

                    if (i > 50)
                    {
                        into.AppendText(builder.ToString());
                        i = 0;
                        builder.Clear();
                    }
                }

                into.AppendText(builder.ToString());
            }
        }
Example #2
0
 /// <summary>
 /// 增加文字到textbox
 /// </summary>
 /// <param name="control"></param>
 /// <param name="text">增加的文字</param>
 /// <param name="time">是否在前面加上时间</param>
 public static void AppendText(TextBoxBase control, string text, bool time = false)
 {
     if (control.InvokeRequired)
     {
         Action <string> action = x =>
         {
             if (time)
             {
                 control.AppendText(DateTime.Now.ToString() + "  " + x + "\r\n");
             }
             else
             {
                 control.AppendText(x + "\r\n");
             }
             control.SelectionStart  = control.Text.Length;
             control.SelectionLength = 0;
             control.Focus();
         };
         control.Invoke(action, text);
     }
     else
     {
         if (time)
         {
             control.AppendText(DateTime.Now.ToString() + "  " + text + "\r\n");
         }
         else
         {
             control.AppendText(text + "\r\n");
         }
         control.SelectionStart  = control.Text.Length;
         control.SelectionLength = 0;
         control.Focus();
     }
 }
Example #3
0
        ///////////////////////////////////////////////////////////////////////

        public static bool AppendText(
            TextBoxBase textBox,
            string text,
            bool newLine,
            bool asynchronous
            )
        {
            if (asynchronous)
            {
                return(BeginInvoke(textBox, new DelegateWithNoArgs(delegate()
                {
                    textBox.AppendText(text);

                    if (newLine)
                    {
                        textBox.AppendText(Environment.NewLine);
                    }
                }), true));
            }
            else
            {
                return(Invoke(textBox, new DelegateWithNoArgs(delegate()
                {
                    textBox.AppendText(text);

                    if (newLine)
                    {
                        textBox.AppendText(Environment.NewLine);
                    }
                }), true));
            }
        }
Example #4
0
 /// <summary>
 /// Responde al evento de creación del <c>TextBox</c>
 /// volcando todo el texto almacenado en el buffer.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void control_HandleCreated(object sender, EventArgs e)
 {
     if (_builder != null)
     {
         _control.AppendText(_builder.ToString());
         _builder = null;
     }
 }
Example #5
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Methods
        //---------------------------------------------------------------
        /// <summary>
        /// writes a string into the text box
        /// </summary>
        /// <param name="text">string to write</param>
        public override void Write(string text)
        {
            try {
                textBox.AppendText(text);
            } catch (System.ObjectDisposedException) {
                System.Diagnostics.Debug.Listeners.Remove(this);
            }
        }
Example #6
0
        public static void AppendLine(this TextBoxBase textBox, string text)
        {
            if (textBox == null)
            {
                throw new ArgumentNullException("textBox");
            }

            textBox.AppendText(text);
            textBox.AppendText(Environment.NewLine);
        }
Example #7
0
        private void AppendText(string s)
        {
            if (sb != null)
            {
                textBox.AppendText(sb.ToString());
                sb = null;
            }

            textBox.AppendText(s);
        }
 // 最低限度需要重写的方法
 public override void Write(string value)
 {
     if (textBox.InvokeRequired)
     {
         textBox.BeginInvoke(write, value);
     }
     else
     {
         textBox.AppendText(value);
     }
 }
Example #9
0
 public override void Write(string value)
 {
     if (control.IsHandleCreated)
     {
         control.AppendText(value);
     }
     else
     {
         BufferText(value);
     }
 }
Example #10
0
        public static void AppendAtEnd(this TextBoxBase textBox, string text, string endOfLine = "/r/n", bool moveToEndOfText = true)
        {
            if (!textBox.Text.IsMatch($"{endOfLine} $; f"))
            {
                var newEndOfLine = endOfLine.Replace("/r", "\r").Replace("/n", "\n");
                textBox.AppendText(newEndOfLine);
            }

            textBox.AppendText(text);
            if (moveToEndOfText)
            {
                textBox.Select(textBox.TextLength, 0);
            }
        }
Example #11
0
        public async Task Load(string name, TextBoxBase textBox)
        {
            using (var connection = new SQLiteConnection(_connectionString))
            {
                await connection.OpenAsync();

                string query = $"SELECT distinct {_valueColumnName} " +
                               $"from {_tableName} " +
                               $"where {_nameColumnName} = @name";

                using (var command = new SQLiteCommand(query, connection))
                {
                    command.Parameters.Add(new SQLiteParameter("@name", name));

                    using (var reader = await command.ExecuteReaderAsync())
                    {
                        textBox.Clear();

                        if (reader.HasRows)
                        {
                            await reader.ReadAsync(); // read only the first row

                            string temp = await Task.Run(() => _valueEncoding.GetString((byte[])reader[_valueColumnName]));

                            textBox.AppendText(temp);
                        }
                    }
                }
            }
        }
Example #12
0
 private static void TextBoxOutput(TextBoxBase textbox, string output)
 {
     textbox.AppendText(output);
     textbox.SelectionStart  = textbox.Text.Length;
     textbox.SelectionLength = 0;
     textbox.ScrollToCaret();
 }
Example #13
0
 /// <summary>
 /// Internal implementation of Write; bypasses \n checking for the prefix
 /// </summary>
 /// <param name="data">The text to write</param>
 /// <remarks>
 /// This method exists so it can be called when we need to write the prefix.
 /// </remarks>
 protected virtual void _innerWrite(string data)
 {
     data = AddMissingCRs(data);
     if (tb.InvokeRequired)
     {
         if (this.SyncInvoke)
         {
             tb.Invoke(asyncWriteSync, new object[] { data });
         }
         else
         {
             // Okay, an async invocation is needed
             _writeBuffer.QueueWrite(data);
             if (!_writeQueued)
             {
                 _writeQueued = true;
                 tb.BeginInvoke(asyncWriteAsync);
             }
         }
         return;
     }
     // Okay, no invoke required. That means we're executing on the main thread.
     // If there are any queued writes, write them *right now*.
     _asyncWriteAsync();
     tb.AppendText(data);
 }
Example #14
0
        protected override string Write(string value, bool newLine)
        {
            if (_textBox.InvokeRequired)
            {
                _textBox.BeginInvoke(new Func <string, bool, string>(Write), value, newLine);
                return(null);
            }
            else
            {
                if (newLine)
                {
                    value = value.Trim('.') + ".";
                }

                value = base.Write(value, newLine);

                lock (_textBox)
                {
                    _textBox.AppendText(value);
                    if (_scrollTextBox)
                    {
                        _textBox.ScrollToCaret();
                    }
                }

                return(value);
            }
        }
Example #15
0
 public override void Write(String txt)
 {
     if (concon.IsHandleCreated)
     {
         concon.AppendText(txt);
     }
 }
Example #16
0
        private static void RegistryDelete(TextBoxBase updateTextBox, ProgressBar updateProgressBar, String culture)
        {
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Classes\*\shell");

            if (regKey == null)
            {
                return;
            }

            String[] keys = regKey.GetSubKeyNames();
            foreach (String key in keys)
            {
                if (!key.Contains("DtPad"))
                {
                    continue;
                }

                //Registry.CurrentUser.DeleteSubKey(String.Format(@"Software\Classes\*\shell\{0}\command", key));
                Registry.CurrentUser.DeleteSubKeyTree(String.Format(@"Software\Classes\*\shell\{0}", key));

                updateTextBox.AppendText(Environment.NewLine + LanguageUtil.GetCurrentLanguageString("Key", className, culture) + " \"" + key + "\" " + LanguageUtil.GetCurrentLanguageString("DeletedKey", className, culture));
                break;
            }

            updateProgressBar.PerformStep();
        }
Example #17
0
        public override void Write(string message)
        {
            Action append = delegate()
            {
                output.AppendText(string.Format("[{0}] ", DateTime.Now.ToString("HH:mm:ss")));
                output.AppendText(message);
            };

            if (output.Dispatcher.CheckAccess())
            {
                append();
            }
            else
            {
                output.Dispatcher.Invoke(append);
            }
        }
Example #18
0
 public override void Write(string message)
 {
     message = message.Replace("\r\n", "\n");
     message = message.Replace("\n", "\r\n");
     _textBox.BeginInvoke((Action) delegate {
         _textBox.AppendText(message);
         _textBox.ScrollToCaret();
     });
 }
    public override void Write(string message)
    {
        Action append = delegate()
        {
            output.AppendText(string.Format("[{0}] ", DateTime.Now.ToString()));
            output.AppendText(message);
            output.AppendText(Environment.NewLine);
        };

        if (output.InvokeRequired)
        {
            output.BeginInvoke(append);
        }
        else
        {
            append();
        }
    }
Example #20
0
        public override void Write(String text)
        {
            MethodInvoker action = delegate
            {
                _textBoxBase.AppendText(text);
                _textBoxBase.ScrollToCaret();
            };

            _form.BeginInvoke(action);
        }
Example #21
0
        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());
            }
        }
 /// <summary>
 /// writes the message to the box (if available)
 /// </summary>
 /// <param name="message">the message to output</param>
 public new void WriteMessage(string message)
 {
     base.WriteMessage(message);
     outputTextBox.Dispatcher.Invoke(new Action(() =>
     {
         outputTextBox.AppendText(message + "\n");
         outputTextBox.ScrollToEnd();
     })
                                     );
 }
Example #23
0
        public override void Log(string expression, object value)
        {
            string log = null;

            if (value != null && value.GetType() != typeof(string))
            {
                var enumerable = value as IEnumerable;
                if (enumerable != null)
                {
                    // #lambda value = string.Join(Environment.NewLine, enumerable);

                    var sb = new StringBuilder();

                    foreach (var item in enumerable)
                    {
                        if (item == null)
                        {
                            sb.AppendLine("(null)");
                        }
                        else
                        {
                            sb.AppendLine(item.ToString());
                        }
                    }
                    value = sb.ToString();
                }
            }

            if (value == null)
            {
                value = "(null)";
            }
            if (value == DBNull.Value)
            {
                value = "(DBNull)";
            }

            if (!string.IsNullOrEmpty(expression) && value != null)
            {
                log = ">> " + expression + Environment.NewLine + value.ToString();
            }
            else
            {
                if (!string.IsNullOrEmpty(expression))
                {
                    log = ">> " + expression;
                }
                else
                {
                    log = value.ToString();
                }
            }

            _box.AppendText(log + Environment.NewLine + Environment.NewLine);
        }
Example #24
0
 private static void AppendTextBox(TextBoxBase tb, string s)
 {
     try
     {
         tb.AppendText(s + Environment.NewLine);
     }
     catch (ObjectDisposedException)
     {
         // FIXME: properly dispose subscribers created in the Form1() cctor
     }
 }
Example #25
0
 public static void AppendText(TextBoxBase control, string text)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(new AppendTextDelegate(AppendText), control, text);
     }
     else
     {
         control.AppendText(text);
     }
 }
Example #26
0
 /// <summary>
 /// Write a string to the trace window
 /// </summary>
 /// <param name="message">The string to write</param>
 public override void Write(string message)
 {
     if (textBox.InvokeRequired)
     {
         textBox.BeginInvoke(new AppendTextDelegate(textBox.AppendText), new object[] { message });
     }
     else
     {
         textBox.AppendText(message);
     }
 }
Example #27
0
 protected override void WriteLine(string value)
 {
     if (_logControl.InvokeRequired)
     {
         _logControl.Invoke(new Action <string>(this.WriteLine), value);
     }
     else
     {
         _logControl.AppendText(value + Environment.NewLine);
     }
 }
Example #28
0
 protected override void Append(LoggingEvent loggingEvent)
 {
     someTextBox.AppendText(loggingEvent.RenderedMessage + Environment.NewLine);
     // DP: Vielleicht muss das hier noch eingearbeitet werden
     //MethodInvoker logDelegate = delegate {
     //	textBox.Text = level.toString() + ": " + strLogMessage + System.Environment.NewLine + textBox.Text;
     //};
     //if (textBox.InvokeRequired)
     //	textBox.Invoke(logDelegate);
     //else
     //	logDelegate();
 }
Example #29
0
 private void Append(string message)
 {
     CheckLogMaxLineForTextChangedEvent();
     if (!output.Disposing && !output.IsDisposed)
     {
         output.AppendText(message);
     }
     else
     {
         //todo: Server窗体被关闭后,log写入失败的处理
     }
 }
Example #30
0
 /// <summary>
 /// appends text for text boxes
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="text"></param>
 private void SetAppendText(TextBoxBase obj, string text)
 {
     if (obj.InvokeRequired)
     {
         SetAppendTextCallback tcb = new SetAppendTextCallback(SetAppendText);
         this.Invoke(tcb, new Object[] { obj, text });
     }
     else
     {
         obj.AppendText(text);
     }
 }