C#版机房收费系统之基础小汇

跨窗体传值
//登录界面
       Operator oper = new Operator();
       oper.struserid = txtUserID.Text.Trim();//将登录账号传值给操作员窗体
       oper.ShowDialog();

//操作员界面
       public string struserid;//定义外部可访问的公共变量

       private void Operator_Load(object sender, EventArgs e)
        {
            labUserID.Text  = struserid;//将登录账号加载到操作员界面
        }
关闭窗体
	this.hide();//这是隐藏当前窗口,但会继续占用资源.
	this.close();//直接关闭当前窗口.以后可以再调用.
	this.dispose();//关闭当前窗口,以后不可以调用.
	Application.Exit();//关闭整个应用程序

循环判断TextBox输入框不能为空
 foreach (Control c in this.Controls)
    {
        if (c is TextBox)
        {
            if (string.IsNullOrEmpty((c as TextBox).Text))
            {
               MessageBox.Show("输入框不能为空,请核对您的输入信息!","温馨提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                break;
             }
        }

    }

清空所有TextBox框中内容
			 //this代表本窗体,如果是其他控件,如Panel,则要换成控件名
            foreach (Control c in this.Controls ) 
            {
                if (c is TextBox )
                {
                    c.Text = "";
                }
            }

为comboBox控件加载信息
	//一次性添加多个数据项
	string[] level = {"一般用户","操作员"};
	comboUserLevel.Items.AddRange(level);
	//一次添加一个数据项
	comboUserLevel.Items.Add("管理员");
	//设置默认值,0为所添加数据项的下标
	comboUserLevel.SelectedIndex = 0;

Label中文字居中显示
Label1.TextAlign=ContentAlignment.MiddleCenter;

加载数据
workloginfo.LoginDate = System.DateTime.Now.ToString();//获取时间
workloginfo.Computer = System.Environment.MachineName;//获取本地计算机名 
workloginfo.UserID = System.Environment.UserName;获取本地计算机登录名


猜你喜欢

转载自blog.csdn.net/sevengirl2017/article/details/80667783