C#: How to control the behavior of the TAB Key ???

Salmaan

Newcomer
Joined
Aug 20, 2003
Messages
21
Hello,
I am using C# on the VS.NET platform. I have this application that requires the TAB key to function in a different manner.
I want to know how I can control the behavior of the TAB key in my Application???
If there is no way to control the TAB key, is it possible to disable it completely in my application ????? :confused:

Any help would be greatly appreciated.

Thanks.
 
I don't think you'll have any luck with that !

I'll have three options to solve your problem... :

1st: Use multiple panels and play with their visible property as you like... It works real fine...

2nd: A tech a bit like the above but instead of panels use Forms! Yeah... you can add a form into other form just like any other control! Crazy isn't it!:D For this you'll just have to set the hided property TopLevel = False and make the windows border = none... with this just add the form by code! You can find infinit benifits in this...

3rd: This is the easyest but the worst! You can use a free tabcontrol from CrownWood (now it isn't free anymore but I'm sending you the last free version). ATENTION !: It have some problems with DataBinding...

Sorry ... I don't know how to post attachments...
See this: http://www.dotnetmagic.com/
If you wna't the free version give-me your email or figure out how to post files ! :D Sorry ...
 
Last edited:
Hi there,

Thank you for the quick response. I will try out the three options you provided. I will let you know if I need the software.

Thanks again for the help.

Chow

Salmaan.
 
When there is a bridge...There is a way

There is a bridge...
What you want can be done. I forget how though, but there is a way to capture keydown commands before they get to the control and potentially stop or redirect them.

Maybe try overriding WndProc and listening for the KeyDown message.
 
I was wondering around the net and I've found a guy with the same problem... I mean... You can grab the key it was pressed before it is sent to the control setting the Form KeyPreview property to True...

Now the problem is get a "MousePreview" cause the user can just go there with the mouse and... Click!
Some guy just said that he've putted a transparent label over all controls and then all the mouse events are from that transparent label.

Every thing works good exept for the fact that we can't focus any component beneath !! :p

I've made a UserControl that is completly transparent and is ontop of all others controls. The only way to get to the controls beneath is to compare the click X&Y to the X&Y coordenates of the controls! And it works! you set the focus to a beneath text box and you see trough the transparent user control !
 
Build this user controls and mess around with it!
You cand use the overided OnPaint Event to draw whatever you like on the control...


Visual Basic:
Public Class TransparentUC
    Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'TransparentUC
        '
        Me.Name = "TransparentUC"
        Me.Size = New System.Drawing.Size(448, 150)

    End Sub

#End Region

    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = &H20
            Return cp
        End Get
    End Property

    Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
        'Do nothing
    End Sub

    Protected Overrides Sub OnMove(ByVal e As System.EventArgs)
        MyBase.RecreateHandle()
    End Sub

End Class
 
Ok... do it as you like... I think, and is not because it's me who is posting it :D, this is a very very good peace of code...

Please reply what you think :) Thanks
 
Maybe I'm missing the point, but can't you just handle the KeyDown, KeyPress or KeyUp events and if the key pressed is the tab key, then perform your custom action and cancel out the normal tab result?

If you need further explanation, let me know.

Apologies if I've misunderstood the problem.
 
AlexCode posted:
You can grab the key it was pressed before it is sent to the control setting the Form KeyPreview property to True

That is what I was referring to.

The reason you cannot just override KeyDown is because if a control is focused KeyDown will not be called in the Form but in the control. But if you set KeyPreview to true you probably can do this.

Another way I think is that you can override WndProc and do this the C++ way.
 
Back
Top