y2010m02d04
今更すぎる各種Panel活用
スナップラインとか使わずにきれいにレイアウトできるウィンドウ。
Form の Padding を 7, 7, 7, 7 くらいに設定して
TabControl の Dock を Fill に設定して
Dock が Bottom で AutoSize が true な FlowLayoutPanel を追加してボタンを適当に入れる。
タブページの Padding は 0, 0, 0, 0 にしておく。
中身は TableLayoutPanel で Padding を 7, 7, 7, 7 に設定して Dock を Fill。
AutoSize な行や列を適当に追加しまくってれば勝手にレイアウト調整してくれる。
スナップラインとかもうどうでもいいです。
Form の AutoSize を true にできる場合もあって、その場合はウィンドウサイズ調整も省ける。
AutoSize を設定するときは AutoSizeMode に注意。
y2009m11d15
TextBoxからバルーンを表示する
どうやらXP以降で使用可能な*1、テキストボックスのバルーンの設定。EM_SHOWBALLOONTIP。
↑こんなん。
public static class Windows { [SuppressUnmanagedCodeSecurity, DllImport("user32")] private static extern bool SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); [SuppressUnmanagedCodeSecurity, DllImport("user32", CharSet = CharSet.Auto)] private static extern bool SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref EDITBALLOONTIP lParam); [StructLayout(LayoutKind.Sequential)] private struct EDITBALLOONTIP { public int cbStruct; [MarshalAs(UnmanagedType.LPWStr)] public string pszTitle; [MarshalAs(UnmanagedType.LPWStr)] public string pszText; public int ttiIcon; } public static void ShowBalloonTip(this TextBox control, string title, string text) { var balloon = new EDITBALLOONTIP { cbStruct = Marshal.SizeOf(typeof(EDITBALLOONTIP)), pszTitle = title, pszText = text, }; SendMessage(control.Handle, 0x1503, IntPtr.Zero, ref balloon); } public static void HideBalloonTip(this TextBox control) { SendMessage(control.Handle, 0x1504, IntPtr.Zero, IntPtr.Zero); } }
textBox1.ShowBalloonTip("無効な URL", "正しく URL と認識される文字列を入力する必要があります");
textBox1.HideBalloonTip();
y2009m11d09
TextBoxにウォーターマークテキストを設定する
どうやらXP以降で使用可能な*1、テキストボックスのウォーターマークテキスト*2の設定。
↑こんなん
ここによるとEM_SETCUEBANNERを使うとできるようなので、値を調べる。
EM_SETCUEBANNERは0x1501でEM_GETCUEBANNERは0x1502らしいことが分かったのでCommCtrl.hのEdit_SetCueBannerTextマクロ定義でも見ながら適当にSendMessage。
public static class Windows { [DllImport("user32", EntryPoint = "SendMessage", CharSet = CharSet.Auto)] private static extern int GetCueBannerText(IntPtr hWnd, int msg, StringBuilder wParam, int lParam); [DllImport("user32", EntryPoint = "SendMessage", CharSet = CharSet.Auto)] private static extern int SetCueBannerText(IntPtr hWnd, int msg, bool wParam, string lParam); public static string GetCueBannerText(this TextBox control) { var rt = new StringBuilder(256); GetCueBannerText(control.Handle, 0x1502, rt, rt.Capacity); return rt.ToString(); } public static void SetCueBannerText(this TextBox control, string text) { SetCueBannerText(control.Handle, 0x1501, false, text); } }
こんな感じでやると、
textBox1.SetCueBannerText("検索");
見たいな感じで設定可能です。*3
ところでXP上だとこのウォーターマークテキストに日本語がサポートされていないそうですが、実際のところどうなのかXP持ってる人だれか教えてください。




