Hotkeys to tabpages

  • Thread starter Thread starter skumar
  • Start date Start date
S

skumar

I need to access the Tabpages by hotkeys "alt+P" in case
of "Principals" as one of the Tabpage.

Also i need to underline the word "P" in "Principals" so
that user is informed about the hotkey.If i use "&" in
front of the word "P",it is not underlining the word.It
just stays "&" itself.

I know we can add this hotkeys to toolbars,buttons and
lots of other controls.

But How to do this in Tabcontrol pages.

Any Thoughts,

Thanks,
SKumar
..
 
You could just listen for key press event and then if the correct
combination is pressed set the selected tab index to the correct number.

I don't have a awnser for the underline question (yet).

Olle
 
To display the underlining you'll need to draw it yourself
See TabControl.DrawMode for more info

The following code works well for strings that are not to long
For strings longer than 10-15 characters it doesn't look very good
(I don't know how to fix it)

Private Sub myTabControl_DrawItem( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles myTabControl.DrawItem

Dim tc As TabControl = CType(sender, TabControl)
Dim tp As TabPage = tc.TabPages(e.Index)

' Draw background
Dim backgroundBrush As New SolidBrush(tc.BackColor)
e.Graphics.FillRectangle(backgroundBrush, e.Bounds)

' Draw foreground
Dim foregroundBrush As New SolidBrush(tc.ForeColor)
Dim rect As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width,
e.Bounds.Height)
Dim format As New StringFormat
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show
If tc.SelectedIndex = e.Index Then
rect.Offset(0, -1)
e.Graphics.DrawString(tp.Text, tc.Font, foregroundBrush, rect,
format)
Else
rect.Offset(0, 2)
e.Graphics.DrawString(tp.Text, tc.Font, foregroundBrush, rect,
format)
End If

backgroundBrush.Dispose()
foregroundBrush.Dispose()
End Sub

/claes
 
* "skumar said:
I need to access the Tabpages by hotkeys "alt+P" in case
of "Principals" as one of the Tabpage.

Also i need to underline the word "P" in "Principals" so
that user is informed about the hotkey.If i use "&" in
front of the word "P",it is not underlining the word.It
just stays "&" itself.

<http://www.google.de/[email protected]>
 
Back
Top