1 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; 2 namespace MyApplication 3 public class Form1 : System.Windows.Forms.Form { … } 4 public Form1() { // Required for Windows Form Designer support // InitializeComponent(); // TODO: Add any constructor code after // InitializeComponent call } 5 #region Windows Form Designer generated code /// /// Required method for Designer support do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(300,300); // размер формы в пикселях this.Text = "Form1"; // заголовок формы. } #endregion 6 static void Main() { Application.Run(new Form1()); }
static void Main() { Application.Run(new Form2()); }
Таблица 1 – Возможные значения перечисления FormStartPosition
private void Form1_Closed(object sender, System.EventArgs e) { // код для обработки события }
Form myForm = new Form(); myForm.Show();// Здесь срабатывает событие Load myForm.Hide();// Форма стала невидимой myForm.Show();// Событие Load больше не срабатывает myForm.Close(); // Эта команда закрывает и удаляет // форму... myForm.Show(); // Эта команда генерирует //исключение, поскольку // объект myForm уже недоступен
Область лотка
Рисунок 1 Рисунок 2 Рисунок 3
// button2 // this.button2.BackColor = System.Drawing.Color.Yellow; this.button2.ForeColor = System.Drawing.Color.Black; this.button2.Location = new System.Drawing.Point(32, 64); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(128, 32); this.button2.TabIndex = 1; this.button2.Text = "желтый"; this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.MouseEnter += new System.EventHandler(this.BtnEnter); this.button2.MouseLeave += new System.EventHandler(this.BtnLeave); // // button3 // this.button3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(192))); this.button3.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204))); this.button3.ForeColor = System.Drawing.Color.Black; this.button3.Location = new System.Drawing.Point(32, 104); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(128, 32); this.button3.TabIndex = 1; this.button3.Text = "голубой"; this.button3.Click += new System.EventHandler(this.button3_Click); this.button3.MouseEnter += new System.EventHandler(this.BtnEnter); this.button3.MouseLeave += new System.EventHandler(this.BtnLeave);
private void button1_Click(object sender, System.EventArgs e) { panel1.BackColor=System.Drawing.Color.Red; } private void BtnEnter(object sender, System.EventArgs e) { Button btn = (Button)sender; oldColor = btn.BackColor; btn.BackColor = Color.Red; switch(btn.Text) { case "красный":{ panel1.BackColor = System.Drawing.Color.Red; break; } case "желтый": { panel1.BackColor = System.Drawing.Color.Yellow; break; } case "голубой":{ panel1.BackColor = System.Drawing.Color.LightSkyBlue; break; } case "зеленый": { panel1.BackColor = System.Drawing.Color.MediumSpringGreen; break; } case "белый": { panel1.BackColor = System.Drawing.Color.White; break; } }}
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.radioButton3 = new System.Windows.Forms.RadioButton(); this.radioButton4 = new System.Windows.Forms.RadioButton(); this.radioButton5 = new System.Windows.Forms.RadioButton(); // groupBox1 // this.groupBox1.Controls.Add(this.radioButton1); this.groupBox1.Controls.Add(this.radioButton2); this.groupBox1.Controls.Add(this.radioButton3); this.groupBox1.Controls.Add(this.radioButton4); this.groupBox1.Controls.Add(this.radioButton5); this.groupBox1.Location = new System.Drawing.Point(21, 20); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(146, 220); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Цвет фона"; //
private void bkgChanged(object sender, System.EventArgs e) { RadioButton rb = (RadioButton)sender; switch(rb.Text) { case "красный": { label1.BackColor = Color.LightCoral; break; } case "зеленый": { label1.BackColor = Color.LightGreen; break; } case "голубой": { label1.BackColor = Color.LightBlue; break; } case "белый": { label1.BackColor = Color.White; break; } case "желтый": { label1.BackColor = Color.Yellow; break; }