Call other Form from mainForm - Components not visible of other Form
In my mainForm, I check for installed compoenets in its Form_Load. If they are not installed, I call another Form (WaitingDialog) to show the status of instalaltion. I call waitingDialog as :
waitDlg = new WaitingDialog(null); // Parent is set to null
waitDlg.set("Checking....", "Components"); // Set 2 Labels
waitDlg.Title = "Installing...";
waitDlg.Show();
With the above code the waiting form is visible, but hte text set is not visible. That part (text size) of label is of white background but no text is visible.
I have to perform this in Form_Load only of mainForm as if componetns are not there then mainForm installls it and approp message is displayed on waitingDlg form.
How to handle this in a way that text is also visible in waitingDlg form ?
WaitingDialog Code :
public partial class WaitingDialog : Form
{
private string title;
priv开发者_JAVA技巧ate string message;
private bool cancel;
private ParentForm myParent = null;
public WaitingDialog()
{
InitializeComponent();
Cancel = false;
this.StartPosition = FormStartPosition.CenterScreen;
}
public WaitingDialog(ParentForm parent) : this()
{
if (parent != null)
{
myParent = parent;
this.StartPosition = FormStartPosition.Manual;
}
}
public WaitingDialog(string title, string message)
: this()
{
label1.Text = title;
msgLbl.Text = message;
// Title = title;
// Message = message;
}
private void WaitingDialog_Load(object sender, EventArgs e)
{
}
public string Title
{
get { return title; }
set { title = value;
label1.Text = title;
Invalidate();
}
}
public string Message
{
get { return message; }
set { message = value;
msgLbl.Text = value;
Invalidate();
}
}
public void set(string title, string message)
{
Title = title;
Message = message;
}
public void set(string title, string message, bool showButton)
{
Title = title;
Message = message;
this.cancelBtn.Visible = showButton;
}
public void showCancelButton(bool showButton)
{
this.cancelBtn.Visible = showButton;
}
public bool Cancel
{
get { return cancel; }
set { cancel = value; }
}
private void cancelBtn_Click(object sender, EventArgs e)
{
Console.WriteLine("CANCEL BUTTON CAUGHT");
Cancel = true;
}
}
// TRIED CAlling as :
waitingDlg = new WaitingDialog("Installing", "Components");
waitingDlg.Text = "Install Components"; //CAN SEE THIS IN TITLE
waitingDlg.Show();
But the labels text can't be visible and its background (text's size) is white.
Hope this helps. If you need more, would be glad to share more.
Thanks
Check that the constructor of WaitingDialog calls;
InitializeComponent();
Also put a breakpoint in your form load and make sure that you are setting the Text property of the label you wish to update to the waitDialog.Title property. Use this breakpoint to inspect the waitDialog.Title properties value also.
As I am doing instalaltion of components on showing the waitingDlg. Hnece the CPU stays busy and hence the UI thread couldn't paint the labels. I show and set the labels in my background thread's ReportProgress and call lthe installation in DoWork.
This solved the problem and shows everything nicely as expected.
Thanks to all of you for yout time and efforts.
Thanks
精彩评论