Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Scroll after node creation (Read 1605 times)
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Scroll after node creation
Dec 2nd, 2008 at 3:01pm
Print Post  
Hi!

I create nodes programmatically in my constructor. The horizontal scrollbar is not displayed and I can't pan. It's like the size of the graphic is not correct. If I resize the window and move the last node, it works fine afterwards... Do you know what is wrong with my code?

Here is the code in the constructor:
Code
Select All
int nodeCount = 20;
int xShift = 200;
int yShift = 100;
int xMax = 1000;
float width = 100;
int height = 75;
float xPos = 0;
float yPos = 0;
for (int i = 0; i < nodeCount; i++)
{
    TableNode node = new TableNode(this.diagram1);
    this.diagram1.Items.Add(node);

    int number = i + 1;
    node.Caption = "Node " + number;
    node.Bounds = new RectangleF(xPos, yPos, width, height);

    xPos += xShift;

    if (xPos >= xMax)
    {
        xPos = 0;
        yPos += yShift;
    }
} 



Designer code:
Code
Select All
#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
    this.diagramView1 = new MindFusion.Diagramming.WinForms.DiagramView();
    this.diagram1 = new MindFusion.Diagramming.Diagram();
    this.SuspendLayout();
    //
    // diagramView1
    //
    this.diagramView1.Behavior = MindFusion.Diagramming.Behavior.LinkShapes;
    this.diagramView1.ControlHandlesStyle = MindFusion.Diagramming.HandlesStyle.HatchHandles;
    this.diagramView1.ControlMouseAction = MindFusion.Diagramming.ControlMouseAction.SelectNode;
    this.diagramView1.DelKeyAction = MindFusion.Diagramming.DelKeyAction.DeleteSelectedItems;
    this.diagramView1.Diagram = this.diagram1;
    this.diagramView1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.diagramView1.Location = new System.Drawing.Point(0, 0);
    this.diagramView1.MiddleButtonActions = MindFusion.Diagramming.MouseButtonActions.Pan;
    this.diagramView1.ModificationStart = MindFusion.Diagramming.ModificationStart.SelectedOnly;
    this.diagramView1.Name = "diagramView1";
    this.diagramView1.RightButtonActions = MindFusion.Diagramming.MouseButtonActions.Cancel;
    this.diagramView1.Size = new System.Drawing.Size(292, 266);
    this.diagramView1.TabIndex = 0;
    this.diagramView1.Text = "diagramView1";
    //
    // diagram1
    //
    this.diagram1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
    this.diagram1.GridSizeX = 25F;
    this.diagram1.GridSizeY = 25F;
    this.diagram1.MeasureUnit = System.Drawing.GraphicsUnit.Pixel;
    this.diagram1.RoutingOptions.GridSize = 16F;
    this.diagram1.RoutingOptions.NodeVicinitySize = 48F;
    this.diagram1.TableCaptionHeight = 25F;
    this.diagram1.TableColumnWidth = 80F;
    this.diagram1.TableRowHeight = 24F;
    //
    // Form1
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.diagramView1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false);

}

#endregion

private MindFusion.Diagramming.WinForms.DiagramView 



All this code comes from a little sample program I did to narrow down the problem... There isn't any more code except for auto-generated one. It's just a window with a diagram view in it.

Thanks!
Marie

Note: the same problem occurs after loading a saved graph.
« Last Edit: Dec 9th, 2008 at 2:52pm by marie »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Scroll after node creation
Reply #1 - Dec 2nd, 2008 at 3:22pm
Print Post  
Call Diagram.ResizeToFitItems() after creating all nodes. This is not done automatically after creating nodes from code, because it could slow down your program a lot if you create many nodes in a loop.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Scroll after node creation
Reply #2 - Dec 2nd, 2008 at 4:07pm
Print Post  
Thanks Stoyan!

It works great. I added it after loading a saved graph as well and it solves both problems.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint