I don't want some command buttons on my form to take the focus when they are clicked. Is there some easy way out, like setting some properties etc. I want only the depress and release effects, no dotted rectangle.
Printable View
I don't want some command buttons on my form to take the focus when they are clicked. Is there some easy way out, like setting some properties etc. I want only the depress and release effects, no dotted rectangle.
you could just use a picture of a button - the picture box control wont draw any focus rects or depress.
The harder way is to subclass the button control.
Thanks Therob :)
I m using a picture box right now but it is very resource hungry. (Imagine more than 20 picture boxes instead of command buttons).
Why I asked this quesiton was that whenever command btn has focus (dotted rectangle), the caption wraps if it doesn't fit the button width. Just want to prevent that thing as I can't increase button size. When it doesn't have focus, the caption appears OK.
set the focus to a other control or form after OnClick event
or even onmousedown
I can't.
Their GotFocus event will get fired which would create unexpected problems!
Create a texbox called txtTakeFocus.
Form_Load should move it's left to -900 (there but not 'see a ble')
In your button click event use
VB Code:
txtTakeFocus.SetFocus
I needed to do the same thing and here is what I found:
In a Module:
VB Code:
Option Explicit 'declare external procedures Public Declare Function SetWindowLong Lib "user32" _ Alias "SetWindowLongA" _ (ByVal hwnd As Long, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Public Declare Function CallWindowProc Lib "user32" _ Alias "CallWindowProcA" _ (ByVal lpPrevWndFunc As Long, _ ByVal hwnd As Long, _ ByVal uMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long 'declare constants Public Const GWL_WNDPROC As Long = (-4) 'declare local variables Private WndProcOrig As Long Public Function BtnWndProc(ByVal hwndBtn As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long If wMsg = 7 Then BtnWndProc = 0 Exit Function Else BtnWndProc = CallWindowProc(WndProcOrig, hwndBtn, wMsg, wParam, lParam) End If End Function Public Sub SubClassBtn(ByVal hwndBtn As Long) WndProcOrig = SetWindowLong(ByVal hwndBtn, GWL_WNDPROC, AddressOf BtnWndProc) End Sub Public Sub UnSubclassBtn(ByVal hwndBtn As Long) Call SetWindowLong(hwndBtn, GWL_WNDPROC, WndProcOrig) WndProcOrig = 0 End Sub
On your Form in the Form Load Event:
VB Code:
Private Sub Form_Load() Me.Command1.TabStop = False SubClassBtn Me.Command1.hwnd End Sub
The command button will not receive the focus.
Thank u all for the replies.
RobCrombie, Ur method works OK. Only the problem is when the mouse is down, the button still looks odd.
I think I should stick to what I m doing at present (pictureboxes) or subclass the buttons (the harder way). Mark Gambo's code is really helpful and working.
Matter closed :)
Pradeep