Command button focus indication
You know how a command button gets that "rectangle" of hash-lines when it gets focus...
Is there a way to easily stop that?
I am going to change the color to indicate what command button is clicked - I don't want that rectangle focus indicator to be on the buttom.
Re: Command button focus indication
Re: Command button focus indication
Thanks RD!
I'm curious - is it easier in .Net?
Re: Command button focus indication
Yes, you inherit the button in a class. Then use that as a control in your form. In the inherited class you override the ShowFocusCues and set the TabStop to False and done :D
VB.NET Code:
Option Strict On
Option Explicit On
Public Class MyButton
Inherits System.Windows.Forms.Button
Public Sub New()
MyBase.New()
MyBase.TabStop = False
End Sub
Protected Overrides ReadOnly Property ShowFocusCues() As Boolean
Get
Return False
End Get
End Property
End Class
Re: Command button focus indication
I wish I had time to make our main user app .Net...
Oh well - I guess it's subclassing for me on this one. btw - you can subclass many command buttons on the same form to not have the focus rectangle - right?
Re: Command button focus indication
Yes but you would pass each of their handles to the SubClass function but I dont think you can have them all pointing to the same WindowProc procedure, probably one for each. You may be better off trying to subclass the form if you have many buttons but then you will have to filter out all the other possible focussed controls by reading the wParam or lParam to check if its the desired control.
Re: Command button focus indication
Re: Command button focus indication
Additionally, just a thought but what about using the Forms Interop Toolkit to create .NET forms to use in your VB 6 project?
Re: Command button focus indication
Quote:
Originally Posted by RobDog888
Additionally, just a thought but what about using the Forms Interop Toolkit to create .NET forms to use in your VB 6 project?
We are going to start doing that - we need to add a form soon that will use a Canon SDK to drive a digital camera capture process.
But this change is to old legacy code.
We were using option-buttons to determine what flexgrids to display. Basically we hide flexgrids one under the other and you click the option-buttons in a frame to bring one flexgrid to the top.
This has been buggy and ugly since we are also "checking" the buttons from code when the form init's (as well as "adding" them at runtime by cloning one after the one). All those check events pile up in a strange way since the option buttons are all related in a control-array. The code has never been strong and we are about to add some additional "optional" display functionality - so we thought it best to leave the option-buttons behind and instead use command buttons - all touching left-to-right - and color the one that's clicked by the user. Since they don't have the option-button automatic relationship we are thinking that they will work a whole lot better.
Re: Command button focus indication
To my knowledge of programming in Visual Basic 6.00 Pro, you are trying to rewrite the whole engine, that runs the whole show of Visual Basic. I don't think that you can do this, but if you make a control, which is called Command1 and then mess around with the Focus aspect of nature of the control.
Question: Why would you want to change the focus indication of the control. Unless you were making a game or some other type of project, am I right?
Re: Command button focus indication
No, szlamany is not a game programer.
Quote:
Originally Posted by szlamany
I am going to change the color to indicate what command button is clicked - I don't want that rectangle focus indicator to be on the buttom.
This is why he wants to not use the default button behavior.
Re: Command button focus indication
I posted here a http://vbforums.com/showpost.php?p=3089877&postcount=30 a solution that uses no subclassing. on control GotFocus event that can be used. would like to no your openion on that.
Re: Command button focus indication
@ThEiMp - it's not just game programmers that search for the best visually appealing UI's...
@fazi - how does the method you posted in the other thread handle a caption on the button at the same time?
I understand that you are "hiding" the rectangle by coloring over it with the backcolor of the button...
Would it require adding a "command1_gotfocus" event that would then "do the erase" of the focus indicator?
Re: Command button focus indication
Hai szlamany,
I mean when we put the draw line function on GotFocus even on the command button. so imediatly it will erase the focus rect when ever the command button got the focus.
Re: Command button focus indication
Have you tested it with a small button where the CAPTION is large enough to be covered by the focus rectangle??
Re: Command button focus indication
I really have the issues on getting the focus rectangle's Rect. so if have the rect, i can draw over the same border with same size. so you will not loose anything. so now i need to find a way to get the focus rectangle's Rect coordinates. Ill try that an post the results ASAP. but you can carry on your project with the current solution you have :D
Re: Command button focus indication
Just to add my 2 cents
1. Using non-subclassing by drawing on GotFocus can be problematic because VB won't always send a GotFocus when a control gets the focus. This occurs specifically when VB loses focus to another app then regains focus again -- no focus event for the control is fired, though it repaints focused. This includes msgboxs & other modal popups too -- no focus event.
2. Subclassing can be done for all command buttons in one call, but this gets a little tricky. The technique is called SuperClassing and superclassing vb controls requires some extra steps vs superclassing normal window controls. I would consider this option only if one has lots & lots of command buttons; otherwise subclassing each one to the same window procedure is a bit easier to code.
Re: Command button focus indication
This is an existing application - in use since 2000. I'm actually not considering adding a GOTFOCUS event - adding events to existing applications leads to problems...
I followed RobDog's subclass method that he posted - and it's working fine. My "command buttons" are in a control array - so I just sub-classed each one (in a loop) to the same WindowProc routine...
This seems to be working fine.
Re: Command button focus indication
I have posted my results on the other thread :D
http://www.vbforums.com/showthread.p...3&goto=newpost
Sorry to Trouble YOu !
BTW, Thank LaVolp for your comments.
Re: Command button focus indication
Quote:
Originally Posted by ThEiMp
To my knowledge of programming in Visual Basic 6.00 Pro, you are trying to rewrite the whole engine, that runs the whole show of Visual Basic. I don't think that you can do this, but if you make a control, which is called Command1 and then mess around with the Focus aspect of nature of the control.
Question: Why would you want to change the focus indication of the control. Unless you were making a game or some other type of project, am I right?
There are several reasons to have a button with no focus rectangle. Even Windows XP in its navigation panne on the left in explorer uses linklabels with no focus rectangles. Its a default method used in several places thoughout Windows.