问题描述
我正在使用c#开发一个Windows应用程序,创建一个表单并在其中添加了menustrip,一旦我点击打开一个表单,它再次显示我点击它并显示所以我需要一些代码,该表单应显示一次,我试过,但我没有得到帮助我
i am developing a windows application using c#,created a form and added menustrip in it ,once i click to open a form it shows again i clicked in it and it shows so i need some code for that form should show once,i tried but i don't get pls help me
推荐答案
registration obj=new registration();
obj.Show();
这将允许您的代码以两种形式继续,因此您可以根据需要打开其他表单。
请注意,如果你这样做,没有什么可以阻止你打开另一个注册表单和现有表格 - 你可能想保留一个类级别的引用,并处理它的FormClosing事件得到来自它的信息并清除参考,以便你可以在需要时打开一个新的。
This will allow your code to continue in both forms, so you can open other forms if you want.
Do be aware that if you do this, there is nothing preventing you opening another copy of the Registration form alongside the existing one - you probably want to keep a class level reference to it, and handle it's FormClosing event to both get the information from it and clear the reference so that you are clear to open a new one if needed.
this.DialogResult = System.Windows.Forms.DialogResult.OK;
然后,在您的表单中,将注册表单显示为对话框:
Then, in your Form that shows the Registration Form as a Dialog:
if (RegistrationFormShown) return;
if (theRegForm.ShowDialog() == DialogResult.OK)
{
RegistrationFormShown = true;
}
此代码允许注册表单多次显示,但一旦注册成功,则不会显示。
This code would allow the Registration Form to be shown more than once, but once registration was successful, then it would not be shown.
这篇关于不要一次又一次地显示表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!