我有一個類,我想從組合框和文本框中獲取值,但是當我傳遞該值時,它顯示以下錯誤:非靜態字段,方法或屬性需要對象引用
An object reference is required for the non-static field, method, or property
下面是代碼
public class Device1
{
public int dwMachineNumber = cboMachineNo.SelectedIndex;
public int dwBaudrate = 9600;
public int dwCommPort = CboComPort.SelectedIndex;
public string dwIPAddress = tbIPAdd.Text.Trim();
public int dwPort = int.Parse(tbPort.Text.Trim());
public int dwPassWord = int.Parse(tbPwd.Text.Trim());
}
private bool OpenDevice(int flag)
{
bool result = false;
int DEVICE_BUSY = 0;
Device1 dww = new Device1();
try{
result = OpenCommPort(dww.dwMachineNumber,
dww.dwBaudrate,
dww.dwCommPort,
dww.dwIPAddress,
dww.dwPassWord,
dww.dwPort,
flag);
}
tb *定義在哪裏?而你錯過了一些代碼....如果你需要幫助,請發佈一個更連貫的代碼塊。 – Nix 2011-05-25 15:18:56
in form.designer – Mano 2011-05-25 15:21:45
它直接獲得價值,但是當我通過它傳遞它時,它顯示以下錯誤 – Mano 2011-05-25 15:22:40