Author Topic: .NET Graphics Components  (Read 7342 times)

0 Members and 1 Guest are viewing this topic.

SomeCallMeDave

  • Guest
.NET Graphics Components
« on: December 21, 2007, 09:24:25 AM »
I have found myself needing to create small line diagrams for Windows apps.   So far,  I have muddled through using  System.Drawing.....
Surely there is a  better way.

I found a list of graphics components here

I was wondering what you guys were using and if you could recommend any or warn me away from any.

Right now, it would just be for experimentation, so a freebie would be preferred (or one with a trial version, at least)

BTW, I am using C#2008 Express,  but I do have VS2005 Standard.

Thanks

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: .NET Graphics Components
« Reply #1 on: December 21, 2007, 09:44:08 AM »
SCMD,

I haven't had much of a need for this type of thing myself, however Charles Petzold's book 'Programming Microsoft Windows with C#' does have a lot of graphics drawing in it from memory.

Can you allude as to what you're trying to accomplish, maybe with some screen cappies...?

Cheers,
Glenn.
Me

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: .NET Graphics Components
« Reply #2 on: December 21, 2007, 09:45:36 AM »
Another thought - can you create small bitmap/png's of what you need and embed them as resources into your dll and then load/draw the resource piccy into a picturebox for example?
Me

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: .NET Graphics Components
« Reply #3 on: December 21, 2007, 09:57:04 AM »
It does seem that GDI+ would give the most control, It might be fairly strait forward once you built your base object classes.
At one time I was pondering building a .SLD to GDI+ converter, but its beyond current my skill level.

SomeCallMeDave

  • Guest
Re: .NET Graphics Components
« Reply #4 on: December 21, 2007, 09:58:40 AM »
Glenn,
Attached is a screen capture of the simple one that I have done so far. I used the Help file and some stuff from the internet to figure out the simple diagram.
 I was able to get the coordinates that I needed by creating a sketch in Autocad.  The built-in components worked OK for this, but I can see if things get more complex, the coding could get intense.


But what I would really like to do with this little app is to have a simple 3D view that would show scenario a bit more intuitively .


The bitmap route doesn't really fit for this app because the values update with each re-calc.  (I figured out how to use the mousewheel to increment the values so the user can interactively adjust the scenario.  I'm really liking C#  :) )

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: .NET Graphics Components
« Reply #5 on: December 21, 2007, 10:02:29 AM »
SCMD,

I thought that was where you were heading. I concur with Dan - GDI+ will give the ultimate control.
Glad you're liking the .NET land of curly braces - the only way to go ;)

Nicely done BTW.

Cheers,
Glenn.
Me

SomeCallMeDave

  • Guest
Re: .NET Graphics Components
« Reply #6 on: December 21, 2007, 10:05:15 AM »
It does seem that GDI+ would give the most control, It might be fairly strait forward ....

Daniel,

I'm thinking that your definition of 'fairly strait forward' and mine vary a great deal  :)


SomeCallMeDave

  • Guest
Re: .NET Graphics Components
« Reply #7 on: December 21, 2007, 10:06:39 AM »
Glenn and Daniel,

Thanks for the advice.   I will dig further into GDI+ and save my money for something more tasty :)


Thanks again,

Dave

MickD

  • Gator
  • Posts: 3420
  • (x-in)->[process]->(y-out)
Re: .NET Graphics Components
« Reply #8 on: December 22, 2007, 09:52:48 PM »
David,
another option - but a whole new learning curve is either DirectX or OpenGL, once you have a device context you're set, just call the drawing functions supplied with the lib and you have a full 3d environment.
I mention these as you are heading down the 3d route otherwise for 2d drawing gdi would be ok.
If you will be sure that your app will only be windows based, DirectX would be the way to go although they do revise it regularly which is a bit of a pain with hardware and maintenance etc. It's OO and pretty straight forward and there are plenty of resources/tut's on the net.

OpenGL on the other hand is easier IMO and full (hardware accelerated) support in vista is not certain afaik. Look up Colin Fahey's opengl C# wrapper if you want to go down that path. To me it's easier and you can nearly use C code line for line in C# so there's plenty of source and examples around.

If you want some more info just holler.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: To attain knowledge, add things
every day; to obtain wisdom, remove things every day.

quamper

  • Guest
Re: .NET Graphics Components
« Reply #9 on: December 23, 2007, 08:41:57 AM »
If you will be sure that your app will only be windows based, DirectX would be the way to go although they do revise it regularly which is a bit of a pain with hardware and maintenance etc. It's OO and pretty straight forward and there are plenty of resources/tut's on the net.

OpenGL on the other hand is easier IMO and full (hardware accelerated) support in vista is not certain afaik. Look up Colin Fahey's opengl C# wrapper if you want to go down that path. To me it's easier and you can nearly use C code line for line in C# so there's plenty of source and examples around.

DirectX and OpenGL might be overkill. But if you do go that route, MDX (Managed DirectX is no more) they replaced it with the XNA framework. If you are looking at doing DirectX then the .NET then SlimDX is the way to go http://slimdx.mdxinfo.com/

For OpenGL you have the http://www.taoframework.com/ and SDL.NET http://cs-sdl.sourceforge.net/index.php/Main_Page Both of those are really nice .NET wrappers.

But for what you're doing GDI+ is probably best

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: .NET Graphics Components
« Reply #10 on: December 23, 2007, 09:41:13 AM »
Here is how I might start out with GDI+
Build a set of geometry/object classes, then add extension methods to the
System.Drawing.Graphics class to draw your stuff.

In this case, I created an extension method to draw an AutoCAD line on a form  8-)

Code: [Select]
public static class GraphicsExtension
  {
    public static void DrawLine(this Graphics m_this, Autodesk.AutoCAD.DatabaseServices.Line line)
    {
      Pen pn = new Pen(Color.White);
      m_this.DrawLine(pn, new Point((int)line.StartPoint.X, (int)line.StartPoint.Y),
                          new Point((int)line.EndPoint.X, (int)line.EndPoint.Y));
     

    }
  }

Code: [Select]
   private void panel1_Paint(object sender, PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      Line line1 = new Line(new Point3d(30, 30, 0), new Point3d(220, 220, 0));
      Line line2 = new Line(new Point3d(220, 30, 0), new Point3d(30, 220, 0));
      g.DrawLine(line1);
      g.DrawLine(line2);
    }



It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: .NET Graphics Components
« Reply #11 on: December 26, 2007, 12:38:40 PM »
..Surely there is a  better way...

You are right, this is too much work to use out of the box for simple lines and text. I want/need something similar for my casework application, a more dynamic graphic that updates with changes. I am working on a small set of classes to make these tasks more intuitive. Ill post code once I am little further along and if people are interested.

example of what I have so far

Code: [Select]

     Graphics g = e.Graphics;
      Pen pen = new Pen(Color.PapayaWhip);//hmmm interesting

      EntityList ents = new EntityList();

      ents.Add(new Text(g, textBox1.Text,
                        new Font("Verdana", 16), new SolidBrush(Color.Red), Center));

      ents.Add(new Ellipse(g, Center, 35, 10, pen, 33));//rotated
      ents.Add(new Line(g, pt1, pt2, pen));
      ents.Add(new Line(g, pt2, pt3, pen));
      ents.Add(new Line(g, pt3, pt4, pen));
      ents.Add(new Line(g, pt4, pt1, pen));
      ents.Add(new Circle(g, Center, diameter, pen));
      ents.Add(new Ellipse(g, Center, 35, 10, pen, -33));//rotated
      ents.Add(new Ellipse(g, Center, 35, 10, pen));
      ents.Draw();

      //rotated text
      Text txt = new Text(g, "Rotated", new Font("Verdana", 16),
                          new SolidBrush(Color.Red), new PointF(200, 200), -45);//rotated

      txt.Draw();



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: .NET Graphics Components
« Reply #12 on: December 26, 2007, 12:44:07 PM »

Ooops, missed this thread.
looks like fun guys !
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: .NET Graphics Components
« Reply #13 on: January 23, 2008, 02:01:37 AM »
Anyone want to play? Add Stuff?

Make a form
Make a panel
Make a paint event (see pic)
The origin is bottom left

See the sample code:
Code: [Select]
private void panel1_Paint(object sender, PaintEventArgs e)
    {
      DrawSpace drawSpace = new DrawSpace(panel1, e.Graphics);
      Pen pen = new Pen(Color.PapayaWhip);//hmmm interesting

      Line line1 = new Line(drawSpace, new PointF(10, 10), new PointF(100, 100), pen);
      line1.Draw();

      Text txt = new Text(drawSpace, "Rotated", new Font("Verdana", 16),
                          new SolidBrush(Color.Red), new PointF(100, 100), 45);//rotated
      txt.Draw();

      Ellipse ell = new Ellipse(drawSpace, new PointF(100, 200), 30, 50, pen, -45);
      ell.Draw();

      //
      EntityList eList = new EntityList();
      eList.Add(new Circle(drawSpace, new PointF(100, 100), 30, pen));
      eList.Add(new Line(drawSpace, new PointF(100, 100), new PointF(100, 200), pen));
      eList.Add(new Circle(drawSpace, drawSpace.LLPoint, 30, pen));
      eList.Add(new Arc(drawSpace, drawSpace.CenterPoint, 45, 0, 180, pen));
      eList.Draw();
    }

SomeCallMeDave

  • Guest
Re: .NET Graphics Components
« Reply #14 on: January 23, 2008, 07:09:51 AM »
Very nice Daniel. 

I know how my free time will be spent today  :)

Thanks for sharing.