|
-
Jun 12th, 2013, 03:00 PM
#1
Thread Starter
Addicted Member
[RESOLVED] How can I remove the focus rectangle?
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?
-
Jun 12th, 2013, 03:25 PM
#2
Re: How can I remove the focus rectangle?
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Jun 12th, 2013, 04:26 PM
#3
Thread Starter
Addicted Member
Re: How can I remove the focus rectangle?
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
-
Jun 12th, 2013, 04:39 PM
#4
Re: How can I remove the focus rectangle?
Er, as written above doesn't that prevent you from ever checking either CheckBox?
-
Jun 12th, 2013, 06:03 PM
#5
Thread Starter
Addicted Member
Re: How can I remove the focus rectangle?
@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.
Last edited by vb.elmar; Jun 12th, 2013 at 06:43 PM.
-
Jun 12th, 2013, 06:59 PM
#6
Re: [RESOLVED] How can I remove the focus rectangle?
Here is little easy hack I just made that you could use.
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
To use it all you need to do is call the function on the checkbox_mousedown, better if you use array.
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)
Code:
Private Sub Check2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
RemoveFocus Check2
End Sub
Note: Do not add to the CheckBox_Click event because it will cause 'Out of stack space' error.
-
Jun 14th, 2013, 08:45 AM
#7
Thread Starter
Addicted Member
Re: [RESOLVED] How can I remove the focus rectangle?
Thanks, but I do it using a label beside the checkbox as described in posting #5 (there is no Api needed).
Last edited by vb.elmar; Jun 14th, 2013 at 08:51 AM.
-
Jun 14th, 2013, 09:12 AM
#8
Re: [RESOLVED] How can I remove the focus rectangle?
 Originally Posted by vb.elmar
... but I do it using a label beside the checkbox as described in posting #5 (there is no Api needed).
Keep in mind though, that any control (including windowless controls) always have greater overhead than a simple API call.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|