The ControlPaint
class has many useful tools for painting common control-related graphical elements. It includes a DrawFocusRectangle
method, which should do what you are looking for. From the MSDN:
Draws a focus rectangle on the specified graphics surface and within the specified bounds.
...
A focus rectangle is a dotted rectangle that Windows uses to indicate what control has the current keyboard focus.
It's a Shared
method, so you can call it without creating an instance of the ControlPaint
class, for instance:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ControlPaint.DrawFocusRectangle(Button1.CreateGraphics(), Button1.ClientRectangle)
End Sub
There is also an overload to the method which allows you to specify the foreground and background color.
It's in the System.Windows.Forms
namespace, defined by the System.Windows.Forms.dll
library, so it's not technically part of the System.Drawing
library, like you requested, but you should be able to reference and use that library even outside of a WinForm application, if necessary.