Professional Documents
Culture Documents
C# Lab3
C# Lab3
tools such as Lines, Polygons, Arcs, Circles, Pies to construct a simple image. You learn how to: Create a new project. Use drawing tools to add different shapes to form. Fill the drawn regions. Add some tips to form, such as the current location of the mouse. When you finish, your program will look like the following picture.
Create a Windows Forms Application Project. Set Your Form Properties. Add Buttons controls to your form. Rename your buttons to something more meaningful. Write Codes, and run your program.
************************************* using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Linq; namespace BOAT { public partial class BOAT : Form { . . . . . . private void Form1_MouseClick(object sender, MouseEventArgs e) { ToolTip n = new ToolTip(); string s = "You are here: "+ e.Location.ToString() ;
n.SetToolTip(this, s);
}
} private void Arc_Click(object sender, EventArgs e) { g = this.CreateGraphics(); g.DrawArc(mypen, 225, 55, 50, 120, 90f, 180f); } private void Polygon_Click(object sender, EventArgs e) { g = this.CreateGraphics(); Point[] p ={new Point (1,229), new Point (1,378), new Point (571,378), new Point (571, 229)}; Pen pp = new Pen(Color.Blue, 3); g.DrawPolygon(pp, p); } private void FillPoly_Click(object sender, EventArgs e) { g = this.CreateGraphics(); Point[] p ={new Point (1,229), new Point (1,378), new Point (571,378), new Point (571, 229)}; g.FillPolygon(Brushes.Blue, p); } private void Clear_Click(object sender, EventArgs e) {
Invalidate();
} } }
Things to do: 1. 2. 3. 4. Use other tools such as circles, ellipses, etc. Add more shapes to the project, such as sun, men, birds, cloads, .. etc Try to add animation to the project, say try to make the boat moving. Try to save the created image in any image format.