C#-WinForm常用控件简述

1.对齐控件

菜单栏>格式>对齐

2.锁定控件

                     1.属性栏中Locked改为true

                     2.右击控件锁定

                     3.锁定全部:菜单栏>格式>锁定控件

                     注:可避免误操作

        属性visible:显示/隐藏控件

3.Button控件

                设置为窗体“接受”按钮(点击Enter键触发)

        private void form1_load(object sender, EventArgs e)
        {
            this.AcceptButton = button2;
            
        }

                 设置为窗体的“取消”按钮(Esc触发)

this.CancelButton = button3;

4.TextBox控件

                设置加密文本框:属性PasswordChar(自定义显示符号)

                                             属性UseSystemPasswordChar(使用“*”)

                突出显示: SelectionStart(开始位置)

                                   SelectionLength(长度) 

                文本更改响应事件: TextChanged

        private void textbox1_cahnged(object sender, EventArgs e)
        {
            this.label1.Text = textBox1.Text;
        }

5.RichTextBox控件

                属性Multiline:设置是否显示滚动条

                属性ScrollBars:如何显示滚动条

                属性SelectionFont:设置字体属性

                属性SelectionColor:设置字体颜色 

                事件LinkClicked:设置超链接

                属性SelectionBullet:是否以符号列表形式显示内容

                属性SelectionIndent:段落相对于控件左边缘缩进

                属性SelectionRightIndent:相对于控件右边缘缩进

 this.richTextBox1.SelectionBullet = true;
 this.richTextBox1.SelectionIndent = 8;
 this.richTextBox1.SelectionRightIndent = 17;

6.选择类控件

(下拉组合框ComboBox、复选框CheckBox、单选按钮RadioButton、数值选择NumericUpDown、列表ListBox)

        1、ComboBox下拉组合框控件:

                属性DropDownStyle:选择只可选类型

                选择全部(前提DropDownStyle为DropDown)

comboBox1.SelectAll();

                事件SelectedValueChanged:当下拉框的选择项发生改变时引发 

        2、CheckBox复选控件

                Click事件中判断是否选中

        private void checkBox_Click(object sender, EventArgs e)
        {
            if (checkBox1.CheckState == CheckState.Checked)
            {
                MessageBox.Show("被选中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else 
            {
                MessageBox.Show("没选中");
            }
        }

                事件CheckStateChanged:选择状态发生改变时响应

        private void checkBox1_CheckStateChanged(object sender, EventArgs e)
        {
            MessageBox.Show("复选框选择状态发生改变");
        }

         3、RadioButton单选控件

                Click事件中判断是否选中

        private void radiobutton1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
                MessageBox.Show("选中苹果");
        }
        private void radioButton2_Click(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
                MessageBox.Show("选中西红柿");
        }

                CheckedChanged事件:单选选中状态发生改变 

        4、NumericUpDown数值选择控件

                Value属性:获取NumericUpDown控件的数值

                Maximum属性:设置控件最大值

                Minimum属性:设置控件最小值

                DecimalPlaces属性:设置小数点后显示几位

                ThousandsSeparator属性:是否每三个十进制字位插入一个分隔符

                Hexadecimal属性:是否可用十六进制显示值

        5、ListBox列表控件

                添加项

        private void button1_Click(object sender, EventArgs e)
        {
            //label1.Text = textBox1.Text;
            if (textBox1.Text == "")
                MessageBox.Show("请输入内容");
            else
            {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Text = "";
            }
        }

                移除项 

        private void button4_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count == 0)
                MessageBox.Show("没有要移除的内容");
            else
                listBox1.Items.Remove(listBox1.SelectedItem);//移除选中项
        }

                HorizontalScrollbar属性:是否总显示水平滚动条

                ScrollAlwaysVisible属性:是否总显示垂直滚动条 

                MultiColumn属性:是否支持多列显示

                SelectionMode属性:选择多项

7.分组类控件

(Panel容器控件、GroupBox分组框控件、TabControl选项卡控件)

        Panel容器控件

                Enabled属性:是否对用户交互做出响应(        是否有用)

 if (textBox1.Text.Trim() == "Auston")//判断文本框是否输入“Auston”
     panel1.Show();

        GroupBox分组框控件 

                 :总是显示边框;可以显示标题;:没有滚动条

                Text属性:设置标题

        TabControl选项卡控件

                 TabPage:表示选项卡

                 TabPages属性:表示所有选项卡的集合               

                 Appearance属性:设置选项卡按钮的样式

                 在选项卡中加按钮:TabPage的Control属性的Add()方法

  tabControl1.ImageList = imageList1;//使用imageList控件图像
  tabPage1.ImageIndex = 0;//使用索引0位置的图像作为选项卡图标
  tabPage1.Text = "选项卡1";
  tabPage2.ImageIndex = 0;
  tabPage2.Text = "选项卡2";
  //tabControl1.Appearance = TabAppearance.Buttons;//设置成三维按钮的样式
  tabControl1.Appearance = TabAppearance.FlatButtons;//平面按钮的样式
  Button but1 = new Button();
  but1.Text = "新增按钮";
  but1.Width=140;
  but1.Height = 40;
  tabPage1.Controls.Add(but1);

                添加选项卡 :使用tabPages选项卡集合的Add()方法

  string title="选项卡"+(tabControl1.TabCount+1).ToString();
  TabPage newtabpage = new TabPage(title);
  tabControl1.TabPages.Add(newtabpage);

                移除选项卡:使用TabPages属性的Remove()方法

 private void button6_Click(object sender, EventArgs e)
 {
      if (tabControl1.SelectedIndex == 0)
          MessageBox.Show("未选中选项卡");//提示信息
      else
          tabControl1.TabPages.Remove(tabControl1.SelectedTab);//移除被选中的选项卡
 }

                 删除所有选项卡:使用TabPages属性的Clear()方法

8.菜单、工具栏、状态栏控件 

        MenuStrip菜单控件:

支持多文档界面、菜单合并、工具提示和溢出

                文本框输入“文件&F”,“&”被识别为确认快捷键的字符,快捷Alt+F,显示为“文件(F)”

        ToolStrip工具控件

        StatusStrip状态栏控件:

由ToolStripStatusLabel对象组成,还可以包含ToolStripDropDownButton、ToolStripSplitButton、ToolStripProgressBar控件

toolStripStatusLabel1.Text = DateTime.Now.ToString();//状态栏显示日期
 private void button7_Click(object sender, EventArgs e)
 {
      this.toolStripProgressBar1.Maximum = 1000;//进度条最大值
      this.toolStripProgressBar1.Minimum = 0;//进度条最小值
      this.toolStripProgressBar1.Step = 1;//进度条的增值
      for (int i = 0; i < 1000; i++)
      {
          System.Threading.Thread.Sleep(1);
          this.toolStripProgressBar1.PerformStep();//按照step属性增加进度栏位置 
      }
  }
    

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值