What replaces the old line/circle/shape control in visual studio 2022 (VB)?

Gary Smith 5 Reputation points
2023-05-04T05:34:25.63+00:00

I haven't used Visual Basic for over 20 years, but now I am back to it. What can I do to draw a line or circle? There used to be a shape control. What replaces that?

Also, is there a good replacement for the scroll bars? It seems like the ones in Visual Studio can't change their color.

Any help for an old dog would be appreciated.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,759 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,625 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 27,501 Reputation points Microsoft Vendor
    2023-05-04T06:38:50.4433333+00:00

    Hi @Gary Smith ,

    You can use a panel control and use the graphics drawing functions in the System.Drawing namespace to achieve.

    Here is an example about drawing a circle.

        Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
            'Create a Graphics object
            Dim g As Graphics = e.Graphics
            'Create a circular path
            Dim path As New Drawing2D.GraphicsPath()
            path.AddEllipse(0, 0, Panel1.Width - 1, Panel1.Height - 1)
            'Fill the path with color
            g.FillPath(Brushes.Blue, path)
            'Draw a border on the path
            g.DrawPath(Pens.Black, path)
        End Sub
    

    If you want to modify the color of the ScrollBar, you can customize the appearance of the ScrollBar by extending the System.Windows.Forms.ScrollBar class and overriding the OnPaint method.

    Use the following code to customize the scrollbar, then you can add the custom scrollbar to your form.

    Imports System.Drawing.Drawing2D
    
    Public Class CustomScrollBar
         Inherits System.Windows.Forms.ScrollBar
    
         'Override the OnPaint method
         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
             MyBase. OnPaint(e)
    
             'Create a Graphics object
             Dim g As Graphics = e. Graphics
    
             'Set the background color to red
             g.Clear(Color.Red)
    
             'Create slider path
             Dim path As New GraphicsPath()
             path.AddRectangle(New Rectangle(0, 0, Me.Width, Me.Height))
    
             'Set the slider color to yellow
             g. FillPath(Brushes. Yellow, path)
         End Sub
    End Class
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments