-
May 13th, 2015, 12:58 PM
#1
Thread Starter
Junior Member
How to update graphics at a form
Hello,
I'm trying to understand how to events work (I'm NET beginner), so my code looks like:
Code:
Public Class Form1
Public x As Single()
Public y As Single()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = New Single(1) {100, 200}
y = New Single(1) {100, 100}
End Sub
Public Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawLine(Pens.Beige, x(0), y(0), x(1), y(1))
Label1.Text = "Line is OK"
End Sub
Private Sub Form1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseClick
MsgBox("Mouse clicked")
y(0) = 200 : y(1) = 200
Me.Label1.Text = "Line is moved"
End Sub
End Class
Unfortunately when mouse is clicked on form, the msgbox is shown only, but Line is not moved and Label is not changed...
What's wrong with this code?
-
May 13th, 2015, 01:30 PM
#2
Re: How to update graphics at a form
In mouse.click event handler, after you set the values for x and y, you call the the form's Refresh method to repaint the whole form or for better performance, you use the form.Invalidate method and specify the region you want to repaint in the arguments.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|