Sign in to follow this  
Ksingh30

C#

Recommended Posts

Ksingh30    100
is there a way I can dynamically draw pictures in C#, for example I have a program its does some stuff, and based on the result I wanna draw a box or a sphere. what would be the best method to draw this.

Share this post


Link to post
Share on other sites
Agony    3452
The System.Drawing namespace (GDI+) has a buttload of stuff that allows all sorts of flexible drawing. To use this stuff, you need to get a Graphics object, which is most easily obtained from a System.Windows.Forms.Control object using the CreateGraphics() method. Using the Graphics object, you can call various Draw* methods to draw lines, curves, filled shapes, and images. The documentation should contain a wealth of information for you to browse.

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by Ksingh30
ok I need to convert double to float, how do I do that.
theres not Convert.Tofloat(value)

is it possible to do that?


Yes, it's an explicit conversion:

double val1 = 5;
float val2 = (float)val1;

I tried it in C# to make sure it works before hand [wink] That should do it. For more information on that nonsense in C#, look at this MSDN page. It can get quite confusing at times when you need a function to go between types or just a typecast.

[edit]Explicit conversions page. The other link is for the implicit ones.

[Edited by - Drew_Benton on October 8, 2005 3:21:45 AM]

Share this post


Link to post
Share on other sites
Arild Fines    968
Quote:
Original post by Ksingh30
ok I need to convert double to float, how do I do that.
theres not Convert.Tofloat(value)

You're looking for Convert.ToSingle(value). A float is a "single precision floating point" variable. But it just gives you the same result as what Drew_Benton posted, so you should really use that instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this