winform公共控件

公共控件

1、Button 按钮
Enabled -- 是否启用控件(例:注册界面,我同意,才可启用)
Visible -- 控件是可见的,还是隐藏的 
2、CheckBox -- 复选框(多个复选框,用panel框起来等同于复选框组)
CheckListBox --复选框组   Checked:默认选中
3、ComboBox --下拉菜单
①数据填进去
可以在后台 将要填进去的内容放到 Items集合中去

②如何取到选中的数据
SelectedItem

只允许选择 -- DropDownStyle 
默认选中项 -- SelectedIndex
4、DateTimePicker  日期时间选择器
text -- 中文日期
value -- DateTime类型

5、Label --添加文字 


6丶LinkLabel --添加链接类型的文字

7、ListBox 列表框
SelectionMode -- 只是列表框是单项选择、多项选择还是不可选择 
在后台如何获取多选的全部内容

SelectionMode :None不让选  One只能选一个 MultiExtended连选  MultiSimple多选,并且不用连选
SelectedItems集合,遍历它们

private void button3_Click(object sender, EventArgs e)
        {
            string a = "";
            foreach(object o in listBox1.SelectedItems)
            {
                a += o.ToString();
            }

 

8、MaskedTextBox   掩码文本框
Mask -- 使用掩码规定用户输入的内容格式

9、MonthCalendar: -- 日历表
MaxSelectionCount -- 可选择的天数
SelectionStart / SelectionEnd -- 开始日期 / 结束日期

10、NotifyIcon: -- 任务栏显示小图标 QQ托盘
Visible -- 控件是可见还是隐藏
Icon -- 图标
Text -- 鼠标悬停在小图标上时显示的文字

11、NumericUpDown
increment -- 单次点击时增加或减少的数量 
Maximum -- 数值控件的最大值 
Minimum -- 数值控件的最小值

12、PictureBox:--显示图像
Image --不好用,显示不完全
BackgroundImage --背景图片,可使用Layout 设置布局格式

13、ProgressBar: --进度条
value -- 0到100之间
Maximum --正使用的范围上限
Minimum -- 正使用的范围下限

Style(Marquee) --不显示进程的进度条
MarqueeAnimationSpeed --进度条的速度,以毫秒为单位


14、RichTextBox --高级文本输入和编辑功能

可以设置多行 并且在超出高度之后自动出现滚动条
text (\r\n) --换行

15、TextBox  文本框

Multiline:多行编辑

ScrollBars :滚动条显示

WordWrap:自动换行



16、ToolTip: 注释
ToolTipTitle --每一个控件都显示此内容 
只要拖进来这个控件,那所有控件的杂项里都会多一条属性
就是用来设置此控件的介绍

InitialDelay --鼠标移上去多长时间显示介绍的内容
ReshowDelay --鼠标移开,显示的介绍内容停留多长时间消失

17、TreeView
树状列表(类似于目录菜单)

18、WebBrowser:(允许用户在窗体内浏览网页)
指定Web浏览器控件导航到的Url

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication2.App_code;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            checkBox1.Checked = true;//默认选中
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //if (checkBox1.Checked)
            //    checkBox1.Checked = false;
            //else
            //    checkBox1.Checked = true;
            List<Natrion> nlisi = new Nationdata().select();
            comboBox1.DataSource = nlisi;
            comboBox1.DisplayMember = "Nationname";
            comboBox1.SelectedIndex = nlisi.Count - 1;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string end = "";
            int count = 0;
            foreach (object o in checkedListBox1.CheckedItems)
            {
                if (count > 0)
                    end += ",";
                end += o.ToString();
                count++;
            }
            MessageBox.Show(end);


        }

        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
            {
                this.checkedListBox1.SetItemChecked(i, true);//true就是全选 
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
            {
                this.checkedListBox1.SetItemChecked(i, false);//true就是全选 
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            foreach (Control c in flowLayoutPanel1.Controls)
            {
                CheckBox cb = c as CheckBox;
                if (cb.Text == "满族")
                {
                    cb.Checked = true;
                }
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Natrion n = comboBox1.SelectedItem as Natrion;
            MessageBox.Show(n.NationName + n.NationCode);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Natrion n = comboBox1.SelectedItem as Natrion;
            MessageBox.Show(n.NationName + n.NationCode);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            MessageBox.Show(dateTimePicker1.Text + "\r" + dateTimePicker1.Value);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            dateTimePicker1.Value = Convert.ToDateTime("2000-1-1");
        }

        private void button9_Click(object sender, EventArgs e)
        {
            MessageBox.Show(monthCalendar1.SelectionEnd.ToString("yyyy年MM月dd日"));
        }
    }
}
View Code

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

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string aaa = "这是第一行\n这是第二行\n这是第三行\n";
            textBox1.Text = aaa;
            richTextBox1.Text = aaa;
            Uri u = new Uri("https://www.baidu.com/");
            webBrowser1.Url = u;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a=Convert.ToInt32(numericUpDown1.Value);
            progressBar1.MarqueeAnimationSpeed = a;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(numericUpDown1.Value.ToString());
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            MessageBox.Show(treeView1.SelectedNode.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Uri u = new Uri(textBox2.Text);
            webBrowser1.Url = u;
        }
    }
}
View Code

 

posted @ 2016-12-05 16:58  尘暮  阅读(325)  评论(0编辑  收藏  举报