• Csharp Winform TextBox 樣式以一條橫線顯示


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.ComponentModel;
    
    
    namespace TextboxsStyleLineControlLibrary
    {
        /// <summary>
        ///csharp winform 划横线输入框
        /// 塗聚文 2012-03-27
        /// 締友計算機信息技術有限公司
        /// 捷為工作室
        /// </summary>
        [ToolboxItem(true)] 
        public  class GeovinDuTextBoxLine:TextBox
        {
            private bool m_DrawLine = false;
            private const int WM_NCPAINT = 0x0085;
            private const int WM_CHAR = 0x0102;
    
            [System.Runtime.InteropServices.DllImport("user32.dll ")]
            static extern IntPtr GetWindowDC(IntPtr hWnd);
    
            [System.Runtime.InteropServices.DllImport("user32.dll ")]
            static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
            /// <summary>
            /// 
            /// </summary>
            public GeovinDuTextBoxLine()
            {
                //
                //   TODO:   在此处添加构造函数逻辑
                //
                this.SetStyle(ControlStyles.DoubleBuffer, true);
                this.BorderStyle = BorderStyle.None;
            }
            private Color _linecolor = Color.Black;
            /// <summary>
            /// 线条颜色
            /// </summary>
            public Color LineColor
            {
                get
                {
                    return this._linecolor;
                }
                set
                {
                    this._linecolor = value;
                    this.Invalidate();
                }
            }
    
            private const int WM_PAINT = 0xF;
    
    
            /// <summary>
            /// 
            /// </summary>
            public bool DrawLine
            {
                get
                {
                    return this.m_DrawLine;
                }
                set
                {
                    this.m_DrawLine = value;
                    this.Invalidate();
                }
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="m"></param>
            protected override void WndProc(ref   Message m)
            {
    
    
                base.WndProc(ref   m);
                if (m.Msg == 0xf || m.Msg == 0x133)
                {
                    if (this.DrawLine)
                    {
                        IntPtr hDC = GetWindowDC(m.HWnd);
                        if (hDC.ToInt32() == 0)
                        {
                            return;
                        }
                        Graphics g = Graphics.FromHdc(hDC);
                        //Brush b = Brushes.Black;
                        Pen p = new Pen(this._linecolor, 1);//b
    
                        Point p1 = new Point(0, this.Height - 2);
                        Point p2 = new Point(this.Width, Height - 2);
                        g.DrawLine(p, p1, p2);
    
                        m.Result = IntPtr.Zero;
                        ReleaseDC(m.HWnd, hDC);
                    }
                }
            }   
    
        }
    }
    
    哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
  • 相关阅读:
    [转]Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)
    [转]OAuth 2.0
    SpringMVC之七:SpringMVC中使用Interceptor拦截器
    多数据源问题--Spring+Ibatis 访问多个数据源(非分布式事务)
    读写分离
    SVN中检出(check out) 和 导出(export) 的区别
    Hbase之三:Hbase Shell使用入门
    hadoop之一:概念和整体架构
    Twitter Storm如何保证消息不丢失
    Twitter Storm: storm的一些常见模式
  • 原文地址:https://www.cnblogs.com/geovindu/p/2419752.html
Copyright © 2020-2023  润新知