实现一个类似WshShell.popup的function Envionment:C#, .Net3.5,Win7要求: 1. 一个主窗口弹出一个子窗口,子窗口负责询问用户是否要做什么事'是/否' 2. 如果在规定时间内,如10秒,用户无反应,就自动返回是或否请问: 这个要如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一个问题 设置dialogresult 返回即可第二个问题 添加timer控件 用tick事件控制即可。 现在弄出来了,详细写下方法.虽然很多人不屑这个case,但毕竟是基础.如 绝代坏坏)所说,只是他省略了具体步骤. 这可是个恶习啊,能详细点就详细点吧.1. 通过studio加入一个form文件(名字叫mess好了),设计好.比如我就是很简单:1个yes+1个no+1个Label+1个timer2. 在GUI上设置yes与no的dialog性质为DialogResultYes与DialogResultNo. this.acceptbutton=yes; this.cancelbutton=no;3. YesButtonClick事件中返回DialogResult.Yes,No中返回DialogResult.No.4. 创建一个function,当timer时间到时invoke它. 在mess的load事件中加入Timer.Tick +=yourfunctionname. ;5. 主form调用这个form,用showDialog. (MSDN说的,我尝试如果用show,那就立刻显示主form与mess form,达不到要求了)虽然解决了很多要求,但是通过看MSDN又有了很多新的疑问:1.窗体之间不能直接控制,如果要控制,有多少种方法,是哪些 2.timer有2种,但是都有问题 .而且还把异步调用与多线程都看了一遍(当然,还是很多不懂)Sourcode:主窗体的namespace tmp2{ /// <summary> /// Description of MainForm. /// </summary> public partial class MainForm : System.Windows.Forms.Form { public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); dosomething(); // TODO: Add constructor code after the InitializeComponent() call. // TODO: Add Code to call testing functions - for example: // Automation.Start() } void Button1Click(object sender, EventArgs e) { } public void dosomething() { messwin newmess =new messwin(); newmess.setlabel("good"); newmess.ShowDialog(); System.Windows.Forms.MessageBox.Show(newmess.DialogResult.ToString()); } }}message form的namespace tmp2{ /// <summary> /// Description of mess. /// </summary> public partial class messwin : Form { public messwin() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } public void setlabel(string s) { this.label1.Text=s; } void MessLoad(object sender, EventArgs e) { this.AcceptButton=buttonyes; this.CancelButton=buttonno; this.timer1.Tick +=new EventHandler(this.returnvalue); timer1.Interval=6000; timer1.Enabled=true; timer1.Start(); } void returnvalue(object sender,EventArgs e) { ButtonyesClick(null,null); timer1.Stop(); } void ButtonnoClick(object sender, EventArgs e) { this.DialogResult= DialogResult.No; } void ButtonyesClick(object sender, EventArgs e) { this.DialogResult= DialogResult.Yes; } }} TreeNode如何存储键值 求正则 快结 SQL里有针对ntext类型字段的替换函数吗?(类似针对字符字段的replace函数 ) 急救!我的一个数据导入程序在台式机和笔记本上运行正常,但是在服务器上导入速度特别慢,不知道是什么原因? 有没有想开软件公司的朋友 关于Winform的问题!搞不明白! 求C#函数及其用法(详细) 程序显示在 小字体 环境下正常,在大字体就不行 ,出现问题,大家帮帮我. 为什么在系统启动时自动启动C#开发的应用程序很慢? 一個c的問題 WebBrowser问题请各位帮忙! 文档的问题
第二个问题 添加timer控件 用tick事件控制即可。
如 绝代坏坏)所说,只是他省略了具体步骤. 这可是个恶习啊,能详细点就详细点吧.
1. 通过studio加入一个form文件(名字叫mess好了),设计好.比如我就是很简单:1个yes+1个no+1个Label+1个timer
2. 在GUI上设置yes与no的dialog性质为DialogResultYes与DialogResultNo.
this.acceptbutton=yes;
this.cancelbutton=no;
3. YesButtonClick事件中返回DialogResult.Yes,No中返回DialogResult.No.
4. 创建一个function,当timer时间到时invoke它. 在mess的load事件中加入Timer.Tick +=yourfunctionname. ;
5. 主form调用这个form,用showDialog. (MSDN说的,我尝试如果用show,那就立刻显示主form与mess form,达不到要求了)虽然解决了很多要求,但是通过看MSDN又有了很多新的疑问:1.窗体之间不能直接控制,如果要控制,有多少种方法,是哪些 2.timer有2种,但是都有问题 .而且还把异步调用与多线程都看了一遍(当然,还是很多不懂)
Sourcode:
主窗体的
namespace tmp2
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : System.Windows.Forms.Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
dosomething();
// TODO: Add constructor code after the InitializeComponent() call. // TODO: Add Code to call testing functions - for example:
// Automation.Start() }
void Button1Click(object sender, EventArgs e)
{
}
public void dosomething()
{
messwin newmess =new messwin();
newmess.setlabel("good");
newmess.ShowDialog();
System.Windows.Forms.MessageBox.Show(newmess.DialogResult.ToString());
}
}
}
message form的
namespace tmp2
{
/// <summary>
/// Description of mess.
/// </summary>
public partial class messwin : Form
{
public messwin()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
public void setlabel(string s)
{
this.label1.Text=s;
}
void MessLoad(object sender, EventArgs e)
{
this.AcceptButton=buttonyes;
this.CancelButton=buttonno;
this.timer1.Tick +=new EventHandler(this.returnvalue);
timer1.Interval=6000;
timer1.Enabled=true;
timer1.Start();
}
void returnvalue(object sender,EventArgs e)
{
ButtonyesClick(null,null);
timer1.Stop();
}
void ButtonnoClick(object sender, EventArgs e)
{
this.DialogResult= DialogResult.No;
}
void ButtonyesClick(object sender, EventArgs e)
{
this.DialogResult= DialogResult.Yes;
}
}
}