Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

TextBox OnPaint override issues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DeveloperX - 03 Jan 2007 11:03 GMT
Hi, I'm a little confused regarding the OnPaint override for a textbox
(code to follow). I have a tiny test class which inherits from TextBox
and overrides OnPaint. However OnPaint in my derived class is never
called. Could someone be so kind as to explain where I'm going wrong?
I've got some ideas, I believe the textbox is a wrapper around the
win32 textbox, so perhaps I need to override the wndproc, but even so
I'd still expect my OnPaint to get called...
Thanks

    public class DTextBox : System.Windows.Forms.TextBox
    {
        public DTextBox()
        {
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Console.WriteLine("s");
            //base.OnPaint(e);
        }
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            Console.WriteLine("d");
            this.Invalidate(); //trying to force OnPaint
        }
    }
Paul E Collins - 03 Jan 2007 11:31 GMT
> [overridden OnPaint not called for derived TextBox]

Try adding this to your derived constructor:

this.SetStyle(ControlStyles.UserPaint, true);

Eq.
DeveloperX - 03 Jan 2007 11:41 GMT
Cheers Paul, got there just as you posted :) I also found:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=26542&SiteID=1

which covers painting in the non client area as well for anyone who's
interested.

> > [overridden OnPaint not called for derived TextBox]
>
[quoted text clipped - 3 lines]
>
> Eq.
DeveloperX - 03 Jan 2007 11:32 GMT
Solved it...

http://www.codeproject.com/cs/miscctrl/alphablendtextbox.asp

> Hi, I'm a little confused regarding the OnPaint override for a textbox
> (code to follow). I have a tiny test class which inherits from TextBox
[quoted text clipped - 21 lines]
>         }
>     }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.