Special Characters in ToolTip

芮承运
2023-12-01

First Way:

 

1. a single ampersand is not displayed:
       Acme & Co. = Acme Co.
2. the backslash is NOT the 'escape' character for tooltips:
       Acme /& Co. = Acme / Co.
3. an ampersand is NOT the 'escape' character for tooltips (it behaves as if
using Mnemonics):
       Acme && Co. = Acme _ Co.
4. double ampersand 'escapes' a single ampersand:
       Acme &&& Co. = Acme & Co.

 

Second Way:

 

public class Form1 : System.Windows.Forms.Form
{

   {..form initialization..}

   private void Form1_Load(object sender, System.EventArgs e)
   {
       //here I'm setting tooltips
       toolTip1.SetToolTip(textBox1, "My & ToolTip");
       toolTip1.SetToolTip(button1, "My & Button & ToolTip");

       //tooltip's style reset
       CallBack xCallBack = new CallBack(ProcessEnumWindows);
       EnumWindows(xCallBack, Handle);
   }

   public const int GWL_STYLE = (-16);
   public const int TTS_NOPREFIX = 0x02;
   public const string TOOLTIPS_CLASS = "tooltips_class32";

   [DllImport("user32",CharSet=CharSet.Auto)]
   internal static extern int GetWindowLong(IntPtr hwnd, int nIndex);
   [DllImport("user32.dll",CharSet=CharSet.Auto)]
   private static extern int SetWindowLong(IntPtr hwnd, int nIndex,
       int dwNewLong);
   [DllImport("user32",CharSet=CharSet.Auto)]
   public static extern int EnumWindows(CallBack lpEnumFunc,
       IntPtr lParam);
   [DllImport("user32",CharSet=CharSet.Auto)]
   public static extern IntPtr GetParent(IntPtr hWnd);
   [DllImport("user32",CharSet=CharSet.Auto)]
   public static extern int GetClassName(IntPtr hWnd,
       System.Text.StringBuilder lpClassName, int nMaxCount);

   public delegate bool CallBack(IntPtr hwnd, IntPtr lParam);

   public static bool ProcessEnumWindows(IntPtr hwnd, IntPtr lParam)
   {
       IntPtr xParentHandle = GetParent(hwnd);
       if (xParentHandle.Equals(lParam))
       {
           System.Text.StringBuilder xClassName =
               new System.Text.StringBuilder(255, 255);
           int xCount = GetClassName(hwnd, xClassName, 255);
           string xName = xClassName.ToString(0, xCount);
           if (xName.IndexOf(TOOLTIPS_CLASS)>-1)
           {
               int xStyle = GetWindowLong(hwnd, GWL_STYLE);
               if ((xStyle & TTS_NOPREFIX)==0)
               {
                   xStyle |= TTS_NOPREFIX;
                   SetWindowLong(hwnd, GWL_STYLE, xStyle);
               }
           }
       }
       return true;
   }
}
____________________________________
where textBox1 is System.Windows.Forms.TextBox and
button1 is System.Windows.Forms.Button.

 类似资料:

相关阅读

相关文章

相关问答