Results 1 to 20 of 20

Thread: Command button focus indication

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Command button focus indication

    Thanks RD!

    I'm curious - is it easier in .Net?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. Public Class MyButton
    5.  
    6.     Inherits System.Windows.Forms.Button
    7.  
    8.     Public Sub New()
    9.         MyBase.New()
    10.         MyBase.TabStop = False
    11.     End Sub
    12.  
    13.     Protected Overrides ReadOnly Property ShowFocusCues() As Boolean
    14.         Get
    15.             Return False
    16.         End Get
    17.     End Property
    18.  
    19. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Command button focus indication

    Thanks!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    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?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  12. #12
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    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.

  13. #13

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  14. #14
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    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.

  15. #15

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  16. #16
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    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

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.

  18. #18

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  19. #19
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    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.

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width