社区
C#
帖子详情
使用delegate 后无法关闭Form
dream19861009
2010-10-15 02:00:09
大概现象是这样的,在C#中 通过delegate将函数指针(暂命名为Process函数,Process函数是FormA 的私有函数)传给C++ 的 dll, 在dll中会去调用Process函数, 在Process中 的this.Close() 执行后 FormA并不会关闭?为什么? 如何才能关闭
...全文
88
2
打赏
收藏
使用delegate 后无法关闭Form
大概现象是这样的,在C#中 通过delegate将函数指针(暂命名为Process函数,Process函数是FormA 的私有函数)传给C++ 的 dll, 在dll中会去调用Process函数, 在Process中 的this.Close() 执行后 FormA并不会关闭?为什么? 如何才能关闭
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
我是一道光_
2010-10-15
打赏
举报
回复
symbol_bc
2010-10-15
打赏
举报
回复
等待高手
c# 实现子窗口
关闭
父窗口也
关闭
的方法
其实是窗口间通讯的问题,在
form
1上打开
form
2 ,
form
2
关闭
时
关闭
form
1 实现方法: 在子窗口
form
2中声明事件: public
delegate
void childclose(); public event childclose closefather; 然后在它的
关闭
事件中触发本事件: private void
Form
2_Closed(object sender, System.EventArgs e) { //用事件去
关闭
主窗口 closefather(); } 在父窗口
form
1中(比如登陆窗口中): 然后弹出子
form
2窗体的
c# 实现子窗口
关闭
父窗口也
关闭
的简单实例
其实是窗口间通讯的问题,在
form
1上打开
form
2 ,
form
2
关闭
时
关闭
form
1 实现方法: 在子窗口
form
2中声明事件: public
delegate
void childclose(); public event childclose closefather; 然后在它的
关闭
事件中触发本事件: private void
Form
2_Closed(object sender, System.EventArgs e) { //用事件去
关闭
主窗口 closefather(); } 在父窗口
form
1中(比如登陆窗口中): 然后弹出子for
C#串口通信,包括打开串口,接收发送数据
public partial class
Form
1 :
Form
{ public
Form
1() { InitializeComponent(); } SerialPort port1 = new SerialPort(); string InputData = String.Empty;
delegate
void SetTextCallback(string text); private void Port_Select() {//获取机器中的串口地址 string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { comboBox1.Items.Add(port); } } private void
Form
1_Load_1(object sender, EventArgs e) { Port_Select(); this.comboBox1.SelectedIndex = 0; this.comboBox2.SelectedIndex = 0; } private void button1_Click(object sender, EventArgs e) { if (button1.Text == "
关闭
串口") //当要
关闭
串口的时候 { port1.DiscardOutBuffer(); port1.DiscardInBuffer(); port1.Close(); button1.Text = "打开串口"; label3.Text = "串口当前状况:未打开"; comboBox1.Enabled = true; comboBox2.Enabled = true; } else if (button1.Text == "打开串口") //当要打开串口的时候 { try { port1.PortName = comboBox1.SelectedItem.ToString(); port1.BaudRate = Convert.ToInt32(comboBox2.SelectedItem); port1.DataBits = 8; port1.RtsEnable = true; port1.Open(); port1.DiscardOutBuffer(); port1.DiscardInBuffer(); button1.Text = "
关闭
串口"; comboBox1.Enabled = false; comboBox2.Enabled = false; label3.Text = "串口:" + comboBox1.SelectedItem.ToString() + " 波特率:" + comboBox2.SelectedItem.ToString() + " 数据位:8 "; } catch { button1.Text = "打开串口"; label3.Text = "串口:" + comboBox1.SelectedItem.ToString() + "打开失败"; MessageBox.Show("该串口
无法
打开"); } } } 资源中部分代码
C#实现简单的Login窗口实例
本文实例讲述了C#实现简单的Login窗口。分享给大家供大家参考。具体实现方法如下: C# 制作登录窗体,登录成功之后正确的做法是
关闭
(close)登录窗体,而不是隐藏窗体(hide) FrmLogin窗体: public
Form
1() { InitializeComponent(); //登录按钮 button1.Click +=
delegate
{ this.DialogResult = DialogResult.OK; this.Close(); }; //取消登录按钮 button2.Click +=
delegate
{ this.DialogRes
delegate
使用
方法C#(Demo)
老鸟路线。
C#
110,571
社区成员
642,565
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章