码迷,mamicode.com
首页 > Windows程序 > 详细

Windows基础控件使用

时间:2018-06-23 14:34:39      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:工具   常用事件   运行   更改   oid   窗体   box   drop   tip   

button按钮

textbox  文本框事件textchanged

label标签

checkbox复选框

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text == "123") textBox2.Text = "小明";
            else textBox2.Text = ("密码错误");
        }

密码显示姓名

 

复选框中代码

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true && checkBox2.Checked==true)
                textBox3.Text = "我喜欢" + checkBox1.Text + "和" + checkBox2.Text;
            else if (checkBox1.Checked == true && checkBox2.Checked == false)
                textBox3.Text = "我喜欢" + checkBox1.Text;
            else if (checkBox1.Checked == true && checkBox2.Checked == false)
                textBox3.Text = "我喜欢" + checkBox2.Text;
            else if (checkBox1.Checked == true && checkBox2.Checked == false)
                textBox3.Text = "";
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true && checkBox2.Checked==true)
                textBox3.Text = "我喜欢" + checkBox1.Text + "和" + checkBox2.Text;
            else if (checkBox1.Checked == true && checkBox2.Checked == false)
                textBox3.Text = "我喜欢" + checkBox1.Text;
            else if (checkBox1.Checked == true && checkBox2.Checked == false)
                textBox3.Text = "我喜欢" + checkBox2.Text;
            else if (checkBox1.Checked == true && checkBox2.Checked == false)
                textBox3.Text = "";
        }

技术分享图片

添加radiobutton单选按钮代码使用如下:

 

     private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
                textBox4.Text = "我很"+radioButton1.Text;
         {

            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked == true)
                textBox4.Text = "我很" + radioButton2.Text;
        }
    }

技术分享图片

Listbox列表框

找到items属性  点开集合

技术分享图片

显示字符串集合编辑器

技术分享图片

编写代码

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox5.Text = "你喜欢第" + listBox1.SelectedIndex.ToString() + "种颜色:"+listBox1.Text;
        }
    }

技术分享图片

 

 组合框ComboBox

属性 dropdownstyle  控制外观和功能。

有simple ,dropdown,dropdownlist  3个选项

技术分享图片

常用事件  

leave 当控件不再是窗体的活动控件事发生。

selectedindexchanged  更改控件的selectedindew属性发生

 首先进入items  集合编写字符串

然后代码 运行

 

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0) textBox6.Text = "白羊座";
            else if (comboBox1.SelectedIndex == 1) textBox6.Text = "金牛座";
            else if (comboBox1.SelectedIndex == 2) textBox6.Text = "双子座";
            else if (comboBox1.SelectedIndex == 3) textBox6.Text = "蟹座";
            else if (comboBox1.SelectedIndex == 4) textBox6.Text = "狮子";
            else if (comboBox1.SelectedIndex == 5) textBox6.Text = "处女";
            else if (comboBox1.SelectedIndex == 6) textBox6.Text = "天平";
            else if (comboBox1.SelectedIndex == 7) textBox6.Text = "天蝎";
            else if (comboBox1.SelectedIndex == 8) textBox6.Text = "射手";
            else if (comboBox1.SelectedIndex == 9) textBox6.Text = "魔蝎";
            else if (comboBox1.SelectedIndex ==10)
                textBox6.Text = "水瓶";
            else if (comboBox1.SelectedIndex ==11) textBox6.Text = "双鱼";
        }
    }
}

 技术分享图片

ToolTip工具提示

 

Windows基础控件使用

标签:工具   常用事件   运行   更改   oid   窗体   box   drop   tip   

原文地址:https://www.cnblogs.com/ricky1234/p/9212571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!