CreateGraphics logic

  • Thread starter Thread starter vijay_3491
  • Start date Start date
V

vijay_3491

Hi,

How to write a CreateGraphics method for a class similar to
form.CreateGraphics()?

Pls help. Thanks in Advance.
 
Well, what kind of class do you want to generate a device context for
(which the Graphics class is really a wrapper for).

What exactly are you trying to do? The device context is something that
is typically generated for you. Unless you have some sort of output device
which windows doesn't handle (which would be wrong, since you should go
through the hardware abstraction layer to get a device context to output on
anyways), you really shouldn't be creating a Graphics instance yourself.
 
Nicholas Paldino said:
Well, what kind of class do you want to generate a device context for
(which the Graphics class is really a wrapper for).

What exactly are you trying to do? The device context is something
that is typically generated for you. Unless you have some sort of output
device which windows doesn't handle (which would be wrong, since you
should go through the hardware abstraction layer to get a device context
to output on anyways), you really shouldn't be creating a Graphics
instance yourself.

Most likely Graphics.FromImage is appropriate, see
http://msdn2.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

How to write a CreateGraphics method for a class similar to
form.CreateGraphics()?

Pls help. Thanks in Advance.
 
Hi Nicholas/Ben,

Thanks for your reply.

I too used the Graphics.FromImage() but I am facing some problems
using it in my control. Is there any other way to get the graphics?




    Well, what kind of class do you want to generate a device context for
(which the Graphics class is really a wrapper for).

    What exactly are you trying to do?  The device context is something that
is typically generated for you.  Unless you have some sort of output device
which windows doesn't handle (which would be wrong, since you should go
through the hardware abstraction layer to get a device context to output on
anyways), you really shouldn't be creating a Graphics instance yourself.

--
          - Nicholas Paldino [.NET/C# MVP]
          - (e-mail address removed)




How to write a CreateGraphics method for a class similar to
form.CreateGraphics()?
Pls help. Thanks in Advance.- Hide quoted text -

- Show quoted text -
 
You still haven't answered the question. What are you trying to get the
graphics instance of? Are you trying to manipulate an image? Or are you
trying to custom paint your control?

If you are trying to custom paint your control, and you are in a class
that derives from that control, then you can override the OnPaint method and
get the Graphics instance from the PaintEventArgs that is passed in to the
method.

If you want to do this outside of the control, you will have to
subscribe to the Paint event and then get the Graphics instance from the
PaintEventArgs passed to the event.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Hi Nicholas/Ben,

Thanks for your reply.

I too used the Graphics.FromImage() but I am facing some problems
using it in my control. Is there any other way to get the graphics?




Well, what kind of class do you want to generate a device context for
(which the Graphics class is really a wrapper for).

What exactly are you trying to do? The device context is something that
is typically generated for you. Unless you have some sort of output device
which windows doesn't handle (which would be wrong, since you should go
through the hardware abstraction layer to get a device context to output
on
anyways), you really shouldn't be creating a Graphics instance yourself.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




How to write a CreateGraphics method for a class similar to
form.CreateGraphics()?
Pls help. Thanks in Advance.- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top