Change border style of text box

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I recently looked at a sample application from DevDays 2004 called
IssueVision. The textboxes in the vb winforms app had a flat appearance
with thin light blue borders at runtime, however, in design view all of the
text box properties we just like any other standard textbox that you drag
onto a form and had the normal appearance of gray sunken borders. I could
not figure out how the different appearance was achieved at runtime. How
can I make controls like textboxes, combo boxes, etc. have a clean flat
appearance like the one I described above?
 
Hi moondaddy,

I have reviewed your issue. I will do some research on it and reply to you
ASAP.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi moondaddy,

Sorry for letting you wait for so long time.

To change the border of the textbox, you may draw the border yourself. You
should override the WndProc, and draw in the WM_NCPAINT message.
I have writen a sample for you. Please refer to:

class MyTextBox : System.Windows.Forms.TextBox
{
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);

[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

const int WM_NCCALCSIZE = 0x0083;
const int WM_NCHITTEST = 0x0084;
const int WM_NCPAINT = 0x0085;


struct RECT
{
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
};
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NCPAINT:
{
Debug.WriteLine("WM_NCPAINT: hWnd = "+m.HWnd.ToString()+"
WParam = "+m.WParam.ToString());
IntPtr hDC = GetWindowDC(m.HWnd);
if (hDC.ToInt32() == 0)
{
Debug.WriteLine("Couldn't get hDC:
"+Marshal.GetLastWin32Error().ToString());
break;
}
Graphics g = Graphics.FromHdc(hDC);

Brush b = Brushes.Red;
Pen p = new Pen(b,5);
Rectangle r = new
Rectangle(0,0,this.Size.Width,this.Size.Height);
Debug.WriteLine("WM_NCPAINT: "+r.Top+","+r.Left+" -
"+r.Bottom+","+r.Right);
g.DrawRectangle(p,r);
m.Result = IntPtr.Zero;

ReleaseDC(m.HWnd,hDC);
return;
}
}
base.WndProc(ref m);
}
}

==============================
Please apply my suggestion above and let me know if it meets your need.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi moondaddy,

Does my reply make sense to you? Is your problem resolved?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top