使用条件打开窗体 [英] To Open a window form using condition

查看:85
本文介绍了使用条件打开窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)带有计时器我正在加载一个显示用户在线的表格

2)当计时器在线加载用户时,它将检查来自用户的任何消息,如果这样,它将打开一个新的窗口表单。



问题:

如果已经为用户打开了一个表单(A)再次为同一个用户打开一个新表单(A )。

我的代码:

1)with timer i am loading a form showing users online
2)while the timer loading the users online it will checks any messages from the users if so it will open a new window form.

Issue:
if a form is opened already for an user(A) again its opening a new form for the same user(A).
My Code:

private void timer1_Tick(object sender, EventArgs e)
        {
            displaying users online
             {
               any messages from the user
               if the above statement is true 
               {
                 //open a new chat form
               }
             }
        }



如何解决问题以停止为单个用户打开多个表单。


How to resolve the issue to stop opening multiple forms for single user.

推荐答案

你有一个主表单,其中正在加载多个聊天表单...

现在,在该主表单中,

采取页面级变量

you have a main form inside which multiple chat forms are loading...
now,in that mainform,
take page level variable
List<int> openedchats = new List<int>();  </int></int>



现在,当在计时器上打开表单时


now, when open form on timer

if (!openedchats.Contains(userId))
{ 
    openedchats.add(userId);

    frmchat c = new frmchat();
    c.Tag = userId;
    c.Parent = this;
    c.show();
}
else
{
    //nothing to do
}



以父表格添加方法......


Add method... in parent form

public void RemovefromOpenedchats(int userid)
{
     openedchats.Remove(userId);	
}





frmchat 形式

in form_closing 事件



and in frmchat form
in form_closing event

(MainForm)this.Parent.RemovefromOpenedchats((int)this.Tag);





快乐编码!

:)



Happy Coding!
:)


目前还不是很清楚你的意思。但只需引用表单并检查它是否不是 null if(form.Visible)。您还可以在打开计时器外部的表单时取消计时器。



祝你好运!
It's not very clear what you mean exactly. But simply have a reference to the form and check it isn't null or if(form.Visible). You can also cancel the timer when opening a form outside of the timer.

Good luck!


这篇关于使用条件打开窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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