Hi i am wondering how to use DrawString outside the form so I am can see the coordinates of my mouse even when the form is closed.
Can anyone help?
Hi i am wondering how to use DrawString outside the form so I am can see the coordinates of my mouse even when the form is closed.
Can anyone help?
You always need a form to draw on. The trick is to make everything about the form except your text invisible. This can be done by using the forms Backcolor
and TransparencyKey
properties. Take this form as an example.
Public Class Form1
Dim WithEvents timer As New Timer With {.Interval = 500}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackColor = Color.Pink
Me.TransparencyKey = Color.Pink
Me.TopMost = True
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
timer.Start()
End Sub
Private Sub timer_Tick(sender As Object, e As EventArgs) Handles timer.Tick
Using g As Graphics = Me.CreateGraphics
g.Clear(Color.Pink)
g.DrawString(MousePosition.ToString, New Font("Arial", 20), Brushes.Red, New PointF(10, 10))
End Using
End Sub
End Class
Every color on the form that has the TransparencyKey
color is transparent. This makes only the text you draw on the form visible. Set the TopMost
property to keep the form from dropping behind other applications.