using using

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martijn Mulder

    #1

    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(PaintEv entArgs e)
    {
    using(e.Graphic s.Clip=GetMyCus tomRegion())
    {
    e.Graphics.Draw Image(bitmap,0, 0);
    }
    }

    Is the Region object returned by GetMyCustomRegi on() 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(PaintEv entArgs e)
    {
    using(e.Graphic s.Clip=GetMyCus tomRegion())
    using(Bitmap bitmap=new Bitmap(34,55))
    {
    e.Graphics.Draw Image(bitmap,0, 0);
    }
    }

    Do both the implicit Region object and the Bitmap object get Disposed()?
  • Alex Meleta

    #2
    Re: using using

    Hi Martijn,

    MMusing(e.Graph ics.Clip=GetMyC ustomRegion())
    MMIs the Region object returned by GetMyCustomRegi on() succesfully Disposed()?

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

    MMusing(e.Graph ics.Clip=GetMyC ustomRegion())
    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(PaintEv entArgs e)
    MM{
    MMusing(e.Graph ics.Clip=GetMyC ustomRegion())
    MM{
    MMe.Graphics.Dr awImage(bitmap, 0,0);
    MM}
    MM}
    MMIs the Region object returned by GetMyCustomRegi on() 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(PaintEv entArgs e)
    MM{
    MMusing(e.Graph ics.Clip=GetMyC ustomRegion())
    MMusing(Bitmap bitmap=new Bitmap(34,55))
    MM{
    MMe.Graphics.Dr awImage(bitmap, 0,0);
    MM}
    MM}
    MMDo both the implicit Region object and the Bitmap object get
    MMDisposed()?
    MM>


    Comment

    Working...