访问另一个进程中的控件对象 [英] Access a control object in another process
问题描述
首先,我不知道这个问题包含在这个论坛部分。
如果没有,抱歉。
...例如,这是两个过程(winform风格和每个winform都有一个按钮)。我称这两个winform为'A'和'B'。
我想从B访问A的按钮,如下所示。
(假设我知道A按钮的窗口句柄。
- B侧码 -
按钮A_button = new Button(); //创建一个表示A按钮的按钮对象。
A_button = ....(A的句柄)//输入按钮的窗口是A_button对象的一个窗口。
然后从B侧自由控制A_button。
A_button.Click();
...
是否可能?
如果那时,我想知道如何在另一个过程中将句柄信息输入到同一类型的对象。
从这里工作,我想从B winform远程控制一个winform。
请告诉我。
Firstly, I do not know this my question is included in this forum section.
If not, sorry.
...
For example, threre are two process(winform style and each winform has a button).
I called that two winform as 'A' and 'B'.
I want to access A's button from B as like below.
(Assume I know the window handle of A's button.
-- B side code --
Button A_button = new Button(); // create a button object that meaning A's button.
A_button = ....(handle of A's) // input A button's window hanle to A_button object.
// and then control freely A_button from B side.
A_button.Click();
...
Is it possible?
If then, I want to know how to input the handle information to the same type object in another process.
from this work, I want to remote control A winform from B winform.
Please advise to me.
推荐答案
在Form2中创建一个公共方法并从Form1中调用它
Create a public method in Form2 and call it from Form1
'Code for Form 1
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.Show()
frm.MyButtonClick()
End Sub
End Class
'Code for Form 2
Public Class Form2
Public Sub MyButtonClick()
Button1.PerformClick()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Hello from Form 2")
End Sub
End Class
您也可以在Form2 public中创建Button1_Click,然后使用以下代码
You can also create Button1_Click in Form2 public and then use following code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.Show()
frm.Button1_Click(Me, e)
End Sub
这篇关于访问另一个进程中的控件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!