A
Andrus
I created winforms .net 2 mdi child status window class below.
My long running code writes messages to this window to allow user to see
progress.
I want that Log() method writes text at new line and textbox scrolls when
window becomes full.
Currently it adds text to end of current line and does not scroll if window
becomes full. How to fix ?
Is it reasonable to use BackgroundWorker class instead of this ?
If yes, how to change this class to use backgroundworker ?
Andrus.
public class Status : Form {
TextBox lb;
public Status(string title) {
lb = new TextBox();
lb.Dock = DockStyle.Fill;
lb.Multiline = true;
Controls.Add(lb);
StartPosition = FormStartPosition.Manual;
AutoScroll = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
Text = title;
Left = 0;
MdiParent = AppDesktop.MainForm;
Top = (int)(0.6 * (double)MdiParent.Height) - 60;
Height = MdiParent.Height / 3;
Width = MdiParent.Width - 60;
ControlBox = false;
Icon = null;
MaximizeBox = false;
MinimizeBox = false;
Show();
}
public void Log(string s) {
lb.Text += "\r";
lb.Text += s;
lb.ScrollToCaret();
Application.DoEvents();
}}}
My long running code writes messages to this window to allow user to see
progress.
I want that Log() method writes text at new line and textbox scrolls when
window becomes full.
Currently it adds text to end of current line and does not scroll if window
becomes full. How to fix ?
Is it reasonable to use BackgroundWorker class instead of this ?
If yes, how to change this class to use backgroundworker ?
Andrus.
public class Status : Form {
TextBox lb;
public Status(string title) {
lb = new TextBox();
lb.Dock = DockStyle.Fill;
lb.Multiline = true;
Controls.Add(lb);
StartPosition = FormStartPosition.Manual;
AutoScroll = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
Text = title;
Left = 0;
MdiParent = AppDesktop.MainForm;
Top = (int)(0.6 * (double)MdiParent.Height) - 60;
Height = MdiParent.Height / 3;
Width = MdiParent.Width - 60;
ControlBox = false;
Icon = null;
MaximizeBox = false;
MinimizeBox = false;
Show();
}
public void Log(string s) {
lb.Text += "\r";
lb.Text += s;
lb.ScrollToCaret();
Application.DoEvents();
}}}