如何处理表格? [英] how to handle forms?

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

问题描述

Main和Main1有2种形式.Main是MdiContainer.bpaper也是一种形式.这里显示的是bpaper形式,但在第一行也给出了一个例外.形式为Main.
说创建窗口句柄时出错"

此代码的目的是在后台运行Main窗体,而Main1在其顶部运行.
加载Main1后,必须检查系统时间,如果该值小于4.00p.m,则应从
提示bpaper. 如果时间值大于4.0 p.m,则应用程序应退出.

以主要形式加载:

there are 2 forms Main and Main1.Main is a MdiContainer.bpaper is also a form. here it shows the form bpaper but it also gives an exception on line one.Show(); of the form Main.
saying "error creating window handle"

purpose of this code is to run the form Main in the background,while the Main1 is running on top of it.
once the Main1 is loaded it has to check the system time and if that value is less than 4.00p.m it should prompt the bpaper from
if the time value is grater than 4.0 p.m then the application should exit.

in Main form load:

private void Main_Load(object sender, EventArgs e)
{
  Main1 one = new Main1();
  one.MdiParent = Main.ActiveForm;
  one.Show();
}





以Main1形式加载:





in Main1 form load:

private void Main1_Load(object sender, EventArgs e)
{
  t1 = DateTime.Now;
  t2 = Convert.ToDateTime("16:00:00 ");
  bpaper test = new bpaper();

//allow the bpaper to be appear (time before 4oclock)       
   if (t1 < t2)                                 
   {
     MessageBox.Show("less than 4.00 P.M");
     this.Hide();
     test.Show();
   }
//do not allow the bpaper to be appear after 4oclock
   else                                              
   {     
     MessageBox.Show("Time out ", t1.ToString());
     Application.Exit();
   }
}



请帮助我找出这段代码出了什么问题.



please help me to find out what is wrong with this code.

推荐答案

您不需要获取ActiveForm,即使您遇到问题也可以.而是使用当前实例:
You don''t need to get the ActiveForm - that may even by your problem. Instead, use the current instance:
private void Main_Load(object sender, EventArgs e)
{
  Main1 one = new Main1();
  one.MdiParent = this;
  one.Show();
}





仍然在同一位置发生异常!"

然后的问题是,您在Load事件中使用了Hide-在MDI父级完全准备好它之前,它已被执行:将代码移至Shown事件的形式:





"still the exception is occurring at the same place!"

Then the problem is that you are using Hide in the Load event - this is getting execturted before the MDI parent is completely ready for it: move your code to the form Shown event instead:

private void Main1_Shown(object sender, EventArgs e)
{
  t1 = DateTime.Now;
  t2 = Convert.ToDateTime("16:00:00 ");
  bpaper test = new bpaper();

//allow the bpaper to be appear (time before 4oclock)
   if (t1 < t2)
   {
     MessageBox.Show("less than 4.00 P.M");
     this.Hide();
     test.Show();
   }
//do not allow the bpaper to be appear after 4oclock
   else
   {
     MessageBox.Show("Time out ", t1.ToString());
     Application.Exit();
   }
}



但是,无论如何,您为什么要这样做-bpaper不是MDI子对象,那么为什么要创建Main1实例呢?为什么不改用Main表单,甚至不在program.cs文件的Main方法中呢?



But why are you doing it that way anyway - bpaper is not a MDI child, so why create the Main1 instance at all? Why not do this in the Main form instead, or even in the Main method of the program.cs file?


您需要修改您的Main表单 IsMdiContainer 属性更改 True 和一个.MdiParent= this;

希望有帮助,
Theingi Win
You need to modify your Main form IsMdiContainer properties change True and one.MdiParent =this;

Hope Be helpful,
Theingi Win


这篇关于如何处理表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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