我有一个表单,名为frmPleaseWait
,其中包含一个MarqueeProgressBar
和一个Label
。在我们的应用程序加载数据时,我想使用它来显示UI。
问题是frmPleaseWait.Show()
只显示空白矩形而不显示控件。而frmPleaseWait.ShowDialog()
会显示子控件,但不允许UI加载它的数据。
我错了什么?以下是我尝试的代码片段。
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();
编辑
:
根据答案和我的尝试进行跟进。
这是我拥有的,但是我会得到一个Cross-Thread Exception
在pleaseWaitInstance.Location = parent.PointToScreen(Point.Empty);
如果我删除那一行,它将运行,但它将在我的屏幕左上角运行,并忽略应用程序的位置。
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()));
}
}
PleaseWait.Show(this)
时,显然并没有完全起作用,但现在我看不到明显的方法了...无论如何,感谢您的帮助,我会看看是否可以将最后一个问题解决掉。 - Refracted Paladin