Hello.
On a form I have a progress bar (microsoft windows common controls 5.0)
and 2 check boxes. I want none of the 2 check boxes having the focus
rectangle. How can I do that?
Printable View
Hello.
On a form I have a progress bar (microsoft windows common controls 5.0)
and 2 check boxes. I want none of the 2 check boxes having the focus
rectangle. How can I do that?
See this post.
Thanks Bonnie, the link you posted has the solution:Code:Private Const WM_KILLFOCUS As Long = &H8
Private Declare Function SendMessageW Lib "user32.dll" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Sub Check1_Gotfocus()
SendMessageW Check1.hWnd, WM_KILLFOCUS, 0&, 0&
End Sub
Private Sub Check2_Gotfocus()
SendMessageW Check2.hWnd, WM_KILLFOCUS, 0&, 0&
End Sub
Er, as written above doesn't that prevent you from ever checking either CheckBox?
@dilettante
When using the sample above the CheckBox doesn't get checked when clicking the 1st time but when clicking the 2nd time the CheckBox is getting checked (It's a disadvantage - but I don't know a better solution at this time).
[edit post]
Argh, I've found out that the focus rectangle appears when the checkbox has a caption. So when turning the checkbox caption to a vbNullstring and adding a label beside the checkbox I get a checkbox without a focus rectangle. -That's the solution.
Here is little easy hack I just made that you could use.
To use it all you need to do is call the function on the checkbox_mousedown, better if you use array.Code:Private Function RemoveFocus(ChkBox As CheckBox)
Static FakeButton As CommandButton
If FakeButton Is Nothing Then
Set FakeButton = Controls.Add("VB.CommandButton", "FakeButton")
With FakeButton
.Move -300, -300, 30, 30
.Visible = True
End With
End If
With ChkBox
If .Value = vbChecked Then .Value = vbUnchecked Else .Value = vbChecked
End With
FakeButton.SetFocus
End Function
Example 1 (Array)
Code:Private Sub Check1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
RemoveFocus Check1(Index)
End Sub
Example 2 (regular, non-array)
Note: Do not add to the CheckBox_Click event because it will cause 'Out of stack space' error.Code:Private Sub Check2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
RemoveFocus Check2
End Sub
Thanks, but I do it using a label beside the checkbox as described in posting #5 (there is no Api needed).