c# 如何私有成员变量
楼主小白,在用C#写一个类似串口的form程序,现在想写一个函数访问定义的textbox变量发现无法访问,提示错误“需要对象应用”,求问解决方法。下面贴出代码和错误提示:
在form1_design.cs 文件里定义了一些控件:
private System.Windows.Forms.Label label_Port;
private System.Windows.Forms.ComboBox comboBox_Port;
private System.Windows.Forms.Label label_Baudrate;
private System.Windows.Forms.ComboBox comboBox_Baudrate;
private System.Windows.Forms.Button button_Open;
private System.Windows.Forms.Button button_Reset;
private System.Windows.Forms.Label label_Data_Received;
在程序中想给这些控件赋值:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Drawing.Drawing2D;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Radio_Test_GUI
{
public partial class Form_Test_Gui : Form
{
private SerialPort Serial = new SerialPort();
private StringBuilder Builder = new StringBuilder();
private long recv_count = 0;
private long send_count = 0;
private bool listening = false;
private bool clossing = false;
public Form_Test_Gui()
{
InitializeComponent();
}
private static void ReadXml() // 自己写的程序,
{
comboBox_Port.Text = GetAppConfig("Portname"); //出错的地方
comboBox_Baudrate.Text = GetAppConfig("Baudrate"); //出错的地方
}
}
提示的错误:
错误 1 非静态的字段、方法或属性“Radio_Test_GUI.Form_Test_Gui.comboBox_Port”要求对象引用 F:\VS_Project\Radio_Test_GUI 界面优化收发\Radio_Test_GUI\Radio_Test_GUI\Form1.cs 33 13 Radio_Test_GUI
错误 2 非静态的字段、方法或属性“Radio_Test_GUI.Form_Test_Gui.comboBox_Baudrate”要求对象引用 F:\VS_Project\Radio_Test_GUI 界面优化收发\Radio_Test_GUI\Radio_Test_GUI\Form1.cs 34 13 Radio_Test_GUI
求大神指点!