Create an object surface using GDI+

  • Thread starter Thread starter Alejandro Serrano
  • Start date Start date
A

Alejandro Serrano

Hi,
I'm trying to create an object surface (much like PowerPoint's, but for
easier things) using GDI+. I mantain a record of the objects, and their
properties, so as of now I'm able to paint the items in the Graphics object.
However, I also need to make some work with this objects. The first one
is to know, when the user clicks somewhere, in which of the items he or
she has clicked. As first, I was trying to use Rectangle methods, but my
items can be rotated, so it doesn't work very well.
Second, I need to move the items, so I don't know how to do it well. For
example, an user clicks on an item, a popup menu shows, and selects
rotate. The actual results must be shown on the screen until the user
accepts the changes.
Is there any tutorial / information / help available for waht I'm
looking for?

Thanks in advance
 
Robbe Morris [C# MVP] escribió:
This might be a good start depending on
your requirements.

http://www.eggheadcafe.com/articles/draw_tree_with_gdi_plus.asp

This tutorial manages wll the problem. However, I need to where where the user has clicked not just
based in rectangles, like here, but on rectangle or ellipses that can be rotated, each one at a
different rotation.
In addition, I need to provide some drag&drop functionality for the objects inside the design surface.

Thanks
 
Check out my signature. All the hard work is done.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

Alejandro Serrano said:
Robbe Morris [C# MVP] escribió:
This might be a good start depending on
your requirements.

http://www.eggheadcafe.com/articles/draw_tree_with_gdi_plus.asp

This tutorial manages wll the problem. However, I need to where where the
user has clicked not just based in rectangles, like here, but on rectangle
or ellipses that can be rotated, each one at a different rotation.
In addition, I need to provide some drag&drop functionality for the
objects inside the design surface.

Thanks
 
I don't know of any tutorials but I did something similar to what MS Word
does for drawing, moving, sizing Drawing Shapes. I am not suggesting this is
the best approach but it does work.

For hit testing, you can define a collection of GraphicsPath objects that
surround the shapes you create. You can tell if the user clicks in any one of
these using something like:

foreach (GraphicsPath p in pathsCollection)
{
if (p.IsVisible(mouseLoc)) // user clicked in the shape that corresponds to
this path
....
}

For rotated objects, you need to apply the transformation matrix to the
paths.

For moving objects, when the mouse enters an object, I change the cursor
style to indicate the mouse is in an object. When the user presses the left
button, I simply repaint the graphics paths with each mouse movement using
the same graphics path objects. For this technique, I had to write a
DrawReversiblePath method so no graphic relics would be cluttering the screen.
 
You didn't look closely enough at the sample code.
Basically, in the onclick event or any of the
mouse down or mouse up events, you grab
the x,y of the clicked section and see if it
is a match on the drawn objects.

The sample code figures out the dimensions
that the object should contain when drawn.
You can always iterate back through
the collections and figure out what item
was drawn where.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://robbemorris.blogspot.com





Alejandro Serrano said:
Robbe Morris [C# MVP] escribió:
This might be a good start depending on
your requirements.

http://www.eggheadcafe.com/articles/draw_tree_with_gdi_plus.asp

This tutorial manages wll the problem. However, I need to where where the
user has clicked not just based in rectangles, like here, but on rectangle
or ellipses that can be rotated, each one at a different rotation.
In addition, I need to provide some drag&drop functionality for the
objects inside the design surface.

Thanks
 
Back
Top