Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Rendering ControlHosts in Background (Read 3037 times)
mafpinedo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jun 7th, 2010
Rendering ControlHosts in Background
Jun 7th, 2010 at 9:00am
Print Post  

Hello, i´m using Flowchart.NET.

I've a diagrma with a Control Host that contains a RichTextBox.

In order to export the view to word in Background, i need to get the image of the loaded diagram.
All the ShapeNodes are properly exported, my problem only comes on those Custom Control Host that contains those RichTextBoxes that are not rendered.

I´ve defined the DiagramView.PaintControl += flowChart_PaintControlHost that is where normally diagram loading render those controls.
Then the problem is how to force the invoke of this doing it in background to after get the correct image.

I tried also invoke the render from the FlowChart_DrawNode, but my problem there is that DrawNodeEventArgs has no PaintRect property.

Thanks in advance.
Miguel
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Rendering ControlHosts in Background
Reply #1 - Jun 7th, 2010 at 11:12am
Print Post  
Hi,

RichTextBox is not a native .NET control and so it lacks the DrawtoBitmap method available in other controls. Try using the RTFtoBitmap method from this post instead:
http://www.xtremedotnettalk.com/showthread.php?t=97131

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
mafpinedo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jun 7th, 2010
Re: Rendering ControlHosts in Background
Reply #2 - Jun 7th, 2010 at 11:45am
Print Post  
I've read the thread you said, but what i dont understand is where should i invoke the RTFToPicture2 class? I mean, any event in FlowChart implementation class, or inside the own RTF Control?

I dont just want to export the image of the control, i want the rendered image in the whole image of the FlowChart diagram. My problem is that the RTF is always gray when i call Flowchart.CreateImage().

Thanks again!

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Rendering ControlHosts in Background
Reply #3 - Jun 7th, 2010 at 12:10pm
Print Post  
Hi,

Try handling the PaintControl event like this:

Code
Select All
private void diagramView_PaintControl(object sender, PaintControlEventArgs e)
{
	RichTextBox richText = e.Node.Control as RichTextBox;
	if (richText != null)
	{
		e.Graphics.FillRectangle(Brushes.White, e.PaintRect);
		Rectangle paintRect = diagramView.DocToClient(e.PaintRect);
		RtfToPicture2 converter = new RtfToPicture2();
		Bitmap bmp = new Bitmap(paintRect.Size.Width, paintRect.Size.Height);
		converter.RTFtoBitmap(ref richText, ref bmp);
		if (bmp != null)
		{
			e.Graphics.DrawImage(bmp, e.PaintRect);
			bmp.Dispose();
		}
	}
} 



You might also remove the code from RTFtoBitmap that resizes the bitmap. It should not be required in this case and it erroneously does not dispose the bitmap. Or otherwise add a Dispose call there too…

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
mafpinedo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jun 7th, 2010
Re: Rendering ControlHosts in Background
Reply #4 - Jun 7th, 2010 at 1:16pm
Print Post  
That's what i had already done.

This is my piece of code.

private void diagramView_PaintControl(object sender, PaintControlEventArgs e)
{

ExtRichTextBox rtb = e.Node.Control as ExtRichTextBox;
           if (rtb != null)
           {
               MindFusion.Diagramming.Diagram temp = new MindFusion.Diagramming.Diagram();
               MindFusion.Diagramming.WinForms.DiagramView tempDV = new DiagramView();
               tempDV.Diagram = temp;
               temp.MeasureUnit = GraphicsUnit.Inch;
               RectangleF anInch = new RectangleF(0, 0, 1, 1);
               Rectangle devInch = tempDV.DocToClient(anInch);
               float dpi = devInch.Width;

               // Paint background (needed if text doesn't fill the control
               e.Graphics.FillRectangle(new System.Drawing.SolidBrush(rtb.BackColor), e.PaintRect);

               // render the control
               rtb = (ExtRichTextBox)e.Node.Control;
               Rectangle paintRect = diagramView.DocToClient(e.PaintRect);
               Rectangle pageRect = diagramView.DocToClient(flowChart.Bounds);

               IntPtr ptr = e.Graphics.GetHdc();

               using (Graphics g = Graphics.FromHdc(ptr))
               {
                   rtb.Render(g, paintRect);
               }

               e.Graphics.ReleaseHdc(ptr);
           }
}


My problem is that creating and loading in background the View on the fly, the event DiagramView.PaintControl is not raised and dont know how to force it being raised.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Rendering ControlHosts in Background
Reply #5 - Jun 7th, 2010 at 2:57pm
Print Post  
Hi,

Are you asking how to attach an event handler to the dynamically created view? It should look like

view.PaintControl += diagramView_PaintControl;

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
mafpinedo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jun 7th, 2010
Re: Rendering ControlHosts in Background
Reply #6 - Jun 7th, 2010 at 3:26pm
Print Post  
I´ve just fixed!

Cheesy

I had the event attached but i did the creation of the view programatically and  i missed this line, and that was avoiding the event to be raised.

this.DiagramView.Diagram = this.flowChart;

Thanks so much for your help!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint