View Single Post
 
Old 05-23-2014, 10:37 AM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Welcome to the forum. Do not forget to read the forum Posting Guidelines.

christiaan01,

I have not tried running your code, but one thing leaps out at me.
You are not using the PicutureBox.Paint event to paint your graphics.

When you use the paint event Windows itself will redraw your graphics whenever it needs to. This is the easiest and most fool proof way of painting in winforms.

When you try to create a graphics object on your own you take on all the myriad things that can go wrong yourself.

Code:
Imports System.IO Public Class Form1 Dim Circles As New List(Of clsCircle) Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ' Load Circle Data from a text file If File.Exists("C:\Circles.txt") Then Dim Lines() As String = File.ReadAllLines("C:\Circles.txt") For Each Line As String In Lines Dim Segs() As String = Line.Split(","c) ' Check for x,y,radius If Segs.Count = 3 Then ' We really should make sure these are integers before we continue... Dim Circle As New clsCircle(CInt(Segs(0)), CInt(Segs(1)), CInt(Segs(2))) Circles.Add(Circle) End If Next ' Tell windows the picturebox is dirty so it redraws the first time. If Circles.Count > 0 Then PictureBox1.Invalidate() End If End Sub Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint Dim g As Graphics = e.Graphics ' If the Circles list contains objects then draw them For Each Circle as clsCircle In Circles With Circle ' The ellipse class in VB.NET draws the ellipse inside a rectangle. ' So we create the rectangle about the center point. Dim Rect As New Rectangle(.X - .Radius, .Y - .Radius, .Radius * 2, .Radius * 2) g.DrawEllipse(Pens.Blue, Rect) End With Next End Sub End Class Public Class clsCircle ' This shortened form of defining a properties ' is supported in VB.NET 2010 and above. Public Property X As Integer = 0 Public Property Y As Integer = 0 Public Property Radius As Integer = 0 Public Sub New(XValue As Integer, YValue As Integer, RadiusValue As Integer) X = XValue Y = YValue Radius = RadiusValue End Sub End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 05-23-2014 at 10:47 AM.
Reply With Quote