TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ldragos
NA
12
0
Subclassing a TextBox with UserPaint flag set....
May 15 2004 6:37 PM
Hello, I am trying to create a customisable - bordered TextBox control. I draw the border in the overrided method OnPaint, after I have previousely set the UserPaint style bit. I don't understand why the setting of the UserPaint flag makes the text within the textbox change its font. My example can be reduced to this : public class testTextBox : TextBox { public testTextBox() { // // TODO: Add constructor logic here // this.SetStyle(ControlStyles.UserPaint, true); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint (e); SolidBrush sb = new SolidBrush(Color.Red); Pen pen = new Pen(sb, 1); e.Graphics.DrawRectangle(pen, 0, 0, 10,10); sb.Dispose(); pen.Dispose(); } } I tried handling text drawing using DrawString(), but that dindn't work great, since the EditControl did at some point it's own painting, changing back my font. To prevent this, I overriden the OnFontChanged method, where I Invalidated my control, forcing it to redraw itself using my Paint method. The problem left was that the caret still moved within the TextBox according to the default font size (which was wider)... Can anyone help, please?
Reply
Answers (
1
)
Visual Inheritance
Weird RAM-behaviour