zoukankan      html  css  js  c++  java
  • winform设置textbox设置水印

    1、新建自定义控件

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace takelinks
    {
        public partial class WatermarkTextBox : TextBox//修改为继承自TextBox
        {
            public WatermarkTextBox()
            {
                InitializeComponent();
            }
            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);
    
            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);
            }
    
        }
    }
    View Code

    2、新建的控件除了textbox的功能外还增添了水印的功能

    运用

     textBox1.WatermarkText = "请输入链接,可以拖拽!";


    完!

  • 相关阅读:
    [zz]struct epoll_event
    [zz]libev 简介
    [zz]红黑树
    [zz]leveldb 实现原理
    [zz]使用 libevent 和 libev 提高网络应用性能
    [zz]AVL树
    [zz]do...while(0)的妙用
    Mybatis中的缓存简介
    Spring框架的介绍
    ThreadLocal
  • 原文地址:https://www.cnblogs.com/wwz-wwz/p/7552585.html
Copyright © 2011-2022 走看看