不要一次又一次地显示表格 [英] Do not show form again and again

查看:74
本文介绍了不要一次又一次地显示表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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

推荐答案

当你调用ShowDialog时,它显示表单,主代码不再执行,直到你只是表单显示已关闭 - 线程冻结直到那时。

所以,你要做的是使用Show代替:

When you call ShowDialog, it displays the form, and the main code executes no further until the form you just displayed is closed - the thread "freezes" until then.
So, what you want to do it use Show instead:
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.


我认为你需要一个简单的布尔标志。



private bool RegistrationFormShown = false;



然后,在使用RegistrationForm调用'ShowDialog'的代码中,执行类似这样的操作:



if(RegistrationFormShown(return);



RegistrationFormShown.ShowDialog();



//如果注册成功:

RegistrationFormShown = true;



以上假设注册表已经为您提供......以某种方式......注册成功的信息。



注册表本身为您提供的一种方式指示用户是否注册:在注册表中的某处,您检测到成功:
I think a simple boolean flag is all you need here.

private bool RegistrationFormShown = false;

And then, in the code that calls 'ShowDialog using the RegistrationForm, do something like this:

if(RegistrationFormShown(return);

RegistrationFormShown.ShowDialog();

// if registration is successful:
RegistrationFormShown = true;

The above assumes that the Registration Form has provided you ... somehow ... with the information that the registration was successful.

One way to have the Registration Form itself provide you with an indication of whether the user registered: somewhere in the Registration Form where you detect "success:"
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.


这篇关于不要一次又一次地显示表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆