using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace PS6_Q2 { // // Problem Set 6, Question 2 // Written by Paul Hudak // October 27, 2006 // public class Form1 : System.Windows.Forms.Form { // // Rectangle appears and disappears on mouse clicks. // (Problem 16 in Chapter 8.) // private System.ComponentModel.Container components = null; // instance variables to keep track of rectangle bool present = false; // no rectangle to start int x; // x and y coordinates of rectangle int y; int mx; // x and y coordinates of mouse int my; int len = 50; // length and width of rectangle int wid = 25; public Form1() { // Required for Windows Form Designer support InitializeComponent(); Size = new Size(300,300); Text = "Magic Rectange"; } protected override void OnPaint(PaintEventArgs e) { // get handle on graphics window Graphics g = e.Graphics; if (present) g.FillRectangle(Brushes.Blue,x,y,len,wid); } protected override void OnMouseDown(MouseEventArgs e) { mx = e.X; my = e.Y; base.OnMouseDown (e); } protected override void OnDoubleClick(EventArgs e) { if (x /// 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 // The main entry point for the application. [STAThread] static void Main() { Application.Run(new Form1()); } } }