我試圖從項目的一類,類似這種方法得到一個處理我的窗體的文本框控件:如何與類中的文本框控件進行交互?
How to access Winform textbox control from another class?
我只是無法得到它的工作。在我的表單類我有這樣的:
public Form1()
{
InitializeComponent();
id = new InputDevice(Handle, this);
id.KeyPressed += new InputDevice.DeviceEventHandler(m_KeyPressed);
}
public void UpdateScanCode(string scanCode)
{
txtScanCode.Text = scanCode;
}
然後我的InputDevice類中我有這樣的:
Form mainForm;
public InputDevice(IntPtr hwnd, Form frmMain)
{
... stuff ...
mainForm = frmMain;
}
...終於,裏面我的功能之一:
mainForm.Update???
儘管Intellisense找到了許多Form1的其他成員,但無法找到UpdateScanCode函數。當我嘗試mainForm.UpdateScanCode()它不會編譯。
爲什麼不能工作?
嘗試創建form1的對象,然後嘗試訪問。像Form1 frmM = new Form1(); frmM.UpdateScanCode(); – 2015-02-06 04:22:24