Results 1 to 6 of 6

Thread: [2008] Creating a finer Pen

Hybrid View

  1. #1
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Using g As Graphics = myControl.CreateGraphics()
    2.     'Use g here.
    3. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    499

    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
  •  



Click Here to Expand Forum to Full Width