扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Public Class Form3 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler Middle.SendMessage, AddressOf DoMethod End Sub Private Sub DoMethod(ByVal getstr As String) Me.ListBox1.Items.Add(getstr) End Sub End Class |
Public Class Form2 Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Middle.DoSendMessage(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() End Sub End Class |
Public Class Middle Public Shared Event SendMessage(ByVal str As String) Public Shared Sub DoSendMessage(ByVal str As String) RaiseEvent SendMessage(str) End Sub End Class |
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> Protected Overrides Sub OnCreateMainForm() Me.MainForm = Global.WindowsApplication3.MainFrm ChildFrm.show() End Sub |
public partial class MainFrm: Form { private void MainFrm _Load(object sender, EventArgs e) { Middle.sendEvent += new Middle.SendMessage(this.DoMethod); } public void DoMethod(string getstr) { listBox1.Items.Add(getstr); } } ChildFrm.cs: public partial class ChildFrm: Form { public ChildFrm () { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Middle.DoSendMessage(this.textBox1.Text); textBox1.Text = ""; textBox1.Focus(); } } Middle.cs: public static class Middle { public delegate void SendMessage(string str); public static event SendMessage sendEvent; public static void DoSendMessage(string str) { sendEvent(str); } } |
static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Application.Run(new Form1()); Form1 mainFrm = new Form1(); childFrm secondFrm = new childFrm(); secondFrm.Show(); Application.Run(mainFrm); } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者