Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to display or hide standard trackbar cues,and how override ReadOnly Property ShowFocusCues by VB.net,not BY C#.Thanks.
Posted

You can always make control unable to get keyboard focus at all by removing the flag System.Windows.Forms.ControlStyles.Selectable from control's style by using System.Windows.Forms.Control.SetStyle. This is a protected method, so you can only call it if you subclass your control and call this method in your derived control's constructor. It will not show any focus cues, of course. You can change the control styles during run-time if you created and expose some method doing so as internal or public.

See
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[^].

To override the read-only property like System.Windows.Forms.Control.ShowFocusCues, just override its getter. Please see this code sample:
http://stackoverflow.com/questions/554369/overriding-readonly-property-in-a-subclass-to-make-it-read-write-vb-net[^].

A note: if you want to get really good help, I would advise you to stop demanding "not C#". Of course, in MSDN samples you can always switch the declaration and sample code to VB.NET. By that reason, I always prefer showing MSDN references. However, people who can write decent original sample mostly write in C#. This is not anyone's preoccupation but a real-life social phenomena. Microsoft also does not take VB.NET seriously; anyone can see many signs of it. So without understanding of at least some C# you cannot get all the help you need and may have problems in your work. As soon as you start .NET development, understanding of C# is highly desirable.

—SA
 
Share this answer
 
v4
Thank you for your answer.But by System.Windows.Forms.ControlStyles.Selectable ,we can get the focus lost in many controls,like button,but Trackbar.When I override showfocuscus like below,
VB
Class CustomTrackbar
    Inherits System.Windows.Forms.TrackBar

    Private _DisplayFocusCue As Boolean = True
    <BrowsableAttribute(False)> _
    Protected Overrides ReadOnly Property ShowFocusCues() As Boolean
        Get
            Return _DisplayFocusCue
        End Get
    End Property

    Public Property DisplayFocusCues() As Boolean
        Get
            Return _DisplayFocusCue
        End Get
        Set(ByVal value As Boolean)
            _DisplayFocusCue = value
        End Set
    End Property
End Class

When I set the Property false.It cann't work correct.But when I inherits System.Windows.Forms.Button,It works correct.Please help me.thanks.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900