I\'m creating a custom control derived from UserControl that I would like to set focus to.
The custom control contains a ComboBox control and I draw some strings bes
Say, you have a picture on your user control and you want to highlight it mimicking the "GetFocus" event (say focus on your user control takes this picture). The focus on your user control will be handled by drawing an outline dashed line to the PictureBox. This is done through your user control OnEnter and OnLeave events. Here is the highlight procedure...
Public Sub highlightImage()
Dim l As Single() = {2, 2, 2, 2}
Dim p As New Pen(Color.Gray, 1)
p.DashPattern = l
Dim g As Graphics = picColor.CreateGraphics()
g.DrawRectangle(p, 0, 0, picColor.Width - 1, picColor.Height - 1)
End Sub
These two overrides will do the job.
Protected Overrides Sub OnEnter(e As EventArgs)
MyBase.OnEnter(e)
Me.highlightImage()
End Sub
Protected Overrides Sub OnLeave(e As EventArgs)
MyBase.OnLeave(e)
MyBase.Refresh()
End Sub