VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,756 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm learning VB 2010 programming, using windows 10. I've added a windows form and added the following imports:
Imports System
Imports System.Drawing.Drawing2D
And these Dims:
Public Class MyForm
Dim myGraphics As Graphics = Me.CreateGraphics
Dim myPen As Pen
In the form load event is this code:
Private sub MyForm_load(...
myPen = New Pen(Drawing.Color.Blue, 15)
myGraphics.DrawLine(myPen, 50, 50, 50, 5)
When ran, nothing appears on the form. What am I doing wrong?
Drawing in the form load event is the wrong event to use. You should be doing your drawing in the Paint event This way when the form needs to be repainted your graphics will be there
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Dim myPen = New Pen(Drawing.Color.Blue, 15)
e.Graphics.DrawLine(myPen, 50, 50, 50, 5)
End Sub