WPF で ErrorProvider に似たことを行う

 

  

using System.Runtime.InteropServices;

namespace FormattableDownloaderWpf
{
    public partial class MainWindow : Window
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]

        public static extern int SetCursorPos(int x, int y);

        private bool ValidatingDownload()
        {
            ToolTipService.SetToolTip(this, null);

            if (String.IsNullOrEmpty(this.textBoxUrlDirectory.Text))
            {
                SetToolTip(this.textBoxUrlDirectory, "ディレクトリの値が不正です。");
                return false;
            }

            if (String.IsNullOrEmpty(this.textBoxFileFormat.Text))
            {
                SetToolTip(this.textBoxFileFormat, "ファイル書式の値が不正です。");
                return false;
            }

            return true;
        }

        private void SetToolTip(TextBox element, string content)
        {
            Point pos = element.PointToScreen(new Point(element.Width / 2, element.Height / 2));
            ToolTipService.SetToolTip(element, content);
            SetCursorPos((int)pos.X, (int)pos.Y);
            element.Focus();
        }

    }
}

参照情報

ToolTipService クラス
http://msdn.microsoft.com/ja-jp/library/system.windows.controls.tooltipservice.aspx

Livedoor タグ:

広告