views:

722

answers:

0

Hello All,

I am trying to arrange the shapes in canvas control before changing it to a bmp file. I am calling Measure, Arrange and updatelayout methods subsequently and opening the bmp file in documentviewer for printpreview functionatliy.

but, my shapes are connected by line with arrow head, which is not properly arranged (the arrowhead is pointing rightwards like |> instead of point downwards.).

if i re-try printpreview it works !.

do not know, what is the issue. I have posted printpreview code below.

I appreciate your help.

System.Windows.Documents.FixedDocument PreviewDocument = new System.Windows.Documents.FixedDocument(); 
foreach (TabItem tabItem in this.Items)   
{   
DesignerCanvas dcSource = (DesignerCanvas)tabItem.Content;  

Size szOrg = new Size(dcSource.ActualWidth, dcSource.ActualHeight);   
Size sz = new Size(700, 800);   
Size pageSize = new Size();   

pageSize.Width = szOrg.Width > sz.Width ? sz.Width : szOrg.Width;   
pageSize.Height = szOrg.Height > sz.Height ? sz.Height : szOrg.Height;   

dcSource.Measure(sz);   
dcSource.Arrange(new Rect(new Point(0, 0), sz));
dcSource.UpdateLayout();

System.Windows.Documents.PageContent pc = new System.Windows.Documents.PageContent();   
System.Windows.Documents.FixedPage fp = new System.Windows.Documents.FixedPage();   

//Capture the image of the visual in the same size as Printing page.      
System.Windows.Media.Imaging.RenderTargetBitmap bmp = new System.Windows.Media.Imaging.RenderTargetBitmap   
                                                     ((int)dcSource.ActualWidth, (int)dcSource.ActualHeight, 96, 96, PixelFormats.Pbgra32);   
bmp.Render(dcSource as Visual);   
DrawingVisual dv = new DrawingVisual();   
DrawingContext dc = dv.RenderOpen();   
dc.DrawImage(bmp,new Rect(pageSize));   
dc.Close();   

fp.Height = sz.Height;   
fp.Width = sz.Width;   

VisualContainer vc = new VisualContainer(); // custom class of type frameworkelement   
vc.AddVisual(dv); // add object to visualcollection   

fp.Children.Add(vc);   
((IAddChild)pc).AddChild(fp);   
PreviewDocument.Pages.Add(pc);  
}   
System.Drawing.Printing.PrintDocument PrintDoc = new                 System.Drawing.Printing.PrintDocument();   

PrintPreview PrintPreview1 = new PrintPreview();   
PrintPreview1.DocumentPreview.Document = PreviewDocument;   
PrintPreview1.ShowDialog();   
PreviewDocument = null;

Thanks,