[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Graphics in C#

Posted on 2011-03-04
8
Medium Priority
?
394 Views
Last Modified: 2013-12-17
Experts,

I`m using VS2008, C# 3.5

Given a List of spatial co-ordinates [X, Y and Z]. How do you draw the underlying shape in a C# application. I do realize there is a lot of Math involved. I`m still in the planning phase, so directions and suggestions will be greatly appreciated before I start out. Should I be using some kind of Graphics package? Are they drawn on a regular Panel. Examples of code will be welcome, even a simple cube or a triangle. I first have to get the idea of how its done, and then I can work on the more complex stuff.

Thanks,
San
0
Comment
Question by:San24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Accepted Solution

by:
Rahul Agarwal earned 800 total points
ID: 35037674
0
 
LVL 7

Assisted Solution

by:jdavistx
jdavistx earned 1200 total points
ID: 35037738
Initially, you probably want to consider if you're going to be animating your drawing, allowing interaction with the surface, just drawing static images, and other concepts along those lines.

You can use the Graphics class to draw on your surface
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx

Your surface could come from different places.  You could get the graphics object from a Control, a PrintPageEventArgs, create a new one, etc.

Once you have that graphics object, you can then draw on it using the methods of the Graphics class.  Then you can begin to look in to how/when you update this graphics object, which is the trickier side of drawing your own graphics.

Just as a really simple example, assuming you just had a new blank Windows form, you could draw a diagonal line across it with the following:
private void Form1_Paint(object sender, PaintEventArgs e)
{
	Graphics g = this.CreateGraphics();
	Pen p = new Pen(Color.Black, 5);
	
	g.DrawLine(p, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
}

Open in new window


The above create a new graphics object from the form (this), we create a new pen, and then we use the Pen to draw on the Graphics object we created from the form.

We put it in the Paint event so that any time the Form is drawn, it will draw our line for us.

Hope this helps to get you started.
0
 

Author Comment

by:San24
ID: 35037794
jdavistx and agarwalrahul - Thanks.

I have basic understanding of how graphics work. What is GDI+ and DirectX and all? Should I be looking into it. At some point I will have to animate it.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Assisted Solution

by:Rahul Agarwal
Rahul Agarwal earned 800 total points
ID: 35037926
0
 
LVL 7

Assisted Solution

by:jdavistx
jdavistx earned 1200 total points
ID: 35038486
GDI+
http://msdn.microsoft.com/en-us/library/ms533798%28v=vs.85%29.aspx

"Windows GDI+ is a class-based API for C/C++ programmers. It enables applications to use graphics and formatted text on both the video display and the printer. Applications based on the Microsoft Win32 API do not access graphics hardware directly. Instead, GDI+ interacts with device drivers on behalf of applications."

DirectX
http://msdn.microsoft.com/en-us/directx/default

Your question is very broad.  DirectX is a hefty API for handling all the imaginable aspects of manipulating the video, input and sound for whatever you're developing.  I imagine you could embed a C/C++ based DirectX app within a C# app, but I would anticipate this to be an involved process.

Alternatively, you could use OpenGL for rendering your graphics
http://www.opengl.org/documentation/

Expect to have a stronger understanding of linear algebra concepts, vector math, and matrix manipulation to understand (conceptually) what you're doing with the above APIs.

If you're looking to do graphics in C#, you want to use GDI.  As for animating those graphics, there's several tutorials available.
http://www.java2s.com/Code/CSharp/2D-Graphics/Animation.htm

However, I would also suggest that if you intend to do a graphic/animation intensive C# app, that you should base it on a WPF app rather than a WinForm app.  While you  can do all the animating, graphics, etc with a WinForm app, these types of apps are more suited to be developed as WPF apps.
0
 

Author Comment

by:San24
ID: 35039762
@jdavistx _ Thanks for the help. For now, I`m using GDI+. Once I have the basics right I can move to a different more complex platform.

Well, when I started off, WPF was an option - but I need to show wire meshes - connecting lines and WPF doesn`t support this. So, I had to chuck this option.


0
 
LVL 7

Assisted Solution

by:jdavistx
jdavistx earned 1200 total points
ID: 35040706
Show wire meshes?

I'm sure you could.  There's some pretty intensive charts/graph C# apps that go a long way to show some of the neat stuff you can do without the use of DirectX/OpenGl/et al
0
 

Author Comment

by:San24
ID: 35056699
You can but you`ll have to use resources outside the framework - like using _3DTools;, and right now I don`t want go that way.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question