Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Require content at the Centre of the client (Read 1723 times)
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Require content at the Centre of the client
Oct 24th, 2009 at 1:57pm
Print Post  
Hi Stoyan,

I have some nodes and links in the diagram.

If I call FitToScreen() function, Contents of the diagram should come in the center of the Client area.

But it is not working as expected.
Please suggest for this as early as possible.

Following is the code which for  FitToScreen().

private void FitToScreen()
       {
           diagram.ZoomToFit();
           if (diagram.ZoomFactor > 100)
           {
               diagram.ZoomFactor = 100;
           }
           
           Point p1 = scrollViewer.TransformToDescendant(diagram.DocumentPlane).Transform(
                      new Point(0, 0));
           Point p2 = scrollViewer.TransformToDescendant(diagram.DocumentPlane).Transform(
                      new Point(scrollViewer.ActualWidth, scrollViewer.ActualHeight));

           Rect containerRect = new Rect(p1, p2);
           Rect contentRect = diagram.GetContentBounds(false, false);

           double differenceInWidth = containerRect.Width - contentRect.Width;
           double differenceInHeight = containerRect.Height - contentRect.Height;

           Rect diagBounds = diagram.Bounds;
           diagBounds.Union(contentRect);
           diagram.Bounds = diagBounds;
           Point topLeft = new Point(contentRect.X + differenceInWidth / 2, contentRect.Y + differenceInHeight / 2);
           diagram.ScrollTo(diagram.ClientToDoc(topLeft));
      
       }


Regards,
Anshul.
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Require content at the Centre of the client
Reply #1 - Oct 26th, 2009 at 6:45am
Print Post  
Hi Stoyan,

Please suggest us for this problem.

Regards,
Anshul
« Last Edit: Oct 27th, 2009 at 9:39am by Anshul »  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Require content at the Centre of the client
Reply #2 - Oct 28th, 2009 at 8:43am
Print Post  
Hi Stoyan,

Any pointer for the above problem?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Require content at the Centre of the client
Reply #3 - Oct 28th, 2009 at 8:49am
Print Post  
One problem I can see is that topLeft is already in document coordinates, so you shouldn't call ClientToDoc on it when calling the scroll method.

Regards,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Require content at the Centre of the client
Reply #4 - Nov 12th, 2009 at 3:00pm
Print Post  
I have tried this but its not working. Any more suggestion?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint