C#

Started by
4 comments, last by Arild Fines 18 years, 6 months ago
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.
Advertisement
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
You can use the Graphics class in the .NET framework to draw boxes and stuff. You could even use the GDI extensions. SDL.NET uses SDL_gfx for primitive drawing.
Rob Loach [Website] [Projects] [Contact]
ok I need to convert double to float, how do I do that.
theres not Convert.Tofloat(value)

is it possible to do that?
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]
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.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement