C# winfrom简单的题目

来源:互联网 发布:淘宝加盟商 编辑:程序博客网 时间:2024/06/14 09:51

1.编写程序在窗体上放置1个Text Box控件和4个Button控件。分别按下这4个按钮,可以把文本框的背景色分别设置为红色、蓝色、黑色和绿色。

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 Colors{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void Redbutton_Click(object sender, EventArgs e)        {            Redbutton.BackColor = textBox1.BackColor = Color.Red;            Redbutton.ForeColor = Color.White;        }        private void Bluebutton_Click(object sender, EventArgs e)        {            Bluebutton.BackColor = textBox1.BackColor = Color.Blue;            Bluebutton.ForeColor = Color.White;        }        private void Blackbutton_Click(object sender, EventArgs e)        {            Blackbutton.BackColor = textBox1.BackColor = Color.Black;            Blackbutton.ForeColor = Color.White;        }        private void Greenbutton_Click(object sender, EventArgs e)        {            Greenbutton.BackColor = textBox1.BackColor = Color.Green;            Greenbutton.ForeColor = Color.White;        }    }}

2.在窗体上放置4个排成矩形的按钮,每个按钮的标题都是Push Me!。当用户单击其中一个按钮时,此按钮便会消失,其它3个依然存在。



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 BadButton{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void PushMebutton_Click(object sender, EventArgs e)        {            PushMebutton.BackColor = Color.Transparent;            PushMebutton.FlatStyle = FlatStyle.Flat;            PushMebutton.FlatAppearance.BorderSize = 0;            PushMebutton.Text = " ";        }        private void PushMebutton4_Click(object sender, EventArgs e)        {            PushMebutton4.BackColor = Color.Transparent;            PushMebutton4.FlatStyle = FlatStyle.Flat;            PushMebutton4.FlatAppearance.BorderSize = 0;            PushMebutton4.Text = " ";        }        private void PushMebutton2_Click(object sender, EventArgs e)        {            PushMebutton2.BackColor = Color.Transparent;            PushMebutton2.FlatStyle = FlatStyle.Flat;            PushMebutton2.FlatAppearance.BorderSize = 0;            PushMebutton2.Text = " ";        }        private void PushMebutton3_Click(object sender, EventArgs e)        {            PushMebutton3.BackColor = Color.Transparent;            PushMebutton3.FlatStyle = FlatStyle.Flat;            PushMebutton3.FlatAppearance.BorderSize = 0;            PushMebutton3.Text = " ";        }    }}

0 0
原创粉丝点击