PROGRAMMING > C / C++ /C#
C# - Getting started with graphic functions
combatking0:
I have completed my first C# program - an updated version of Zero Encrypter, which encompasses all of my C# skills to date.
Since then, I have been researching the graphical functions of C#, but I cannot even figure out how to make it draw a line, for example:
Yabasic - line(x1,y1, x2,y2)
ActionScript - moveTo(x1,y1); lineTo(x2,y2);
There also seem to be many implementations of OpenGL for C# - if C# does not support graphical functions natively, which implementation of OpenGL would you suggest is best to use in terms of portability? So far, I have found OpenTK and Tao API. Are there any standard ones?
Or should I switch to C++ until C# is officially supported by the OpenGL group?
Raizor:
@CK
There's lots of built in functionality for drawing lines and all sorts of other shapes in C#. Have a look at the Graphics class. which provides lots of methods for such things.
Each control in C# has a CreateGraphics() methods that will return a Graphics object (representing the surface of the control) that you can then draw onto. For playing around, I suggest creating a simple form, chucking a Canvas or PictureBox control on it and then calling CreateGraphics() on the Canvas control and try drawing some stuff.
Be aware that the controls will automatically repainted (redrawn) when they're invalidated (by moving the window off-screen and then on-screen for example, which fires the repainting of the control). If you've done some custom drawing on the surface, this will get wiped when the control is redrawn. Have a look at the Paint event for some info on overriding this behaviour or drawing your own stuff on top of the control each time it's repainted. That link also shows a basic example at the bottom which will probably prove useful to you. Once you've got the hang of this, you can draw text and images too. You can also do pixel manipulation and other stuff, but I'd leave that until you've got your head round this stuff first.
Hope this helps.
Raizor:
Here's a tutorial I found that looks quite handy.
combatking0:
It's so obvious now - thanks for pointing me in the right direction, Raizor. K++
(edit)
I've got it working - it's only a green circle, but its graphics. Time for something more complex :)
Raizor:
--- Quote from: combatking0 on June 09, 2012 ---It's so obvious now - thanks for pointing me in the right direction, Raizor. K++
(edit)
I've got it working - it's only a green circle, but its graphics. Time for something more complex :)
--- End quote ---
Good news, you're welcome. Everything seems obvious in hindsight though. There's a ton of different namespaces and assemblies in .Net, so tracking things down can be a little tricky at first. Feel free to hit me up whenever you need and I'll do my best to assist with this stuff.
On the subject of OpenGL in C#, I still thoroughly recommend the OpenTK stuff. If you want to play with DirectX, then have a look at SlimDX. It's written by lx/Frequency and looks very nice. I've not used it myself though.
Navigation
[0] Message Index
[#] Next page
Go to full version