473,385 Members | 2,210 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,385 software developers and data experts.

Using 'Dispose' in a Custom Paint Event

I have an About box where I've successfully implemented a custom paint event.
The structure of it is simple:

protected void PaintClient(Object sender, PaintEventArgs e)
{
// Assorted graphics code goes here
}
Following examples I've seen elsewhere I added the following as the last line:
e.Dispose();

But this caused the program to crash. Why is that? Is it not necessary to
dispose of this object after using it to draw assorted graphics?

--
Robert W.
Vancouver, BC
www.mwtech.com

Nov 17 '05 #1
2 1647
No. You don't dispose of anything that "doesn't belong to you". In other
words, since you didn't "allocate it" then you shouldn't "destroy it". You
should dispose of pens, brushes, etc. that you instantiated and used during
the paint routine but not objects passed to the paint handler.

--
Tim Wilson
..NET Compact Framework MVP

"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
I have an About box where I've successfully implemented a custom paint event. The structure of it is simple:

protected void PaintClient(Object sender, PaintEventArgs e)
{
// Assorted graphics code goes here
}
Following examples I've seen elsewhere I added the following as the last line: e.Dispose();

But this caused the program to crash. Why is that? Is it not necessary to dispose of this object after using it to draw assorted graphics?

--
Robert W.
Vancouver, BC
www.mwtech.com

Nov 17 '05 #2
"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
I have an About box where I've successfully implemented a custom paint
event.
The structure of it is simple:

protected void PaintClient(Object sender, PaintEventArgs e)
{
// Assorted graphics code goes here
}
Following examples I've seen elsewhere I added the following as the last
line:
e.Dispose();

But this caused the program to crash. Why is that? Is it not necessary
to
dispose of this object after using it to draw assorted graphics?

--
Robert W.
Vancouver, BC
www.mwtech.com


Because you don;t own that pbject, the WinFor,ms framework has given you an
object to use they will clean it up.

If you allocate a Disposble resource you should ccall Dispose. If you get
handed one, unless there is a defined protocol for who owns it, leave it
well alone

Regards

Richard Blewett - DevelopMentor
http://www.dotnteconsult.co.uk/weblog
http://www.dotnteconsult.co.uk
Nov 17 '05 #3

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

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
3
by: Todd Schinell | last post by:
Back in July, Jeffery Tan posted this: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OWOTdf0VDHA.2296%40cpmsftngxa06.phx.gbl In response as to how to get click events from a...
1
by: nate axtell | last post by:
In VB .Net I made a custom CheckBox column style (for the Datagrid control) that maps to two DataTable columns , one it uses for the Checked status and the other it uses for the Enabled status. I am...
7
by: Peter Row | last post by:
Hi, I've started work on my own control some parts of which use standard controls, others I need to draw on my controls surface to get the display output I require, however.... I seem to be...
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
3
by: Larry | last post by:
I'm sure I've missed the obvious, but when I define a custom color, my DrawString call from my Paint event doesn't seem to draw anything at all. void btnNav_Paint(object sender, PaintEventArgs...
2
tranc3d
by: tranc3d | last post by:
Hello, I have a custom panel in my project (this one: http://www.codeproject.com/KB/graphics/fastimagedrawing.aspx) with a custom paint event ( protected override void OnPaint(PaintEventArgs pe)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.