TabPage Changing

R

ray well

i want a user to be able to change tab pages thru the keyboard, i tried
entering the TabPage.text as '&1 Names', "&2 Addresses', etc., so that the
user can change pages by type ALT 1, ALT 2, on the keyboard.

but the text showing up in the tab is '&1 Names' instead of the '1' being
underlined, and being able to be accessed thru the keyboard.

how can i get a user to be able to change from TabPage to TabPage thru the
keyboard? i find it hard to beleive it can't be done.

thanks,

ray
 
R

rowe_newsgroups

i want a user to be able to change tab pages thru the keyboard, i tried
entering the TabPage.text as '&1 Names', "&2 Addresses', etc., so that the
user can change pages by type ALT 1, ALT 2, on the keyboard.

but the text showing up in the tab is '&1 Names' instead of the '1' being
underlined, and being able to be accessed thru the keyboard.

how can i get a user to be able to change from TabPage to TabPage thru the
keyboard? i find it hard to beleive it can't be done.

thanks,

ray

Ctrl+PageDown and Ctrl+PageUp are the standard Window's commands for
this.

Also, you could moniter the keypress/keyup/keydown events for "alt 1"
and then change the tabpage via code.

Thanks,

Seth Rowe
 
R

ray well

Ctrl+PageDown and Ctrl+PageUp are the standard Window's commands for
this.<<

seth,

thanks your reply.

but if u have a whole bunch of tab pages, it becomes a pain to have to go
thru all of them instead of going to the one u need directly.

ray
 
M

Mick Doherty

The standard Windows.Forms.TabControl does not support this feature.

You can ownerdraw the TabControl to draw the tab text with the mnemonic and
then catch the mnemonics and change tabpage as appropriate.

You will find basic examples of this on my site:
http://www.dotnetrix.co.uk/tabcontrols.html

If you don't want to draw the tabs yourself (a lot of work especially with
Visual Styles), then you may like to use TabControlEx instead. This has
mnemonic support built in and also includes several other frequently
requested features.
http://www.dotnetrix.co.uk/controls.html
 
R

rowe_newsgroups

this.<<

seth,

thanks your reply.

but if u have a whole bunch of tab pages, it becomes a pain to have to go
thru all of them instead of going to the one u need directly.

ray

Like I said, you can watch the keyevents and then code in the
functionality for switching to a certain tab.

Thanks,

Seth Rowe
 
R

rowe_newsgroups

Rowe,

Do you have an idea how that would be done?

Cor





Do you have an idea how that would be done?

Of course I do!

Just start a new form and replace it's code behind with the below and
run the form. Presses Alt+1 will select the first page, Alt+2 selects
the second and Alt+3 will select the third tabpage. I would recommend
the OP inherit TabPage and add a new property for the keycode instead
of using Tag - but for sake of brevity I used Tag.

//////////////
Public Class Form1

Dim tabControl As New TabControl()

Public Sub New()
InitializeComponent()

Me.KeyPreview = True

TabControl.Name = "tabControl1"

For i As Integer = 1 To 3
Dim tabPage As New TabPage(String.Format("TabPage {0}",
i.ToString()))
'// Store the target keycode in the Tag property
'// A value of "D2, Alt" will select the control
'// when the user presses Alt+2
tabPage.Tag = String.Format("D{0}, Alt", i.ToString())
TabControl.TabPages.Add(tabPage)
Next

Me.Controls.Add(TabControl)
TabControl.Location = New Point(30, 30)

End Sub

Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.Alt Then
For Each tabPage As TabPage In tabControl.TabPages
If tabPage.Tag.ToString() = e.KeyData.ToString() Then
tabControl.SelectedTab = tabPage
Exit For
End If
Next
End If
End Sub

End Class
////////////////////

Thanks,

Seth Rowe
 

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