A way is to use an API from the Shell, which has a built-in Tooltip =>
Test with a textBox1 TextBox :
LIMITINPUT li = new LIMITINPUT();
li.pszFilter = Marshal.StringToHGlobalAuto("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + (char)8);
// li.pszFilter = (IntPtr)(LICF_DIGIT | LICF_UPPER | LICF_LOWER | LICF_CNTRL);
li.pszMessage = Marshal.StringToHGlobalAuto("Please enter Letter or Number");
li.pszTitle = Marshal.StringToHGlobalAuto("Information");
li.dwFlags = LIF_INCLUDEFILTER ;
// li.dwFlags = LIF_INCLUDEFILTER | LIF_CATEGORYFILTER;
li.dwMask = LIM_FLAGS | LIM_FILTER | LIM_MESSAGE | LIM_TITLE;
HRESULT hr = SHLimitInput(textBox1.Handle, ref li);
Declarations :
public enum HRESULT : uint
{
S_OK = 0,
S_FALSE = 1,
E_NOINTERFACE = 0x80004002,
E_NOTIMPL = 0x80004001,
E_FAIL = 0x80004005,
E_INVALIDARG = 0x80070057,
E_UNEXPECTED = 0x8000FFFF
}
[DllImport("Shell32.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "#754")]
public static extern HRESULT SHLimitInput(IntPtr hWndEdit, ref LIMITINPUT pli);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct LIMITINPUT
{
public int cbSize;
public int dwMask;
public int dwFlags;
public IntPtr hinst;
public IntPtr pszFilter;
public IntPtr pszTitle;
public IntPtr pszMessage;
public IntPtr hIcon;
public IntPtr hWndNotify;
public int nTooltipTimeout;
public int nTooltipWidth;
}
public const int LIF_INCLUDEFILTER = 0x0;
public const int LIF_EXCLUDEFILTER = 0x1;
public const int LIF_CATEGORYFILTER = 0x2;
public const int LIF_HIDETIPONVALID = 0x200;
public const int LIM_FLAGS = 0x1;
public const int LIM_FILTER = 0x2;
public const int LIM_HINST = 0x8;
public const int LIM_TITLE = 0x10;
public const int LIM_MESSAGE = 0x20;
public const int LIM_ICON = 0x40;
public const int LICF_UPPER = 0x1;
public const int LICF_LOWER = 0x2;
public const int LICF_DIGIT = 0x4;
public const int LICF_SPACE = 0x8;
public const int LICF_PUNCT = 0x10;
public const int LICF_CNTRL = 0x20;
public const int LICF_BLANK = 0x40;
public const int LICF_XDIGIT = 0x80;
public const int LICF_ALPHA = 0x100;