£¨2£©µ¥»÷¡°È·¶¨¡±°´Å¥£¬¿É½«textBoxÖеÄÎÄ×ÖÌí¼Óµ½label2ÖУ» £¨3£©label2ÖеÄÎÄ×Ö¿É×ÖÌå´óС¿ÉÇл»Èý´Î£¨Ð¡¡¢ÖС¢´ó£©£¬³õʼ״̬ÏÂ×ÖÌåΪ¡°Ð¡¡±£¬Ôò¡°ËõС×ÖÌ塱°´Å¥²»¿ÉÓã¬Ã¿´Îµ¥»÷¡°Ôö´ó×ÖÌ塱°´Å¥£¬¿ÉʹÔö´ó×ÖÌåÒ»ºÅ£¬µ±×ÖÌåÔö´óΪ¡°´ó¡±Ê±£¬¡°Ôö´ó×ÖÌ塱°´Å¥²»¿ÉÓã¬Ã¿´Îµ¥»÷¡°ËõС×ÖÌ塱°´Å¥£¬¿Éʹ×ÖÌåËõСһºÅ£»
£¨4£©¡°±ä»»×ÖÌåÑÕÉ«¡±°´Å¥£¬¿Éʹlabel2ÖеÄ×ÖÌåÑÕÉ«Ëæ»ú¸Ä±ä¡£ 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 Test3 {
public partial class Form1 : Form {
public int Add = 0; //Ôö´ó×ÖÌå±êÖ¾£º0´ú±íС£¬1´ú±íÖУ¬2´ú±í´ó public Form1() {
this.StartPosition = FormStartPosition.CenterScreen; //´°¿Ú¾ÓÖÐÏÔʾ InitializeComponent(); }
//È·¶¨°´Å¥
private void button1_Click(object sender, EventArgs e) {
if (textBox1.Text == \ {
MessageBox.Show(\ÇëÊäÈëÎÄ×Ö£¡\ÌáʾÐÅÏ¢\MessageBoxIcon.Warning);
return; }
if (Add == 0) {
button3.Enabled = false; //ÉèÖÃËõС×ÖÌå²»¿ÉÓà }
richTextBox1.Text = textBox1.Text; //ÏÔʾÎÄ×Ö textBox1.Text = \Çå¿ÕÎÄ×Ö
textBox1.Focus(); //¶¨Î»ÊäÈë½¹µã }
//Ôö´ó×ÖÌå°´Å¥
private void button2_Click(object sender, EventArgs e) {
richTextBox1.SelectAll(); //ȫѡÎÄ×Ö
//richTextBox1.Select(0, 0); //È¡ÏûȫѡÎÄ×Ö if (richTextBox1.Text == \ {
MessageBox.Show(\µ±Ç°Îı¾¿òÎÞÎÄ×Ö\\ÌáʾÐÅÏ¢\MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; }
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont.FontFamily, richTextBox1.SelectionFont.Size + 1, richTextBox1.SelectionFont.Style);
Add++; if (Add !=0) {
button3.Enabled = true; //ÉèÖÃËõС×ÖÌå¿ÉÓà }
if (Add == 2) {
button2.Enabled = false; //ÉèÖÃÔö´ó×ÖÌå²»¿ÉÓà } }
//ËõС×ÖÌå°´Å¥
private void button3_Click(object sender, EventArgs e) {
richTextBox1.SelectAll(); //ȫѡÎÄ×Ö richTextBox1.SelectionFont = Font(richTextBox1.SelectionFont.FontFamily, richTextBox1.SelectionFont.Size richTextBox1.SelectionFont.Style);
Add--;
if (Add == 0) {
button3.Enabled = false; //ÉèÖÃËõС×ÖÌå²»¿ÉÓà }
if (Add < 2) {
button2.Enabled = true; //ÉèÖÃÔö´ó×ÖÌå¿ÉÓà } }
//±ä»»×ÖÌåÑÕÉ«°´Å¥
private void button4_Click(object sender, EventArgs e) {
richTextBox1.SelectAll(); //ȫѡÎÄ×Ö //richTextBox1.SelectionColor = Color.Red;
//ÉèÖÃ×ÖÌåÑÕÉ«£ºGetRandomColor()·½·¨ÊÇΪÁË»ñÈ¡Ëæ»úÑÕÉ« richTextBox1.SelectionColor = GetRandomColor();
new -1,
}
//¼ÓÔØ´°¿Ú
private void Form1_Load(object sender, EventArgs e) { }
//»ñÈ¡Ëæ»úÑÕÉ«
public Color GetRandomColor() {
Random RandomNum_First = new Random((int)DateTime.Now.Ticks); // C#µÄËæ»úÊý
System.Threading.Thread.Sleep(RandomNum_First.Next(50));
Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks); // ΪÁËÔÚ°×É«±³¾°ÉÏÏÔʾ£¬¾¡Á¿Éú³ÉÉîÉ« int int_Red = RandomNum_First.Next(256);
int int_Green = RandomNum_Sencond.Next(256);
int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green; int_Blue = (int_Blue > 255) ? 255 : int_Blue;
return Color.FromArgb(int_Red, int_Green, int_Blue); } } }
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 WindowsFormsApplication3 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private void label1_Click(object sender, EventArgs e) { }
private void button1_Click(object sender, EventArgs e) {
textBox2.Text = textBox1.Text; }
public inti = 1;
private void button2_Click(object sender, EventArgs e) {
if (i< 3) {
textBox2.Font = new Font(\ËÎÌå\i++;
} }
private void button3_Click(object sender, EventArgs e) {
if (i> 1) {
textBox2.Font = new Font(\ËÎÌå\i--;
} }
private void button4_Click(object sender, EventArgs e) {
textBox2.ForeColor = Color.Red; } } }
4.ÊÔ±àдWindowsÓ¦ÓóÌÐò£¬Íê³ÉÏÂÁÐÒªÇó£º
£¨1£©Form1´°ÌåÉè¼Æ½çÃæÈçÏ£º
£¨2£©´°Ìå×ó²àΪһ¸ö¿¿×óÍ£¿¿µÄpanel£¬ÆäÖаüº¬Ò»¸ölabel¿Ø¼þ£» £¨3£©³õÊÔ״̬ʱ£¬¡°Ë®Æ½Òƶ¯¡±Ñ¡ÖУ¬µ±Óû§µ¥»÷¡°¿ªÊ¼Òƶ¯¡±°´Å¥Ê±£¬labelÔÚpanelÖÐˮƽ´Ó×óÏòÓÒÒÆ¶¯£¬µ¥»÷¡°ÔÝÍ£ÒÆ¶¯¡±°´Å¥Ê±£¬labelÍ£ÔÚÔλÖò»¶¯£»
£¨4£©ÔÚlabelÒÆ¶¯¹ý³ÌÖУ¬ÈôÓû§Çл»Òƶ¯·½Ê½£¬Ôòµ¯³ö¶Ô»°¿ò£¬ÌáʾÏÈÔÝÍ£ÒÆ¶¯£»ÔÚlabelÔÝÍ£ÒÆ¶¯Ê±£¬Óû§Çл»Òƶ¯·½Ê½£¬labelÔÚÔλÖÃÒÔеÄÒÆ¶¯·½Ê½½øÐÐÒÆ¶¯¡£
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 Test4 {
public partial class Form1 : Form {
int y; //±ê־λ public Form1() {
this.StartPosition = FormStartPosition.CenterScreen; //´°¿Ú¾ÓÖÐÏÔʾ y = 1;
InitializeComponent(); }
//¿ªÊ¼Òƶ¯°´Å¥
private void button1_Click(object sender, EventArgs e) {
timer1.Enabled = true; //ÉèÖö¨Ê±Æ÷¿ÉÓÃ
timer1.Interval = 200; //ÉèÖö¨Ê±Æ÷¼ä¸ôΪ500ºÁÃë
}
//ÔÝÍ£ÒÆ¶¯°´Å¥
private void button2_Click(object sender, EventArgs e) {
timer1.Enabled = false; //ÉèÖö¨Ê±Îª²»¿ÉÓà }
//¼ÓÔØ´°¿Ú
private void Form1_Load(object sender, EventArgs e) {
radioButton1.Enabled = true; }
//¶¨Ê±Æ÷
private void timer1_Tick(object sender, EventArgs e) {
//Ë®Æ½ÒÆ¶¯
if (radioButton1.Checked) {
//×¢Ò⣺laber1.RightÊôÐÔ²»¿É¸Ä±ä£¬Ö»ÄܶÁ¡£ËùÒԸıälaber1µÄλÖÃÖ»ÄÜÓÃtopºÍleftÊôÐÔ
label1.Left = label1.Left + 10*y ; if (label1.Right>panel1.Size.Width) {