|
-
Jan 4th, 2009, 06:36 PM
#1
Re: [2008] Creating a finer Pen
Please tell me that you haven't actually used CreateGraphics.DrawLine in your code. If you ever do call CreateGraphics, which should be a very, VERY rare thing, then you need to keep a reference to the Graphics object it creates so that you can dispose it, which you should almost always do with a Using block:
vb.net Code:
Using g As Graphics = myControl.CreateGraphics() 'Use g here. End Using
The reason that you should almost never need to call CreateGraphics is that you should do all your drawing in the Paint event handler or OnPaint method of the control, which already has a Graphics object provided via the PaintEventArgs object you get from the 'e' parameter.
-
Jan 4th, 2009, 06:53 PM
#2
Thread Starter
Hyperactive Member
Re: [2008] Creating a finer Pen
It sounds like i am doing this completely wrong, the code as follows is a sub within a module that accepts the picturebox, maximum score and the scores. Could you point out what i shouldnt be doing.
I am not being ignorant by not replying straight away, i need to go offline until tomorrow, thanks for having a look.
Code:
Public Sub GraphSub(ByVal pb As PictureBox, ByVal pbMaxH As Integer, ByVal Scores As Integer())
Dim MaxSplit As Double, WidSplit As Double, ScH As Double
Dim LastPoint As New Point
Dim LastX As Integer, LastY As Integer
pb.CreateGraphics.Clear(pb.BackColor)
MaxSplit = pb.Height / pbMaxH
For i As Integer = 0 To Scores.GetUpperBound(0)
ScH = Scores(i) * MaxSplit
WidSplit = Math.Round((pb.Width - LastPoint.X) / ((Scores.Length + 1) - i))
LastPoint.X = CInt(LastPoint.X + WidSplit)
LastPoint.Y = CInt(Math.Round(pb.Height - ScH))
pb.CreateGraphics.DrawLine(Pens.Red, LastPoint.X, LastPoint.Y, LastPoint.X, pb.Height)
pb.CreateGraphics.DrawRectangle(Pens.Red, LastPoint.X - 2, LastPoint.Y - 2, 4, 4)
pb.CreateGraphics.DrawLine(Pens.Blue, LastX, LastY, LastPoint.X, LastPoint.Y)
LastY = LastPoint.Y
LastX = LastPoint.X
Next
End Sub
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
|