|
-
Dec 22nd, 2007, 12:31 PM
#1
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.
-
Dec 22nd, 2007, 12:34 PM
#2
Re: Command button focus indication
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 22nd, 2007, 12:35 PM
#3
Re: Command button focus indication
Thanks RD!
I'm curious - is it easier in .Net?
-
Dec 22nd, 2007, 12:39 PM
#4
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 
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 22nd, 2007, 12:41 PM
#5
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?
-
Dec 22nd, 2007, 12:48 PM
#6
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 22nd, 2007, 12:49 PM
#7
Re: Command button focus indication
-
Dec 22nd, 2007, 12:49 PM
#8
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?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 22nd, 2007, 01:46 PM
#9
Re: Command button focus indication
 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.
-
Dec 23rd, 2007, 02:04 AM
#10
PowerPoster
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?
-
Dec 23rd, 2007, 05:13 AM
#11
Re: Command button focus indication
No, szlamany is not a game programer.
 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.
-
Dec 23rd, 2007, 05:30 AM
#12
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.
-
Dec 23rd, 2007, 09:02 AM
#13
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?
Last edited by szlamany; Dec 23rd, 2007 at 09:06 AM.
-
Dec 23rd, 2007, 10:23 AM
#14
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.
-
Dec 23rd, 2007, 10:45 AM
#15
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??
-
Dec 23rd, 2007, 10:55 AM
#16
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
-
Dec 23rd, 2007, 11:03 AM
#17
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.
-
Dec 23rd, 2007, 11:20 AM
#18
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.
-
Dec 23rd, 2007, 11:24 AM
#19
Re: Command button focus indication
I have posted my results on the other thread 
http://www.vbforums.com/showthread.p...3&goto=newpost
Sorry to Trouble YOu !
BTW, Thank LaVolp for your comments.
-
Dec 23rd, 2007, 12:14 PM
#20
Re: Command button focus indication
 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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
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
|