I have a form, frmPleaseWait
, that has a MarqueeProgressBar
and a Label
that I want to use when the UI is loading the data in a poorly structured app we have.
The problem is that frmPleaseWait.Show()
shows the form but not the controls in it. It is just a white rectangle. Now frmPleaseWait.ShowDialog()
shows the child controls but doesn't let the UI load it's data.
What am I missing? Below is a code snippet from where I am trying this.
PleaseWait = new frmPleaseWait();
PleaseWait.Show(this);
// Set all available HUD values in HUD Object
HUD.LastName = GetCurrentRowVal("LastName").Trim();
HUD.FirstName = GetCurrentRowVal("FirstName").Trim();
HUD.PersonId = Convert.ToInt32(GetCurrentRowVal("PersonID").Trim());
HUD.SSn = GetCurrentRowVal("SSN").Trim();
HUD.MiddleName = GetCurrentRowVal("MiddleName").Trim();
HUD.MasterID = ConnectBLL.BLL.DriInterface.CheckForDriId(HUD.PersonId).ToString();
// This loads numerous UserControls with data
shellForm.FormPaint(HUD.PersonId);
PleaseWait.Close();
Edit
:
Follow up based on answers and my attempt.
This is what I have but I get a Cross-Thread Exception
on pleaseWaitInstance.Location = parent.PointToScreen(Point.Empty);
If I remove that line it will run but it runs in the top left corner of MY screen and ignores the position of the app.
public partial class frmPleaseWait : XtraForm
{
public frmPleaseWait()
{
InitializeComponent();
}
private static frmPleaseWait pleaseWaitInstance;
public static void Create(XtraForm parent)
{
var t = new System.Threading.Thread(
() =>
{
pleaseWaitInstance = new frmPleaseWait();
pleaseWaitInstance.FormClosed += (s, e) => pleaseWaitInstance = null;
pleaseWaitInstance.StartPosition = FormStartPosition.Manual;
pleaseWaitInstance.Location = parent.PointToScreen(Point.Empty);
Application.Run(pleaseWaitInstance);
});
t.SetApartmentState(System.Threading.ApartmentState.STA);
t.IsBackground = true;
t.Start();
}
public static void Destroy()
{
if (pleaseWaitInstance != null) pleaseWaitInstance.Invoke(new Action(() => pleaseWaitInstance.Close()));
}
}