underline character in menu item text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Have anyone seen this problem? I just started developing Windows Forms
application in Studio .NET 2003. I started a new C# windows application,
added a new MainMenu to the app and menu item File. In the Designer, I
located the text property for File in the property box and entered &File. It
showed up as File with F underlined correctly in the designer. However, when
I run the app through Debug->start..., menu item File doesn't show up with
the F underlined in the app. Any idea why this is happening? I tried adding
a couple more menu items with & in their texts and they too showed up
correctly in the designer but not in the running app.

Thanks,
Richard
 
I found the same thing happens in my applications. If you press the Alt key
when running the application all of the underlines will show up. I'm not
sure if there is a way to change the behavior of this.
 
* "=?Utf-8?B?cnlhbmc=?= said:
Have anyone seen this problem? I just started developing Windows Forms
application in Studio .NET 2003. I started a new C# windows application,
added a new MainMenu to the app and menu item File. In the Designer, I
located the text property for File in the property box and entered &File. It
showed up as File with F underlined correctly in the designer. However, when
I run the app through Debug->start..., menu item File doesn't show up with
the F underlined in the app. Any idea why this is happening? I tried adding

From my FAQ (<URL:http://dotnet.mvps.org/dotnet/faqs/>):

There is no general managed way in .NET 1.1 to show accelerator keys
underlined automatically. To do that, a 'WM_CHANGEUISTATE' message with
appropriate data must be sent to the window that should show its accelerator
keys. One of the parameters passed with the message needs the 'MAKELONG'
macro to combine two 16-bit integers to a 32-bit integer. In our sample, we
use a trick with a structure to provide an easy and managed way to replace
the 'MAKELONG', 'LOWORD', and 'HIWORD' macros:

\\\
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Explicit)> _
Private Structure WordConverter
<FieldOffset(0)> Public LongValue As Integer
<FieldOffset(0)> Public LoWord As Short
<FieldOffset(2)> Public HiWord As Short

Public Sub New(ByVal LoWord As Short, ByVal HiWord As Short)
Me.LoWord = LoWord
Me.HiWord = HiWord
End Sub

Public Sub New(ByVal LongValue As Integer)
Me.LongValue = LongValue
End Sub
End Structure
///

The procedure 'MakeAcceleratorsVisible' takes a controls and makes its
accelerator keys visible:

\\\
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Public Const WM_CHANGEUISTATE As Int32 = &H127

Public Const UIS_CLEAR As Int32 = 2

Public Const UISF_HIDEACCEL As Int16 = &H2

Public Sub MakeAcceleratorsVisible(ByVal Control As Control)
SendMessage( _
Control.Handle, _
WM_CHANGEUISTATE, _
New WordConverter(UIS_CLEAR, UISF_HIDEACCEL).LongValue, _
0 _
)
End Sub
///

If accelerators should be made visible within a Windows Forms control class,
the code below can be used instead of 'MakeAcceleratorsVisible':

\\\
MyBase.WndProc( _
Message.Create( _
Me.Handle, _
WM_CHANGEUISTATE, _
New IntPtr(New WordConverter(UIS_CLEAR, UISF_HIDEACCEL).LongValue), _
IntPtr.Zero _
) _
)
///
 
* "=?Utf-8?B?U3RldmU=?= said:
There's also an XP preference setting you can make:

Display Properties (control panel applet) | Appearance tab | Effects button |
"Hide underlined letters for keyboard navigation until I press the Alt key"

I'm not sure if this same setting is on W2K and down.

There is such a setting in Windows 2000 too. The "feature" to hide the
accelerators has been introduced in Windows 2000.
 
Back
Top