Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Copy diagram to clipboard

Last post 10-22-2008 12:07 AM by David Blacketer. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-18-2007 2:44 PM

    Copy diagram to clipboard

    Hello,

    I would like to know how to copy the diagram to the clipboard as an image. I know how to set the clipboard data, I just need an idea on how to get the bitmap from the diagram (whole diagram, not only the visible part) on demand. Can anyone help ?
    • 87.105.212.19
  • 10-18-2007 6:35 PM In reply to

    Re: Copy diagram to clipboard

    Filed under: , , , ,
    • 81.156.199.203
  • 10-19-2007 12:12 PM In reply to

    Re: Copy diagram to clipboard

    Thank you, it works.
    • 87.105.212.19
  • 10-19-2007 12:27 PM In reply to

    Re: Copy diagram to clipboard

    Any chance you could post the complete code for other users who may struggle with the clipboard? Many thanks.

    Filed under:
    • 194.29.65.17
  • 10-19-2007 12:46 PM In reply to

    Re: Copy diagram to clipboard

    Sure, no problem. In fact it's not the code I use (we write in VB), it's a slightly modified version of the code from the link you provided. Clipboard class is in the System.Windows.Forms namespace and Bitmap is from System.Drawing.

    RenderList list = new RenderList(); 

    //Create render list, add only the shapes you want
    foreach (Shape shape in flowchart1.Shapes.Values)
    {
        list.Add(shape);
    }
    foreach (Line line in flowchart1.Lines.Values)
    {
        list.Add(line);
    }

    //Sort for correct zorder
    list.Sort();

    //Save existing render rectangle
    Rectangle rect = flowchart1.Render.RenderRectangle;

    //Set up renderer for output render
    flowchart1.RenderDesign.DrawGrid = false;
    flowchart1.Render.Elements = list;
    flowchart1.Render.RenderDiagram(new Rectangle(new Point(0, 0), flowchart1.DiagramSize));

     

    Bitmap bmp = new Bitmap(flowchart1.Render.Bitmap);

     

    //Reset render
    flowchart1.RenderDesign.DrawGrid = true;
    flowchart1.Render.RenderDiagram(rect);
    flowchart1.Refresh();

     

    // copy image to the clipboard in .NET 2.0

    Clipboard.SetImage(bmp);

     

    // .NET 1.x

    Clipboard.SetDataObject(bmp, true);

    Filed under:
    • 87.105.212.19
  • 10-22-2007 5:07 PM In reply to

    Re: Copy diagram to clipboard

    Thanks!

    • 194.29.65.17
  • 10-22-2008 12:07 AM In reply to

    Re: Copy diagram to clipboard

    Thanks, always very help full to have the code posted.

    A minor improvement I added to avoid unwanted white space is to determined the rectangle of "used" diagram space rather than taking the model.diagramsize property.

     

     

    • 203.34.64.32
Page 1 of 1 (7 items)