By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,526 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

TabPage Changing

P: n/a
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
Jul 12 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Jul 12, 12:28 pm, "ray well" <nos...@nospam.comwrote:
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

Jul 12 '07 #2

P: n/a
>>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
Jul 12 '07 #3

P: n/a
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

--
Mick Doherty
http://www.dotnetrix.co.uk/nothing.html
"ray well" <no****@nospam.comwrote in message
news:OQ*************@TK2MSFTNGP06.phx.gbl...
>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


Jul 12 '07 #4

P: n/a
On Jul 12, 2:20 pm, "ray well" <nos...@nospam.comwrote:
>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
Like I said, you can watch the keyevents and then code in the
functionality for switching to a certain tab.

Thanks,

Seth Rowe

Jul 12 '07 #5

P: n/a
Rowe,

Do you have an idea how that would be done?

Cor

"ray well" <no****@nospam.comschreef in bericht
news:eY**************@TK2MSFTNGP06.phx.gbl...
>>>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


Jul 13 '07 #6

P: n/a
On Jul 13, 12:38 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Rowe,

Do you have an idea how that would be done?

Cor

"ray well" <nos...@nospam.comschreef in berichtnews:eY**************@TK2MSFTNGP06.phx.gbl. ..
>>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
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

Jul 13 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.