0% found this document useful (0 votes)
91 views13 pages

Electro-Team: Interesting Education Visual Basic 2010 Graphics

This document discusses drawing basic shapes in Visual Basic 2010 graphics. It provides code examples for drawing a line, rectangle, and customized line styles. The line drawing code creates a Graphics object, Pen, and uses the DrawLine method to draw between two points. The rectangle code uses DrawRectangle to draw a shape defined by x,y coordinates and width/height. Custom line styles can be set by changing the Pen's DashStyle property before drawing.

Uploaded by

Mohamad Saad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views13 pages

Electro-Team: Interesting Education Visual Basic 2010 Graphics

This document discusses drawing basic shapes in Visual Basic 2010 graphics. It provides code examples for drawing a line, rectangle, and customized line styles. The line drawing code creates a Graphics object, Pen, and uses the DrawLine method to draw between two points. The rectangle code uses DrawRectangle to draw a shape defined by x,y coordinates and width/height. Custom line styles can be set by changing the Pen's DashStyle property before drawing.

Uploaded by

Mohamad Saad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Electro-Team

Interesting Education Visual Basic 2010 Graphics

[email protected]

Agenda
Drawing Line
Drawing Rectangle

New Project

Windows Forms Application

Drawing Line
Add Button From Toolbox

Double Click On Button1


Private Sub Button1_Click
Dim x As Drawing.Graphics = Me.CreateGraphics

Dim myPen As Pen


myPen = New Pen(Brushes.Olive, 10) x.DrawLine(myPen, 10, 10, 100, 10)

End Sub

Code Illustration
Creating the Graphics Object: Dim x As Drawing.Graphics = Me.CreateGraphics Creating a Pen: Dim myPen As Pen myPen = New Pen(Brushes.Olive, 10)

Where myPen is a Pen variable. The first argument define the color of the line and the second argument define the width of the line.
x.DrawLine(myPen, 10, 10, 100, 10) Draw a line on the Form using the DrawLine method. The first argument use the Pen object , the second and third arguments define the starting coordinate the fourth and the last arguments define the ending coordinate of the line. The general syntax of the Drawline argument is : object.DrawLine(Pen, x1, y1, x2, y2)

Run Time

Challenge Yourself Try to modify Button 1 Code to get below result


Private Sub Button1_Click Dim x As Drawing.Graphics = Me.CreateGraphics Dim myPen As Pen myPen = New Pen(Brushes.Olive, 150) x.DrawLine(myPen, 10, 10, 100, 10) End Sub

Answer

Creating Rectangles
Private Sub Button1_Click
Dim x As Drawing.Graphics = Me.CreateGraphics

Dim myPen As Pen


myPen = New Pen(Brushes.Olive, 10)

x.DrawRectangle(myPen, 0, 0, 100, 50)

End Sub

Run Time

What is wrong .!!?


x.DrawRectangle(myPen, 0, 0, 100, 50)

Customizing Line Style


Private Sub Button1_Click
Dim x As Drawing.Graphics = Me.CreateGraphics

Dim myPen As Pen


myPen = New Pen(Drawing.Color.Red, 5)
myPen.DashStyle = Drawing.Drawing2D.DashStyle.Dash

x.DrawRectangle(myPen, 10, 10, 100, 50)

End Sub

Run Time

The End
Produced by

Electro-Team
[email protected]

You might also like