zoukankan      html  css  js  c++  java
  • C# Winform 带水印提示输入框

    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace KK.WatermarkTextBox
    {
        public partial class WatermarkTextBox : TextBox
        {
            private const uint ECM_FIRST = 0x1500;
            private const uint EM_SETCUEBANNER = ECM_FIRST + 1;
    
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
            static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
    
            public WatermarkTextBox()
            {
                InitializeComponent();
            }
    
            private string watermarkText;
            public string WatermarkText
            {
                get { return watermarkText; }
                set
                {
                    watermarkText = value;
                    SetWatermark(watermarkText);
                }
            }
    
            private void SetWatermark(string watermarkText)
            {
                SendMessage(this.Handle, EM_SETCUEBANNER, 0, watermarkText);
            }
        }
    }
    

    运行效果如下所示:

  • 相关阅读:
    HDU-1561
    POJ 1088
    UESTC-878
    CodeForces
    HDU 5753
    HDU 1568
    二分图入门题
    二分图匹配入门题
    树形dp入门
    UVA
  • 原文地址:https://www.cnblogs.com/YYkun/p/11383514.html
Copyright © 2011-2022 走看看