Create Graphics??
-
Hi, I'm doing some string wrapping calculation, and need graphics.MeasureString to calculate the width of each character. One problem is, Graphics does not have constructor. How can I get or create Graphics object, if the wrapping calculation must be inside one class library, not inside a dialog? Thanks so much for your help?
-
Hi, I'm doing some string wrapping calculation, and need graphics.MeasureString to calculate the width of each character. One problem is, Graphics does not have constructor. How can I get or create Graphics object, if the wrapping calculation must be inside one class library, not inside a dialog? Thanks so much for your help?
You can use
TextRenderer.MeasureText()
method instead.Regards:rose:
-
Hi, I'm doing some string wrapping calculation, and need graphics.MeasureString to calculate the width of each character. One problem is, Graphics does not have constructor. How can I get or create Graphics object, if the wrapping calculation must be inside one class library, not inside a dialog? Thanks so much for your help?
What about this MSDN article? How to: Create Graphics Objects for Drawing [^]
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
-
You can use
TextRenderer.MeasureText()
method instead.Regards:rose:
yeah, but
TextRenderer.MeasureText()
takesIDeviceContext
as argument, which he doesn't have.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
-
yeah, but
TextRenderer.MeasureText()
takesIDeviceContext
as argument, which he doesn't have.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
:wtf: Have you even read the the documentation[^]?
Regards:rose:
-
:wtf: Have you even read the the documentation[^]?
Regards:rose:
nope, just glanced :-O:doh: You are right of course. I was wondering why your correct answer got low vote, so I was bit fast in judgment. :rose:
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
-
nope, just glanced :-O:doh: You are right of course. I was wondering why your correct answer got low vote, so I was bit fast in judgment. :rose:
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
Thanks dnh. I was wondering why it got two without the voting guy telling me what's wrong. When you posted your reply I thought you were the guy and that's your reason -felt little frustrated at first:->, sorry!-. Now I wonder again. See you on the forums.
Regards:rose:
-
What about this MSDN article? How to: Create Graphics Objects for Drawing [^]
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
Thank you for all of your replies. I have tried to use TextRenderer.MeasureText(), it works fine.. But I still prefer using Graphics to Measure, I found that it is more accurate. Because I need to set some scaleing and measure unit in graphics. The method I get the Graphics is, I create a Form, and then use Form.CreateGraphics(), seems a stupid method ^_^, but works finally.