Overriding method

M

Mike

Hi,

I have such problem:
On my form I have TabControl. I want to move from one tab to another
using "Next" and "Prev" button. This part works fine.

But control also supports switching between TabPagess using
combination of buttons Ctrl+Tab (forward) and Ctrl+Shift+Tab (back). I
would like to suppress such possibility.

The first think that I tried - set "TabStop" to False.

Also at the article "Control.KeyDown Event " I found such text:
"To handle keyboard events only at the form level and not allow other
controls to receive keyboard events, set the KeyPressEventArgs.Handled
property in your form's KeyPress event-handling method to true.
Certain keys, such as the TAB, RETURN, ESCAPE, and arrow keys are
handled by controls automatically. In order to have these keys raise
the KeyDown event, you must override the IsInputKey method in each
control on your form. The code for the override of the IsInputKey
would need to determine if one of the special keys is pressed and
return a value of true. "

The problem is that I can not find place where (how) I have to
overriding the IsInputKey method. Or is it wrong way?

Maybe somebody has an another idea how fix such problem.

Thanks
 
Y

yEaH rIgHt

Try this:

Public Class Test
Inherits System.Windows.Forms.TabControl

Public Sub New()
MyBase.New()
End Sub


Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = keyData.Tab Or keyData = 131089 Or keyData = 65552 Then
Return True
End If
Return False
End Function
End Class
 
M

Mike

Ok, and after Class Test would be created - how to use it in the program?
The program know only about instance of class TabControl when I put it on
the form .

Thanks,
P.S. Maybe override method is not the best desidion. Do you know another way
not to send events to the controls.
 
Y

yEaH rIgHt

This is how you would use it:


Dim WithEvents t As New Test()

t.Size = New Size(250, 250)
t.Location = New Point(0, 0)
t.TabPages.Add(New TabPage("Help"))
t.TabPages.Add(New TabPage("OK"))
Me.Controls.Add(t)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top