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()); } }
/// <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(); } }
/////////////////////////////////////////////////////////////////////// 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)); } }
/// <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; } }
//--------------------------------------------------------------- #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); } }
public static void AppendLine(this TextBoxBase textBox, string text) { if (textBox == null) { throw new ArgumentNullException("textBox"); } textBox.AppendText(text); textBox.AppendText(Environment.NewLine); }
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); } }
public override void Write(string value) { if (control.IsHandleCreated) { control.AppendText(value); } else { BufferText(value); } }
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); } }
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); } } } } }
private static void TextBoxOutput(TextBoxBase textbox, string output) { textbox.AppendText(output); textbox.SelectionStart = textbox.Text.Length; textbox.SelectionLength = 0; textbox.ScrollToCaret(); }
/// <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); }
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); } }
public override void Write(String txt) { if (concon.IsHandleCreated) { concon.AppendText(txt); } }
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(); }
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); } }
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(); } }
public override void Write(String text) { MethodInvoker action = delegate { _textBoxBase.AppendText(text); _textBoxBase.ScrollToCaret(); }; _form.BeginInvoke(action); }
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(); }) ); }
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); }
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 } }
public static void AppendText(TextBoxBase control, string text) { if (control.InvokeRequired) { control.Invoke(new AppendTextDelegate(AppendText), control, text); } else { control.AppendText(text); } }
/// <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); } }
protected override void WriteLine(string value) { if (_logControl.InvokeRequired) { _logControl.Invoke(new Action <string>(this.WriteLine), value); } else { _logControl.AppendText(value + Environment.NewLine); } }
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(); }
private void Append(string message) { CheckLogMaxLineForTextChangedEvent(); if (!output.Disposing && !output.IsDisposed) { output.AppendText(message); } else { //todo: Server窗体被关闭后,log写入失败的处理 } }
/// <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); } }