📄 form1.cs
字号:
namespace ch9_12
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.ListBox listBox1;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.listBox1.Items.Add("String 1");
this.listBox1.Items.Add("String 2");
this.listBox1.Items.Add("String 3");
this.listBox1.Items.Add("String 4");
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container ();
this.button1 = new System.Windows.Forms.Button ();
this.radioButton2 = new System.Windows.Forms.RadioButton ();
this.radioButton1 = new System.Windows.Forms.RadioButton ();
this.listBox1 = new System.Windows.Forms.ListBox ();
//@this.TrayHeight = 0;
//@this.TrayLargeIcon = false;
//@this.TrayAutoArrange = true;
button1.Location = new System.Drawing.Point (280, 424);
button1.Size = new System.Drawing.Size (75, 23);
button1.TabIndex = 3;
button1.Text = "&Close";
button1.Click += new System.EventHandler (this.button1_Click);
radioButton2.Location = new System.Drawing.Point (152, 368);
radioButton2.Text = "Change Color";
radioButton2.Size = new System.Drawing.Size (280, 23);
radioButton2.TabIndex = 2;
radioButton2.CheckedChanged += new System.EventHandler (this.radioButton2_CheckedChanged);
radioButton1.Location = new System.Drawing.Point (152, 344);
radioButton1.Text = "Change Font";
radioButton1.Size = new System.Drawing.Size (280, 23);
radioButton1.TabIndex = 1;
radioButton1.CheckedChanged += new System.EventHandler (this.radioButton1_CheckedChanged);
listBox1.Location = new System.Drawing.Point (120, 24);
listBox1.Size = new System.Drawing.Size (392, 289);
listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
listBox1.TabIndex = 0;
listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler (this.listBox1_DrawItem);
listBox1.SelectedIndexChanged += new System.EventHandler (this.listBox1_SelectedIndexChanged);
this.Text = "Form1";
this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
this.ClientSize = new System.Drawing.Size (648, 517);
this.Controls.Add (this.button1);
this.Controls.Add (this.radioButton2);
this.Controls.Add (this.radioButton1);
this.Controls.Add (this.listBox1);
}
protected void listBox1_SelectedIndexChanged (object sender, System.EventArgs e)
{
this.listBox1.Refresh();
}
protected void button1_Click (object sender, System.EventArgs e)
{
Close();
}
protected void radioButton2_CheckedChanged (object sender, System.EventArgs e)
{
this.listBox1.Refresh();
}
protected void radioButton1_CheckedChanged (object sender, System.EventArgs e)
{
this.listBox1.Refresh();
}
protected void listBox1_DrawItem (object sender, System.Windows.Forms.DrawItemEventArgs e)
{
// Get the text
string text = (string)this.listBox1.Items[e.Index];
// If it is selected, make it capitalized
if ( e.Index == this.listBox1.SelectedIndex )
{
string temp = "";
for ( int i=0; i<text.Length; ++i)
{
temp += Char.ToUpper(text[i]);
}
text = temp;
}
// Clear the drawing region
e.Graphics.FillRectangle( new SolidBrush(System.Drawing.Color.White), e.Bounds );
// Determine if we are changing the font or the color
if ( this.radioButton1.Checked )
{
Font myFont = new Font("Arial", 14);
e.Graphics.DrawString( text, myFont, new SolidBrush( System.Drawing.Color.Black), e.Bounds );
}
else
if ( this.radioButton2.Checked )
{
e.Graphics.DrawString( text, Font, new SolidBrush( System.Drawing.Color.Blue), e.Bounds );
}
else
{
e.Graphics.DrawString( text, Font, new SolidBrush( System.Drawing.Color.Black), e.Bounds );
}
}
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
Application.Run(new Form1());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -