form1窗口里
private void timer1_Tick(object sender, EventArgs e)
{
DateTime timeend = Convert.ToDateTime(textBox2.Text);//设置结束时间
textBox1.Text = dt.GetDateTimeFormats('M')[0].ToString();//设置当前时间
string timeday = DateAndTime.DateDiff("d", timeend, DateTime.Now, FirstDayOfWeek.Sunday, FirstWeekOfYear.FirstFourDays).ToString();
long time = long.Parse(timeday);
if (time > 0)//判断倒计时时间是否大于0
label1.Text = "倒计时已设置,剩余" + time + "day";//显示倒计时
else
{
label1.Text = "时间已到";
Form1 f1 = (Form1)this.Owner; //获得form1属性
f1.Enabled = false;
}
form2窗口
private void Form2_Load(object sender, EventArgs e)
{
Form1 f2 = new Form1(); //实例化FORM2
f2.Owner = this; //指定form1是form2的父窗体
f2.ShowDialog(); //打开Form2
}
希望form1的时间到,form2窗体禁止任何操作,但是我的总是提示f1.Enabled = false;未将对象引用设置到对象的实例,求大神帮帮忙,小女子感激不尽!!!!
form2的实例传给form1,2里发布一个public的方法,直接调用
当然最好还是用委托,实现自定义事件
代码不清楚, 不清楚 你这俩方法放在哪个类里面
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics; //process类所引用
namespace WindowsFormsApplication4
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Form1 f2 = new Form1(); //实例化FORM2
f2.Owner = this; //指定form1是form2的父窗体
f2.ShowDialog(); //打开Form2
}
}
}
Form2 f1 = (Form2)this.Owner;
f1.Enabled = false;
Application.OpenForms["Form1"].Enabled = false;