一些控件的应用

1.Label标签

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

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

 2.TextBox文本框

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

3.Button按钮

属性说明
Enabled确定是否可以启用或禁用该控件
方法说明
PerformClickButton控件的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组合框

属性说明
DropDownStyleComboBox控件的样式
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);
                }
        }
    }
}


界面展示:

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值