Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Soem basic advice (Read 10820 times)
BidMaestro
Junior Member
**
Offline


to learn is to live

Posts: 74
Location: Australia
Joined: Apr 20th, 2008
Soem basic advice
Oct 31st, 2008 at 3:17am
Print Post  
Hi All

I have looked at the supplied example programs and trawled through this forum and could not find some basic examples of vb.net  code that I would to implement.

The first is zoomtorect. Where an area I select within the clientarea using my mouse is then 'zoomed' to become the new client area.

The second is the ability to centre  on the screen a selected node....expecially when using zoomin/zoomout and keeping the selected note in the centre of the client area.

regards
Doug

  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Soem basic advice
Reply #1 - Oct 31st, 2008 at 8:11am
Print Post  
Hi,

You can do this using the DrawShapes behavior by setting a boolean flag when the zoom tool is selected and handling a few events:

Code
Select All
private bool zoomToRectTool = true;

private void diagram_InitializeNode(object sender, MindFusion.Diagramming.NodeEventArgs e)
{
	ShapeNode node = e.Node as ShapeNode;
	if (zoomToRectTool && node != null)
	{
		node.Shape = Shapes.Rectangle;
		node.Pen = new Pen(Color.LightGray, 0);
		node.Brush = new SolidBrush(Color.Transparent);
		node.ShadowColor = Color.Transparent;
		node.Text = "select the area to zoom to";
	}
}

private void diagram_NodeCreated(object sender, MindFusion.Diagramming.NodeEventArgs e)
{
	ShapeNode node = e.Node as ShapeNode;
	if (zoomToRectTool && node != null)
	{
		diagramView.ZoomToRect(node.Bounds);
		diagram.Nodes.Remove(node);
	}
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Soem basic advice
Reply #2 - Oct 31st, 2008 at 8:27am
Print Post  
You can handle MouseWheel to zoom into or out from the pointed diagram point like this:

Code
Select All
private void diagramView_MouseWheel(object sender, MouseEventArgs e)
{
	Point p = diagramView.PointToClient(Cursor.Position);
	PointF oldcurpos = diagramView.ClientToDoc(p);

	diagramView.ZoomFactor += e.Delta / 60f;

	PointF newcurpos = diagramView.ClientToDoc(diagramView.PointToClient(Cursor.Position));
	float diffx = (oldcurpos.X - newcurpos.X);
	float diffy = (oldcurpos.Y - newcurpos.Y);

	diagramView.ScrollTo(
		diagramView.ScrollX + diffx < 0 ? 0 : diagramView.ScrollX + diffx,
		diagramView.ScrollY + diffy < 0 ? 0 : diagramView.ScrollY + diffy);
}
 



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


to learn is to live

Posts: 74
Location: Australia
Joined: Apr 20th, 2008
Re: Soem basic advice
Reply #3 - Oct 31st, 2008 at 10:19am
Print Post  
Good evening Stoyo (it is 8:20pm here)

Thank you for the reply, per chance do you have the vb.net equivalent of your code? I do not know C, or C+ or C#

If not, I shall try and convert

regards
Doug
  
Back to top
WWW  
IP Logged
 
BidMaestro
Junior Member
**
Offline


to learn is to live

Posts: 74
Location: Australia
Joined: Apr 20th, 2008
Re: Soem basic advice
Reply #4 - Oct 31st, 2008 at 10:49am
Print Post  
Stoyo

I had a go at converting to C code to VB.net for the screen zoom using the mousewheel and it works...might not be elegant code however here it is.

    Private Sub dvMain_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dvMain.MouseWheel
       Dim cursorpos As Drawing.Point
       Dim oldcurposF As Drawing.PointF
       Dim newcurposF As Drawing.PointF
       Dim diffx As Single
       Dim diffy As Single

       cursorpos = dvMain.PointToClient(Cursor.Position)
       oldcurposF = dvMain.ClientToDoc(cursorpos)

       dvMain.ZoomFactor += e.Delta / 60.0F
       newcurposF = dvMain.ClientToDoc(dvMain.PointToClient(Cursor.Position))

       diffx = oldcurposF.X - newcurposF.X
       diffy = oldcurposF.Y - newcurposF.Y

       dvMain.ScrollTo(dvMain.ScrollX + diffx, dvMain.ScrollY + diffy)

    End Sub
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Soem basic advice
Reply #5 - Oct 31st, 2008 at 11:31am
Print Post  
The first two methods should look like this in VB:

Code
Select All
Dim zoomToRectTool As Boolean = True

Private Sub Diagram_InitializeNode(ByVal sender As System.Object, ByVal e As NodeEventArgs) Handles diagram.InitializeNode
	Dim node As ShapeNode = CType(e.Node, ShapeNode)
	If (zoomToRectTool And Not node Is Nothing) Then
		node.Shape = Shapes.Rectangle
		node.Pen = New Pen(Color.LightGray, 0)
		node.Brush = New SolidBrush(Color.Transparent)
		node.ShadowColor = Color.Transparent
		node.Text = "select the area to zoom to"
	End If
End Sub

Private Sub Diagram_NodeCreated(ByVal sender As System.Object, ByVal e As NodeEventArgs) Handles diagram.NodeCreated
	Dim node As ShapeNode = CType(e.Node, ShapeNode)
	If zoomToRectTool And Not node Is Nothing Then
		diagramView.ZoomToRect(node.Bounds)
		diagram.Nodes.Remove(node)
	End If
End Sub
 



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


to learn is to live

Posts: 74
Location: Australia
Joined: Apr 20th, 2008
Re: Soem basic advice
Reply #6 - Oct 31st, 2008 at 1:26pm
Print Post  
Stoyo

Thank you.... code works wonderfully well.

Have a great weekend

Doug
  
Back to top
WWW  
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: Soem basic advice
Reply #7 - Apr 12th, 2009 at 10:10pm
Print Post  
Hi.

Code works. But what can i do to prevent selection & editing nodes? What I want is to have zoom mouse cursor and allow to user only zoom functionality.
Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Soem basic advice
Reply #8 - Apr 13th, 2009 at 8:22am
Print Post  
Hi,

You could handle NodeSelecting and set e.Cancel = true while in zoom mode, or perhaps set Locked = true for all nodes.

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



Posts: 90
Joined: Nov 29th, 2008
Re: Soem basic advice
Reply #9 - Apr 13th, 2009 at 10:05am
Print Post  
Hi!

It works only when

DiagramView.ModificationStart = ModificationStart.SelectedOnly

What to do in situation

DiagramView.ModificationStart = ModificationStart.AutoHandles

There is only NodeSelected event raised.
???
Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Soem basic advice
Reply #10 - Apr 13th, 2009 at 10:10am
Print Post  
You don't need ModificationStart = AutoHandles in zoom mode right? So, set it to SelectedOnly if that works for you.
  
Back to top
 
IP Logged
 
deanhully
YaBB Newbies
*
Offline



Posts: 26
Joined: Aug 25th, 2008
Re: Soem basic advice
Reply #11 - Sep 24th, 2009 at 4:08pm
Print Post  
Stoyo - I was trying this code out and it works except if I zoom out (decrease zoom factor) and then select the nodes/links on the diagramview the scrollto values revert to 0 and the nodes/links shift up and to the left (by the scroll amount?).

I created a stripped down project to demonstrate this if that would help.

Thanks,

Dean


[quote author=BidMaestro link=1225423028/0#4 date=1225450177]Stoyo

I had a go at converting to C code to VB.net for the screen zoom using the mousewheel and it works...might not be elegant code however here it is.

Private Sub dvMain_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dvMain.MouseWheel

Dim cursorpos As Drawing.Point

Dim oldcurposF As Drawing.PointF

Dim newcurposF As Drawing.PointF

Dim diffx As Single

Dim diffy As Single


cursorpos = dvMain.PointToClient(Cursor.Position)

oldcurposF = dvMain.ClientToDoc(cursorpos)


dvMain.ZoomFactor += e.Delta / 60.0F

newcurposF = dvMain.ClientToDoc(dvMain.PointToClient(Cursor.Position))


diffx = oldcurposF.X - newcurposF.X

diffy = oldcurposF.Y - newcurposF.Y


dvMain.ScrollTo(dvMain.ScrollX + diffx, dvMain.ScrollY + diffy)

End Sub[/quote]
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Soem basic advice
Reply #12 - Sep 24th, 2009 at 5:36pm
Print Post  
Hi Dean,

The control doesn't allow scrolling past diagram.Bounds, and seems that's enforced when you click on items to select them. You could try setting larger diagram.Bounds value when zooming out and restore it when zooming in. This should let the centering code set ScrollX/Y values smaller than 0 when needed.

Stoyan
  
Back to top
 
IP Logged
 
deanhully
YaBB Newbies
*
Offline



Posts: 26
Joined: Aug 25th, 2008
Re: Soem basic advice
Reply #13 - Sep 25th, 2009 at 1:42pm
Print Post  
Stoyo - could flesh out some psuedo code on how I might implement your advice?

Thanks,

Dean
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Soem basic advice
Reply #14 - Sep 27th, 2009 at 12:07pm
Print Post  
Hi Dean,

It seems that happens because of AutoScroll: the auto-scrolling function enforces the new scroll position to be inside diagram.Bounds, while the mouse-wheel handler might set the scroll position to be outside Bounds. One way to work around that is to make sure diagram.Bounds contains the new scroll position as shown below.

Code
Select All
Private Sub view_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles view.MouseWheel
	Dim cursorpos As Drawing.Point
	Dim oldcurposF As Drawing.PointF
	Dim newcurposF As Drawing.PointF
	Dim diffx As Single
	Dim diffy As Single

	cursorpos = view.PointToClient(Cursor.Position)
	oldcurposF = view.ClientToDoc(cursorpos)

	view.ZoomFactor += e.Delta / 60.0F
	newcurposF = view.ClientToDoc(view.PointToClient(Cursor.Position))

	diffx = oldcurposF.X - newcurposF.X
	diffy = oldcurposF.Y - newcurposF.Y

	Dim scrollPos As New PointF(view.ScrollX + diffx, view.ScrollY + diffy)
	If e.Delta < 0 Then
		' zooming out, make the diagram larger to prevent AutoScroll from jumping to 0,0
		If Not diag.Bounds.Contains(scrollPos) Then
			Dim minX = Math.Min(diag.Bounds.X, scrollPos.X)
			Dim minY = Math.Min(diag.Bounds.Y, scrollPos.Y)
			diag.Bounds = RectangleF.FromLTRB(minX, minY, diag.Bounds.Right, diag.Bounds.Bottom)
		End If
	Else
		' zooming in
		' possibly revert to a smaller Bounds size until the one from 100% zoom is reached
	End If

	view.ScrollTo(scrollPos.X, scrollPos.Y)
End Sub
 



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