Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Some questions about ControlNodes (Read 3078 times)
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Some questions about ControlNodes
Dec 15th, 2011 at 9:41am
Print Post  
Hi !

Today I played a little bit with ControlNodes. And I have some questions about that.

What I´m trying to do is to use a UserControl with a custom drawing.

Here you can find my actual test project:
https://www.logview.info/Temp/Mind/ControlNode_Test.zip

1) How can I set the Border to zero to get the Links direct to the node? There is always a gab from ~3-4 Pixels:


2) How can I set the Nodes to move only? I don´t need resizeable nodes. I only want to resize the Nodes from code. I set ShapeHandleStyle to "MoveOnly" but that won´t help.

3) If you start the project from above the custom drawing is not painted. The drawing is visible if you resize the node. Did I something wrong with my paint job? I placed the painting in the Paint event of the UserControl.

4) Is there any setting for only moving nodes within the DiagramView? At the moment I have to grap the node at the outer border to move it. But it would be great if I coult switch to a "move only" mode where the user can grap the node at any point.

5) Where can i control the size of the diagramView? I have always Scrollbars and have no idea how to avoid that.

6) Is there a awy to avoid the "big" from for resizing / moving?

As written in 2) I only need a move for the nodes.

Greetz
  Dominik
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some questions about ControlNodes
Reply #1 - Dec 15th, 2011 at 12:38pm
Print Post  
Hi,

If you are going to draw this yourself anyway, better derive from DiagramNode or ShapeNode and override the Draw method. Hosted controls cannot be integrated that well with the rest of the diagram, e.g. you cannot mix them with other items in the Z order, and the diagram cannot always detect mouse operations on the controls.

1) Set the ControlNode.ControlPadding property.

2) ShapeHandlesStyle is the default for ShapeNodes. For ControlNodes you will have to set HandlesStyle or EnabledHandles on individual objects.

3) The problem is you are not drawing on the Graphics supplied with the event. Replace this

DrawIN(this.CreateGraphics(), 0, 0, "IN");

with

DrawIN(e.Graphics, 0, 0, "IN");

You should also call Dispose on the pens and brushes used in DrawIN, or you'll start getting GDI+ exceptions after drawing the controls several thousand times.

4) Set host.HandlesStyle = HandlesStyle.MoveOnly;

5) Set smaller Diagram.Bounds or DiagramView.ShowScrollbars = false;

6) I'm not sure what you mean by that Smiley

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Some questions about ControlNodes
Reply #2 - Dec 15th, 2011 at 1:34pm
Print Post  
Hi Stoyan,

I´m really impressed  Cheesy

I just implemented my own Node based on a DiagramNode Class. That is really amazing and works like a charm.
Thx again for your help!

I tried to append some drawing to the DRAW Methode:
Code
Select All
	  public override void Draw(IGraphics graphics, RenderOptions options)
	  {
		Rectangle iconSizePixels = new Rectangle(0, 0, icon.Width, icon.Height);
		RectangleF imageSize = MindFusion.Utilities.DeviceToDoc(graphics, iconSizePixels);

		// Draw the icon center at the top
		graphics.DrawImage(icon,
		    Bounds.X + Bounds.Width / 2 - imageSize.Width / 2, Bounds.Y);

		// Draw the label at the bottom
		RectangleF labelBounds = RectangleF.FromLTRB(
		    Bounds.X, Bounds.Y + imageSize.Height, Bounds.Right, Bounds.Bottom);
		graphics.DrawString(label,
		    Font, Brushes.Black, labelBounds, format);

		//// Draw Rectangle at right top
		//var penn = new System.Drawing.Pen(Color.Red);
		//graphics.DrawRectangle(penn, 40, 1, 4, 4);
		Font font = new Font("Arial", 7, FontStyle.Bold, GraphicsUnit.Pixel);
		graphics.DrawString("test", font, Brushes.Aqua, 2,2);
	  } 



But DrawRectangle and DrawString are both at drawn to the diagram and not to the node  ???
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some questions about ControlNodes
Reply #3 - Dec 15th, 2011 at 1:41pm
Print Post  
Have you appended this to the IconNodes sample project? You should draw relatively to the node's Bounds as the sample shows, instead of using fixed positions. So replace

graphics.DrawString("test", font, Brushes.Aqua, 2,2);

with

graphics.DrawString("test", font, Brushes.Aqua, Bounds.X + 2, Bounds.Y + 2);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Some questions about ControlNodes
Reply #4 - Dec 15th, 2011 at 1:49pm
Print Post  
Yes that helped alot.

Thx again !

Ok one last question..
What is the easiest way to detect if the user clicks on a special area (red rectangle area for example) at the node?


Greetz
   Dominik
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some questions about ControlNodes
Reply #5 - Dec 15th, 2011 at 6:15pm
Print Post  
You could handle NodeClicked like this:

Code
Select All
var size = ...;
var r = e.Node.Bounds;
r = RectangleF.FromLTRB(r.Right - size, r.Top, r.Right, r.Top + size);
if (r.Contains(e.MousePosition))
	... 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint