Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw graphics by VB.NET

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces VB.NET how to draw graphics, the article is very detailed, has a certain reference value, interested friends must read it!

1. Create a Graphics object

VB.NET drawing requires you to specify a drawing surface. Where the form and all controls with Text properties can be used as surfaces for drawing graphics. Because the Graphics object identifies the drawing surface of GDI+, you must first create a Graphics object to draw a graph. There are several ways to create a Graphics object.

1 > create using the CreateGraphics method

This is a common creation method, and its format is: Dim object name As Graphics object name = form name (or control name) .CreateGraphics

2 > using PaintEventArgs parameters to pass Graphics objects

Graphics can be drawn directly through the Paint event of a form or control. When writing Paint event handlers, the parameter PaintEventArgs provides graphical objects. For example:

Private Sub Form1_Paint (ByVal sender As Object

ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim g_paint As Graphics = e.Graphics

...

End Sub

3 > create from Image object

You can also use the Image object to create it, using the Graphics.FromImage method

2.VB.NET must first be able to use a paintbrush to draw graphics.

A brush is a GDI+ object used to draw lines, and it is an instance of the Pen class. Use brushes to draw lines, curves, and borders of rectangles, circles, polygons and other shapes.

1 > create a brush

Format: Dim pen name As New Pen (color [, width]) where the color is the color of the line drawn with the brush, and the width is the width of the line drawn with the brush, in pixels. The default value for width is 1.

For example: Dim mypen As New Pen (Color.Blue) or Dim mypen As Pen = New Pen (Color.Blue)

2 > draw lines or hollow shapes

After the establishment of the brush, you can use a variety of Graphics methods to draw lines, curves or rectangular, circular and other hollow lines.

(1) DrawLine method-drawing a straight line DrawLine (pen name, X1PowerY1PowerX2pIeY2), where (X1PowerY1) and (X2PowerY2) are the coordinates of the starting point and ending point of the line, they can be Integer values or Single values. When a straight line is short, it can be approximated to a point.

(2) DrawRectangle method-draw a rectangle DrawRectangle (pen name, Xpencil Y, width, height) in which, the coordinates of the upper left corner of the rectangle, width and height specify the width and length of the rectangle.

(3) DrawPolygon method-drawing polygon DrawPolygon (brush name, vertex)

Where the vertex is an array, the array type is Point or PointF structure, and the elements of the array are used to specify the coordinates of each vertex of the polygon. The Integer type is specified by the Point structure, and the Single type is specified by PointF.

The format of using Point or PointF structure to define a point is: the function of the Dim point name As New Point/PointF (XMagol y) DrawPolygon method is to join an array of vertices in order to form a polygon, and draw an edge between two consecutive vertices.

(4) DrawEllipse method-drawing circle and ellipse DrawEllipse (pen name, Xpencil Y, width, height) method, the rectangle defined by width and height is the circumscribed rectangle of the circle or ellipse to be drawn, which determines the size and shape of the ellipse drawn. When the width and height are equal, what is drawn is a circle, otherwise it is an ellipse.

(5) DrawArc method-- Arc drawing DrawArc (pen name, XPerry Y, width, height, starting angle, scanning angle) compared with DrawEllipse method, this method has two more parameters: starting angle and scanning angle, which can be regarded as an arc formed by intercepting a circle or ellipse. The starting angle and scanning angle are measured in degrees, usually with a horizontal radius of 0 degrees to the right, and then draw an arc clockwise. The starting angle is the angle at which the arc is drawn, and the scanning angle is the angle that increases clockwise. When the scanning angle is 360 degrees, a circle or ellipse is drawn.

(6) DrawPie method-drawing pie chart DrawPie (pen name, XMagy Y, width, height, starting angle, scanning angle) pie chart is also called fan chart. This method has the same parameters as the DrawArc method, but the pie chart has two more radii than the arc.

The above is all the content of the article "how to draw graphics in VB.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report