473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Drawing a Border for a textbox

I have tried the following, which draws the border but clears the Text
when the control does not have focus.
Please help.
----------------------------------------------------------
1. Set the ControlStyle to "UserPaint" in the constructor:

public MyTextBox()
{
// This call is required by the Windows.Forms Form Designer.
this.SetStyle(ControlStyles.UserPaint,true);
InitializeComponent();

// TODO: Add any initialization after the InitForm call
}

2. Add the following code to the overrided OnPaint method.

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
int borderWidth = 1;
Color borderColor = Color.Blue;

ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor,
borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth,

ButtonBorderStyle.Solid, borderColor, borderWidth,
ButtonBorderStyle.Solid,

borderColor, borderWidth, ButtonBorderStyle.Solid);
}
Nov 15 '05 #1
1 15060
Murali Valluri wrote:
I have tried the following, which draws the border but clears the Text
when the control does not have focus.
Please help.


Hmm, Interesting.
As soon as you set
this.SetStyle(ControlStyles.UserPaint,true)
you have to take over all aspects of drawing, including text output.
So you have to
e.Graphics.DrawString(Text,this.Font,br,0,0);
But when user edit text it looks incosistens, and when user leave it, no
repaint is called. I see that .net control is strange mix of wrappers of
windows native gui calls.

Vadim Chekan.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Culley | last post by:
I'm trying to covert a userdrawn control written in C# to use the XP style. It consists only of a border, a button and a textbox. The button and textbox is working fine but the border is not. The...
4
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text...
1
by: Dennis C. Drumm | last post by:
How can I determine if a string will fit in the display area of a text box? I don't want to use a char count because the width of each char can vary. I suspect I need to convert the string to a...
2
by: moondaddy | last post by:
I want to change the border of a asp.net textbox to thin-solid-blue but when I set the cssclass property to a class in the stylesheet, the border properties in the stylesheet don't have any effect...
10
by: tshad | last post by:
I have a problem setting the background color of textbox on the fly. I tried using: applicantID.backcolor = "F6F6F6" and applicantID.backcolor = "#F6F6F6"
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
1
by: Mark Rae | last post by:
Hi, Have been modifying a piece of JavaScript I found on the net which completely prevents the Google AutoFill Toolbar from doing its stuff... Got that working now but, while I was debugging it,...
1
by: Andrew | last post by:
Hello Everyone I am receiving an error in an application I am working on. The application when its done will be a Dungeons and Dragons Network game. I am having problems with the Networked...
2
by: john | last post by:
I'm adding a Textbox with javascript, it works except for the border attribute, any advive Thanks John var formFld = document.createElement('input') formFld.setAttribute('type', 'text') ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.