31c

9

Click here to load reader

Transcript of 31c

Page 1: 31c

C# Tutorial

Part 32: GDI

www.siri-kt.blogspot.com

Page 2: 31c

• GDI(graphical designing interface):• The c#.net windows application by default supports only GUI features using GUi

feature we can add all controls on the form container. using GDi we can give 2D & 3D graphics‘ Microsoft assigned these features in the system.drawing.drawing2d;

• Graphics(class):• using this class we can convert windows form mode into GDI mode.this class supports

3 predefined methods

• 1.Drawstring()

• 2.DrawImage()

• 3.DrawEllipse()

• 1.Drawstring():• using this method we can display string value on the form container. this method takes

5 parameters

• 1.string

• 2.font

• 3.brush

• 4.form x-location

• 5.form y-location

Page 3: 31c

• 1.take the form

• 2.add timer control(windows.forms.timer)

• goto-timer-properties-enabled=true interval=10

• source code:

• using System.Drawing.Drawing2D;

• string s = "INDIA";

• Font f = new Font("Ariel", 100);

• Graphics g;

• int i;

• private void timer1_Tick(object sender, EventArgs e)

• { LinearGradientBrush b = new LinearGradientBrush(new PointF(100, 100), new PointF(200, i), Color.Red, Color.Green);

• g = this.CreateGraphics();

• g.DrawString(s, f, b, 100, 100);

• i++;

• if (i == 100)

• { i = 0; } }

Page 4: 31c

• 2.DrawImage():• using this method we can display image on the form container this method takes 2

parameters• 1.image(image.fromfile("path"))• 2.rectangle class

• Rectangle class:• using this class we can display rectangle on this form conatiner. • this class takes 4 constructor parameters• 1.form x location• 2.form y location• 3.Rectangle width• 4.Rectangle height

• Example on drawimage():• 1.take the form• 2.add timer control

Page 5: 31c

• goto-timer-properties-enabled=true interval=10

• goto-solution explorer-add existing item-*.gif images

• source code:

• using System.Drawing.Drawing2D;

• Graphics g;

• int i;

• private void timer1_Tick(object sender, EventArgs e)

• { g = this.CreateGraphics();

• Rectangle r = new Rectangle(i, i, i, i); g.DrawImage(Image.FromFile("E:\\7pmonline\\DrawInageExample\\DrawInageExample\\smallSuccess.gif"),r);

• i++;

• if (i == 200)

• { i = 0;

• } }

Page 6: 31c

• 3.DrawEllipse(): • using this method we can display ellipse on the from container this method takes

5-parameters

• 1.pen structure

• 2.form x-location

• 3.form y-location

• 4.ellipse height

• 5.ellipse width

• example on drawellipse():

• 1.take the form

• 2.add timer control

Page 7: 31c

• goto-timer-properties-enabled=false,interval=10;

• form1-properties-windowstate=maximized

• form1-events-mousedown(doubleclick)

• form1-events-mouseup(doubleclick)

• source code:

• using System.Drawing.Drawing2D;

• int x, y;

• Graphics g;

• int i;

• private void Form1_MouseDown(object sender, MouseEventArgs e)

• { x = e.X;

• y = e.Y;

• timer1.Enabled = true; }

Page 8: 31c

• private void Form1_MouseUp(object sender, MouseEventArgs e)

• { i = 0;• timer1.Enabled = false; }• private void timer1_Tick(object sender,

EventArgs e)• { g = this.CreateGraphics();• g.DrawEllipse(new Pen(new

SolidBrush(Color.Green), 1), x, y, i, i);• i++; }

Page 9: 31c

For more visit our website www.siri-kt.blogspot.com

Thanks for Watching

More Angular JS TutorialsMore C sharp (c#) tutorials