473,480 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using using

When I want to invoke Dispose() automatically on an object, I can use

using(object)
{
//do something with object
}

and after the closing brace the object is Disposed(). But what get
disposed when I use code like this

override protected void OnPaint(PaintEventArgs e)
{
using(e.Graphics.Clip=GetMyCustomRegion())
{
e.Graphics.DrawImage(bitmap,0,0);
}
}

Is the Region object returned by GetMyCustomRegion() succesfully
Disposed()? How does it influence the Clip-property of the Graphics object?

Also, can I nest 'using' statement like this:

override protected void OnPaint(PaintEventArgs e)
{
using(e.Graphics.Clip=GetMyCustomRegion())
using(Bitmap bitmap=new Bitmap(34,55))
{
e.Graphics.DrawImage(bitmap,0,0);
}
}

Do both the implicit Region object and the Bitmap object get Disposed()?
Sep 11 '07 #1
1 1531
Hi Martijn,

MMusing(e.Graphics.Clip=GetMyCustomRegion())
MMIs the Region object returned by GetMyCustomRegion() succesfully Disposed()?

Yes, why not, reference is the same, it's kind of
using (Region tempRegion = (e.Graphics.Clip = <new Region()>))
{
e.Graphics.DrawImage(null, 0, 0);
}

MMusing(e.Graphics.Clip=GetMyCustomRegion())
MMusing(Bitmap bitmap=new Bitmap(34,55))
First for the bitmap, then for the region.

http://msdn2.microsoft.com/en-us/lib...02(VS.80).aspx

Regards, Alex
[TechBlog] http://devkids.blogspot.com

MMWhen I want to invoke Dispose() automatically on an object, I can
MMuse
MM>
MMusing(object)
MM{
MM//do something with object
MM}
MMand after the closing brace the object is Disposed(). But what get
MMdisposed when I use code like this
MM>
MMoverride protected void OnPaint(PaintEventArgs e)
MM{
MMusing(e.Graphics.Clip=GetMyCustomRegion())
MM{
MMe.Graphics.DrawImage(bitmap,0,0);
MM}
MM}
MMIs the Region object returned by GetMyCustomRegion() succesfully
MMDisposed()? How does it influence the Clip-property of the Graphics
MMobject?
MM>
MMAlso, can I nest 'using' statement like this:
MM>
MMoverride protected void OnPaint(PaintEventArgs e)
MM{
MMusing(e.Graphics.Clip=GetMyCustomRegion())
MMusing(Bitmap bitmap=new Bitmap(34,55))
MM{
MMe.Graphics.DrawImage(bitmap,0,0);
MM}
MM}
MMDo both the implicit Region object and the Bitmap object get
MMDisposed()?
MM>
Sep 11 '07 #2

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

Similar topics

5
5677
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
3
2131
by: Mike L | last post by:
Should the command call "using" be before or after my namespace? **AFTER** namespace DataGridBrowser { using System; using System.Drawing; using System.Drawing.Drawing2D; using...
3
2407
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use...
14
5731
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
8
2387
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
0
2174
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
10
1922
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,...
0
2533
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
3
8202
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
6
5117
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
0
6908
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
7043
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,...
1
6737
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
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.