troubleshooting Question

Graphics and Bitmap High CPU with

Avatar of koossa
koossa asked on
Visual Basic.NET
6 Comments1 Solution510 ViewsLast Modified:
I have a picturebox on my Windows form.  Form's windowstate = maximize
Picturebox Dock = fill

Here is my code .

Public Class Form1

  Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    Dim MyBmp As Bitmap
    If PictureBox1.Image Is Nothing Then
      MyBmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
      MyBmp = New Bitmap(PictureBox1.Image)
    End If
    Dim MyGraphics As Graphics = Graphics.FromImage(MyBmp)
    MyGraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    MyGraphics.DrawEllipse(Pens.Blue, e.X - 50, e.Y - 50, 100, 100)
    PictureBox1.Image = MyBmp
  End Sub
End Class

When I draw circles on the form using the code above, the drawing gets very sticky and the CPU is rising.

What can I do to make it softer on the resources?

I know I can draw using Graphics.FromHwnd(picturebox1.handle), but when something moves over the form it wipes the drawing on that region.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros