Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2008, 08:53 PM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to daming_ocean
Default How to use PictureBox OnPaint Event

I want to use PictureBox OnPaint Event to redraw the picturebox.
Just like use Form OnPaint Event to redraw the Form.
I can rewrite Form OnPaint Event in the Form Class,
like this: protected override void OnPaint(PaintEventArgs e).
But I don't know How to rewrite this event in the Form Class.
I really appreciate someone could help me. Thanks very much.


 
Old March 6th, 2008, 03:44 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

To overrid the OnPaint method for a PictureBox you would have to create a user control which inherited from PitureBox and override it in that class.

/- Sam Judson : Wrox Technical Editor -/
 
Old March 6th, 2008, 07:41 PM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to daming_ocean
Default

Thanks a lot. It's really helpful.

 
Old March 16th, 2008, 06:39 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just as another quick point (although I dont think this is really what you are after in this scenario)...

If you want to do some ad-hoc work, you can just add some logic to the Paint event of the PictureBox control and render stuff over the top of it (since the event is raised following its own rendering). For example:
Code:
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            // Do some Graphics Work Here
        }
        This will be much quicker to implement than creating your own UserControl for one-off items.

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old March 24th, 2008, 07:13 PM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to daming_ocean
Default

Thanks a lot. :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Event On PictureBox In C# akumarp2p C# 7 January 14th, 2009 07:55 AM
about picturebox inherit youtubeline C# 3 December 12th, 2008 03:41 PM
Picturebox Array? thomaz C# 2008 aka C# 3.0 1 September 12th, 2008 12:11 PM
Picturebox question julz127 Visual Basic 2005 Basics 0 February 26th, 2008 02:44 AM
Name of image in PictureBox purefan Beginning VB 6 5 November 27th, 2006 02:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.