I have a form and would like to have a circle follow the mouse cursor. Similarly to what is shown in Adobe Photoshop when you are in line brush mode and you can see the size of the brush you are about to draw. My problem occurs when I place a background image on the form.
To use the example code below. Create form and paste the code into the form (the size of my form is 804X584). Run the application. Initially you will have great performance. However if you give the form a background image. In my situation I just used C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Blue hills.jpg and you will see some latent circles when you move the mouse very fast. The attached picture shows you the latent circles.
I've tried using the OvalShape from Microsoft.VisualBasic.Powe
rPacks but the performance of that was even worse.
Some notes about the code below:
1. I pretty draw the circle in the function ShowQualityCircle (called from MouseMove). Here I call Invalidate without any arguments. When I tried it with a rectangle I got a number of latent circles. I even tried a larger rectangles but when I moved the mouse very fast I still got latent circles.
2. Without the call to draw the circle in the Paint routine I got a number of latent rectangles, so that was necessary.
You help would be greatly appreciated.
Public Class Form1
Private QCircle As New Rectangle(0, 0, 0, 0)
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
ShowQualityCircle((e.X), (e.Y), 20)
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If QCircle.Width > 0 AndAlso QCircle.Height > 0 Then
DrawCircle(e.Graphics, Color.Red, QCircle.X, QCircle.Y, QCircle.Width, QCircle.Height, 0, 360)
Private Sub DrawCircle(ByRef g As Graphics, ByVal currentColor As Color, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single, ByVal startAngle As Single, ByVal sweepAngle As Single)
Dim myBrush As New SolidBrush(currentColor)
Dim myPen As New Pen(myBrush)
myPen.Width = 1
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
g.DrawArc(myPen, x, y, width, height, startAngle, sweepAngle)
Private Sub ShowQualityCircle(ByVal imgX As Integer, ByVal imgY As Integer, ByVal mypenradius As Integer)
QCircle = New Rectangle(imgX - mypenradius, imgY - mypenradius, mypenradius * 2, mypenradius * 2)
Dim g As Graphics = Me.CreateGraphics()
DrawCircle(g, Color.Red, QCircle.X, QCircle.Y, QCircle.Width, QCircle.Height, 0, 360)