using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms;
using System.Drawing.Drawing2D; namespace GDISample { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.CheckBox checkBox1; private System.ComponentModel.Container components = null; public Form1() { Windows InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.textBox2 = new System.Windows.Forms.TextBox(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.listBox1 = new System.Windows.Forms.ListBox(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); this.textBox2.Location = new System.Drawing.Point(16, 32); this.textBox2.Multiline = true; this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(144, 64); this.textBox2.TabIndex = 4; this.textBox2.Text = "textBox2"; this.textBox2.Leave += new System.EventHandler(this.refreshForm); this.textBox2.Enter += new System.EventHandler(this.getPainted); this.comboBox1.DropDownWidth = 136; this.comboBox1.Location = new System.Drawing.Point(176, 32); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(112, 21); this.comboBox1.TabIndex = 3; this.comboBox1.Text = "comboBox1"; this.comboBox1.Leave += new System.EventHandler(this.refreshForm); this.comboBox1.Enter += new System.EventHandler(this.getPainted); this.listBox1.Location = new System.Drawing.Point(16, 112); this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(144, 95); this.listBox1.TabIndex = 5; this.listBox1.Leave += new System.EventHandler(this.refreshForm); this.listBox1.Enter += new System.EventHandler(this.getPainted); this.checkBox1.Location = new System.Drawing.Point(184, 72); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(104, 32); this.checkBox1.TabIndex = 6; this.checkBox1.Text = "checkBox1"; this.checkBox1.Enter += new System.EventHandler(this.getPainted); this.checkBox1.Leave += new System.EventHandler(this.refreshForm); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(744, 557); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.checkBox1, this.listBox1, this.textBox2, this.comboBox1}); this.Name = "Form1"; this.Text = "Form1"; this.Enter += new System.EventHandler(this.getPainted); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void PaintMe( Control controlToPaint) { Graphics g = CreateGraphics(); Pen pen = new Pen(Color.Yellow,5);
Pen pen2 = new Pen(Color.Black,7); int p1 = controlToPaint.Left; int p2 = controlToPaint.Top; int p3 = controlToPaint.Width; int p4 = controlToPaint.Height;
g.DrawRectangle(pen2,p1,p2,p3,p4); g.DrawRectangle(pen,p1,p2,p3,p4); } private void getPainted(object sender,System.EventArgs e) { PaintMe((Control)sender);object } private void refreshForm(object sender,System.EventArgs e) { Form1.ActiveForm.Refresh() ; } } } |