一些控件的应用

1.Label标签

     属性                                                说明
   Text 该属性用于设置或获取与控件关联的文本
   方法                                               说明
   Hide 隐藏控件,调用该方法时,即使visible属性设置为True控件也不可见
   show 相当于将控件的visible属性设置为True并显示控件
    事件                                              说明
        Click

        用户单击控件时将发生该事件

 2.TextBox文本框

属性    说明                             
MaxLength 可在文本框中输入的最大的字符数
Multiline 表示是否可在文本框中输入多行文本
Passwordchar 机密和敏感数据密码输入字符
ReadOnly 文本框中的文本为只读
Text 检索在控件中输入的文本
方法 说明
Clear 删除现有的所有文本
事件 说明
KeyPress 用户接一个键结束时,将发生该事件

3.Button按钮

属性 说明
Enabled 确定是否可以启用或禁用该控件
方法 说明
PerformClick Button控件的Click事件
事件 说明
  Click 单击按钮时将触发该事件

 运用的源代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lianxi
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello" + ' ' + txtFname.Text + ' ' + txtLname.Text + ' ' + "Welcome to the Windows", "Welcome", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
        }
    }
}


界面展示:

4.ListBox控件

属性:Items   SelectionMode    SelectedItems      SelectedIndex    SelectedItem    Text

  方法:ClearSelected

事件:SelectedIndexChanged

5.ComboBox组合框

属性 说明
DropDownStyle ComboBox控件的样式
MaxDropDownItems 下拉区显示的最大项目数
方法 说明
Select 在ComboBox控制上选定指定范围的文本

运用的源代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lianxi2
{
    public partial class UserInfo : Form
    {
        public UserInfo()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            lstCountry.Items.Add(txtCountry.Text);
            txtCountry.Clear();
            cboState.Items.Add(txtState.Text);
            txtState.Clear();
        }

        private void btnRemoveCountry_Click(object sender, EventArgs e)
        {
            lstCountry.Items.Remove(lstCountry.SelectedItem);
        }

        private void btnShowDetails_Click(object sender, EventArgs e)
        {
            if (chkEMail.Checked == true || chkPostalMail.Checked == true && rdbMale.Checked == true)
            {
                MessageBox.Show("Hello Man,you will be contacted by either USPS or email", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
            else
                if (chkEMail.Checked == true || chkPostalMail.Checked == true && rdbFemale.Checked == true)
                {
                    MessageBox.Show("Hello Female,you will be contacted by either USPS or email", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
        }
    }
}


界面展示:

猜你喜欢

转载自blog.csdn.net/h_h_1122/article/details/81368504