我有一个带有在其他应用程序上绘制的控件的表单。每次显示窗口时,其他应用程序加载速度太慢,无法启动。
因此,我提前加载了辅助应用程序。我使用控件句柄作为参数,告诉应用程序要使用哪个句柄。
第一次可以正常工作。当我关闭对话框(单击“确定”按钮,将对话框结果设置为“确定”)并再次打开它时,控件句柄发生了变化。
如何在两次对话框加载之间保持控件句柄相同?
public partial class ListForm : Form
{
FilterDialog filterDialog;
public ListForm()
{
InitializeComponent();
filterDialog = new FilterDialog(); //this is where I load my second form, which I draw in
}
我画的对话框
public FilterDialog()
{
InitializeComponent();
string applicationlocation = @"...";
//set the argument
string hexvalue = btnImage.Handle.ToInt32().ToString("X8");
process.StartInfo.Arguments = "0x" + hexvalue;
process.StartInfo.FileName = applicationlocation;
process.StartInfo.UseShellExecute = false;
process.Start();
}
private void FilterDialog_Load(object sender, EventArgs e)
{
if (this.filter != string.Empty)
txtFilter.Text = filter;
}
这段代码似乎有效:
class CustomHandleForm : Form
{
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
base.DestroyHandle();
}
protected override void DestroyHandle() { }
}
经过测试:
Form f = new CustomHandleForm();
f.Show();
var h1 = f.Handle;
f.Hide();
f.Show();
var h2 = f.Handle;
Trace.Assert(h1 == h2);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句