0

حاشیه دار کردن کنترل TextBox با یک رنگ دلخواه

 
siryahya
siryahya
کاربر طلایی1
تاریخ عضویت : اسفند 1389 
تعداد پست ها : 158652
محل سکونت : ▂▃▄▅▆▇█Tabriz█▇▆▅▄▃▂

حاشیه دار کردن کنترل TextBox با یک رنگ دلخواه
سه شنبه 9 اردیبهشت 1393  9:38 AM

حاشیه دار کردن کنترل TextBox با یک رنگ دلخواه

در کلاس TextBox خود (و یا سایر کنترلهای دلخواه : کامبوباکس، لیست باکس و ...) بنویسید :
 

کد:
private static int WM_NCPAINT = 0x0085;
private static int WM_ERASEBKGND = 0x0014;
private static int WM_PAINT = 0x000F;
 
[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgnclip, uint fdwOptions);
 
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC);
 
protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);
    if (m.Msg == WM_NCPAINT || m.Msg == WM_ERASEBKGND || m.Msg == WM_PAINT)
    {
        IntPtr hdc = GetDCEx(m.HWnd, (IntPtr)1, 1 | 0x0020);
 
        if (hdc != IntPtr.Zero)
        {
            Graphics graphics = Graphics.FromHdc(hdc);
            Color borderColor = Color.Blue;
            Rectangle rectangle = new Rectangle(0, 0, this.Width, this.Height);
            ControlPaint.DrawBorder(graphics, rectangle, borderColor, ButtonBorderStyle.Solid);
            m.Result = (IntPtr)1;
            ReleaseDC(m.HWnd, hdc);
        }
    }
}

توجه داشته باشید که انجام اینکار صرفا بوسیله override کردن رویداد paint و رسم یک مستطیل امکانپذیر نیست.

ترکی زبان قربون صدقه رفتنه داریم که: گوزلرین گیله‌سین قاداسین آلیم که یعنی درد و بلای مردمک چشات به جونم …!.

تشکرات از این پست
دسترسی سریع به انجمن ها