Sunday, 18 December 2016

Graphics for Visual Basic

Conceptual Differences


In Visual Basic 6.0, graphics methods apply only to the Form object and to the PictureBox control.
In Visual Basic 2008, graphics methods apply to forms, plus any control that supports the Paint event, including the PictureBox, Panel, and GroupBox controls. Additionally, graphics methods apply to any controls that support the OwnerDraw property, including theListView, TreeView, and Button controls.

AutoRedraw Property

In Visual Basic 6.0, graphics methods can be called from any event procedure; the AutoRedraw property is used to persist graphics when graphics methods are called from an event other than the Paint event.
In Visual Basic 2008, graphics methods should only be called from the Paint event procedure, or in the case of some owner-drawn controls, from the various Draw event procedures (DrawItem, DrawSubItem, etc.). The AutoRedraw property is no longer supported and is not necessary because the Paint and Draw events automatically persist graphics.

ClipControls Property

In Visual Basic 6.0, the ClipControls property is used to control the painting of a form or control. When set to True, only newly exposed areas are repainted, in theory, improving performance.
There is no equivalent for the ClipControls property in Visual Basic 2008; performance enhancements in GDI+ and up-to-date video adapters make it unnecessary.

DrawMode Property

In Visual Basic 6.0, the DrawMode property controls the color of a graphics object when drawing one pattern on top of another. This property only affects monochrome or low-resolution displays (256 colors or less).
There is no equivalent for the DrawMode property in Visual Basic 2008; it is no longer necessary with current displays.

DrawStyle Property

In Visual Basic 6.0, the DrawStyle property controls the appearance of a line drawn using the Line method. If the DrawWidth property is set to a value greater than 1, the DrawStyle property has no effect and the line will always be solid.
In Visual Basic 2008, the appearance of a line is controlled by setting the DashStyle property of a System.Drawing.Pen class used by one of the DrawLine methods; line width has no bearing on this property.

DrawWidth Property

In Visual Basic 6.0, the DrawWidth property determines the thickness of a line in pixels; the DrawWidth property is typically set before performing a graphics method.
In Visual Basic 2008, the Pen.Width property of a System.Drawing.Pen control determines line thickness; you can set the Widthproperty as a parameter when you create the Pen, or by setting Pen.Width after the Pen is created. If no Pen.Width property is specified, the default is 1 pixel.

Image Property

In Visual Basic 6.0 the Image property of a form or PictureBox control returns a handle to a bitmap; the handle can be assigned to thePicture property or used as a value to pass to Windows API calls.
In Visual Basic 2008, bitmaps no longer have handles; the actual bitmap itself is passed as an object of type Bitmap. A Bitmap control can be assigned to the Image property of a PictureBox control, but it cannot be passed to Windows API calls.

Line Method

In Visual Basic 6.0, the Line method is used to draw a rectangle by specifying the top left and lower coordinates, along with an optional argument B. The FillColor property is used to fill a rectangle with a solid color, and the FillStyle property fills the rectangle with a crosshatch pattern.
In Visual Basic 2008, the DrawRectangles method is used to draw the border of a rectangle, and the FillRectangle method is used to fill it. FillRectangle takes a Brush object as a parameter. The SolidBrush replaces the FillColor property and members of the HatchBrushclass replace the FillStyle property.

Point Method

In Visual Basic 6.0, the Point method of a form or PictureBox control is used to return a color value for the pixel at a specified point. Although the Point method can be used for forms or controls that do not contain a picture, it is most often used to retrieve a color from a bitmap assigned to the Picture property.
In Visual Basic 2008, the Point method no longer exists. You can use theM:System.Drawing.Bitmap.GetPixel(System.Int32,System.Int32) method to retrieve a color value from a bitmap. For forms or controls that do not contain a picture, you can query the BackColor property.

Print Method

In Visual Basic 6.0, the Print method is used to display text on a form or PictureBox control. The font used to display the text is determined by the Font properties of the form or control, and the color is determined by the ForeColor property. The Print method offers no control for the location of the text and can only display text horizontally.
In Visual Basic 2008, the DrawString method is used to display text. The font is determined by a Font object, and the color is determined by a Brush object; both are passed as parameters to the DrawString method. The DrawString method also has X and Yparameters that determine the starting location for the text. There is also an optional Format parameter that takes a StringFormat object, allowing you to display text vertically.

PSet Method

In Visual Basic 6.0, the PSet method is used to change the color of a pixel on a form or PictureBox control. If the DrawWidth property is set to a value greater than 1, the PSet method draws a filled circle. An optional parameter is used to specify the color; if omittedForeColor is used.
In Visual Basic 2008, there is no equivalent for the PSet method. To change the color of a single pixel on a form or the PictureBoxcontrol, use the DrawEllipse method to draw a circle with a height and width of 1 pixel. To duplicate the functionality of PSet whenDrawWidth is greater than 1, use the FillEllipse method.

Code for Change shape of Ellipse

  Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim shape As New System.Drawing.Drawing2D.GraphicsPath
        shape.AddEllipse(0, 0, Me.Width, Me.Height)
        Me.Region = New System.Drawing.Region(shape)
    End Sub

Code for Change shape of Bezier

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim shape As New System.Drawing.Drawing2D.GraphicsPath
        shape.AddBezier(0, 0, 67, 545, 443, 23, 23, 23)
        Me.Region = New System.Drawing.Region(shape)
    End Sub


0 comments:

Post a Comment