【问题标题】:vb.net check if a button clicked on another new formvb.net 检查按钮是否单击了另一个新表单
【发布时间】:2017-04-06 04:20:09
【问题描述】:

我在 Visual Studio 2013 中的项目 form1 和 form2 中有 2 个表单。 form2 包含 2 个按钮(button1 和 button2)

form1 有一个计时器事件,在某些情况下会触发 form 2。 所以我需要 Form1 中的代码来知道是否点击了 form2 中的按钮。

我在 form1 中尝试了这些代码但不起作用:

if form2.button2_Click = true then
msgbox("Button 2 clicked")
end if

请有人帮我解决这个问题并做必要的事情。(我只想从 form1 做这个)

【问题讨论】:

  • A Button_click 是一个事件 - 它们在用户单击时触发,仅此而已,让带有按钮的表单调用另一个表单上的方法,告诉它按钮已被单击
  • 谢谢 Plutonix 我得到了方法

标签: vb.net


【解决方案1】:

在表格2中

Public Class Form2

Public Event SimulateForm1ButtonClick()

Private Sub MetroTile2_Click(ByVal sender As System.Object, ByVal e As   System.EventArgs) Handles MetroTile2.Click

    RaiseEvent SimulateForm1ButtonClick()


End Sub

在Form1中

Public Class Form1
Private WithEvents myform As New Form2


Private Sub frm2_SimulateForm1ButtonClick() Handles myform.SimulateForm1ButtonClick

msgbox("Sucecss!!!! called from form 2")
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 2014-04-09
    • 1970-01-01
    相关资源
    最近更新 更多