Page Index Toggle Pages: [1] 2 3  Send TopicPrint
Very Hot Topic (More than 25 Replies) clipboard and ControlHost (Read 16277 times)
ampersand
Junior Member
**
Offline



Posts: 55
Joined: Sep 21st, 2006
clipboard and ControlHost
Nov 8th, 2006 at 10:44am
Print Post  
I'm using ControlHosts with embedded RichTextBoxes in my app. When I use the clipboard functions of flowChart like
Code
Select All
flowChart.CopyToClipboard(false); 


and paste it back the ControlHost and the RichTextBox are pasted, but the RichTextBox looses all its properties as Text, RTF, BackColor etc.

I assume I have to do it manually, but I am wondering where is the right location to do it. Especially I see some trouble when several ControlHosts are copied or even several chartObjects of different kinds.

I would be very grateful to get some hints how to solve this.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #1 - Nov 8th, 2006 at 11:24am
Print Post  
Are the properties restored correctly when you call SaveToFile() / LoadFromFile() ? Both CopyToClipboard and SaveToFile call the same SaveToStream method, and with the FCDemo sample there is a step that loads some RichText controls and their properties from a file...

Stoyan
  
Back to top
 
IP Logged
 
ampersand
Junior Member
**
Offline



Posts: 55
Joined: Sep 21st, 2006
Re: clipboard and ControlHost
Reply #2 - Nov 8th, 2006 at 11:57am
Print Post  
I am using XML Writer and Reader and there the loading works correct.

Code
Select All
private void saveToolButton_Click(object sender, EventArgs e)
{
  foreach (ControlHost host in btChart.ControlHosts)
  {
    if (host.Control is MERichTextBox)
	{
	   (host.Control as MERichTextBox).Tag = (host.Control as MERichTextBox).Rtf;
	}
    }
    string name = "Chart.xml";
    XmlWriter writer = new XmlWriter(btChart);
    writer.Options.CustomTagSerialization = true;
    writer.Write(name);
}



private void loadToolButton_Click(object sender, EventArgs e)
{
  string name = "Chart.xml";
  new XmlReader(btChart).Read(name);
  foreach (ControlHost host in btChart.ControlHosts)
  {
    if (host.Control is MERichTextBox)
    {
	(host.Control as MERichTextBox).Rtf = (string)(host.Control as MERichTextBox).Tag;
    }
  }
}
 



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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #3 - Nov 8th, 2006 at 12:08pm
Print Post  
Actually CopyToClipboard calls SaveToStream, but on items cloned from the original ones. It seems at this time cloning does not work that well for ControlHosts - we'll try to fix that in the following couple of days.

Stoyan
  
Back to top
 
IP Logged
 
ampersand
Junior Member
**
Offline



Posts: 55
Joined: Sep 21st, 2006
Re: clipboard and ControlHost
Reply #4 - Nov 8th, 2006 at 12:10pm
Print Post  
That is great.

Thanks Stoyan
  
Back to top
 
IP Logged
 
ampersand
Junior Member
**
Offline



Posts: 55
Joined: Sep 21st, 2006
Re: clipboard and ControlHost
Reply #5 - Nov 13th, 2006 at 6:19pm
Print Post  
Hi Stoyan,

any news on this issue?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #6 - Nov 14th, 2006 at 8:00am
Print Post  
Hi,

Yes, we have implemented copying all properties of hosted controls, using reflection, when cloning a ControlHost. However there is a problem - now we get an ObjectDisposedException when a RichText control is copied and the flowchart tries to display it.

The developer supposes that one or more of the properties should not be copied. If we cannot find out exactly which property causes the problem, we'll add some event that will let you copy only the properties you need.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #7 - Nov 14th, 2006 at 8:43am
Print Post  
Ok, for now use this version of the control:

https://mindfusion.org/_temp/chost.zip

and handle the CopyHostedControl event:

private void fc_CopyHostedControl(object sender, CopyHostedControlEventArgs e)
{
  RichTextBox src = e.Source as RichTextBox;
  RichTextBox dst = e.Destination as RichTextBox;

  if (src != null && dst != null)
  {
    dst.Text = src.Text;
    dst.ReadOnly = src.ReadOnly;
    // etc...
  }
}

We will make this automatic when we have some more time to find out why that exception happens.

Stoyan
  
Back to top
 
IP Logged
 
ampersand
Junior Member
**
Offline



Posts: 55
Joined: Sep 21st, 2006
Re: clipboard and ControlHost
Reply #8 - Nov 14th, 2006 at 8:46am
Print Post  
Thanks a lot.

I will try it asap.

Dirk
  
Back to top
 
IP Logged
 
ampersand
Junior Member
**
Offline



Posts: 55
Joined: Sep 21st, 2006
Re: clipboard and ControlHost
Reply #9 - Nov 15th, 2006 at 8:22am
Print Post  
Hi Stoyo,

I tested the new control and the CopyHostedControl event. In general the event works. I can set the color and size of the RTB and also the plain text. But I am not able to keep the RichText formatting in the text, i.e. bold, italic, font family, fontsize, bullets etc.

see the following picture (top: original, bottom: copy)


Here's the code in the CopyHostedControl event :

Code
Select All
if (e.Source.GetType() == typeof(MERichTextBox))
{
MERichTextBox src = e.Source as MERichTextBox;
MERichTextBox dst = e.Destination as MERichTextBox;
if (src != null && dst != null)
{
dst.BackColor = src.BackColor;
dst.BulletIndent = src.BulletIndent;
dst.ForeColor = src.ForeColor;
dst.Height = src.Height;
dst.Width = src.Width;
dst.ScrollBars = src.ScrollBars;
dst.ZoomFactor = src.ZoomFactor;
dst.Rtf = src.Rtf;
}
}
 



Although all formatting is within src.Rtf and in dst.Rtf it is not shown in the copied ControlHost.

Another thing is that CopyHostedControl is called when a ControlHost is copied and again called when it is pasted. Is there a reason for this behaviour?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #10 - Nov 15th, 2006 at 9:37am
Print Post  
Hi,

The code that deserializes ControlHosts from the clipboard uses reflection to deserialize all properties. It seems the Text property is handled after the Rtf one, and assign to Text removes all formatting. We will have to add some special handling for RichTextBox controls so that the Text property is ignored.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #11 - Nov 18th, 2006 at 1:23pm
Print Post  
Hi Dirk,

Try this version of the control:
https://mindfusion.org/_temp/chosts.zip

It updates two things:

- Now the control will automatically copy all value and string properties, so hopefully you won't need to handle the CopyHostedControl event. The exception that happened before was due to copying a scrollbar control exposed as a RichTextBox property. It isn't copied anymore since it's not from a value type.

- The Lines and Text properties of RichTextBox controls are explicitly ignored during copy&paste operations, so the RTF formatting should be preserved now.

You can still handle the copy event if you need to copy properties that aren't from value or string types.

Stoyan
  
Back to top
 
IP Logged
 
ampersand
Junior Member
**
Offline



Posts: 55
Joined: Sep 21st, 2006
Re: clipboard and ControlHost
Reply #12 - Nov 21st, 2006 at 11:41am
Print Post  
Hi Stoyo,

thanks for the update.

When I try to compile my Code I get an FileLoadException
in my *.Designer.cs file

Code
Select All
this.ruler = new MindFusion.FlowChartX.Ruler(); 



Error Message is

Quote:
System.IO.FileLoadException was unhandled
  Message="Could not load file or assembly 'FlowChart.NET, Version=4.2.1.22559, Culture=neutral, PublicKeyToken=a0d18338041985ba' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
  Source="Ruler"
  FileName="FlowChart.NET, Version=4.2.1.22559, Culture=neutral, PublicKeyToken=a0d18338041985ba"
  FusionLog="=== Pre-bind state information ===\r\nLOG: User = ZIGZAG2\\DWeber\r\nLOG: DisplayName = FlowChart.NET, Version=4.2.1.22559, Culture=neutral, PublicKeyToken=a0d18338041985ba\n (Fully-specified)\r\nLOG: Appbase = file:///D:/PRG/LayoutControlSolution/TestApp/bin/Debug/\r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : Ruler, Version=4.2.1.22571, Culture=neutral, PublicKeyToken=a0d18338041985ba.\r\n===\r\nLOG: This bind starts in default load context.\r\nLOG: No application configuration file found.\r\nLOG: Using machine configuration file from C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\config\\machine.config.\r\nLO
G: Post-policy reference: FlowChart.NET, Version=4.2.1.22559, Culture=neutral, PublicKeyToken=a0d18338041985ba\r\nLOG: Attempting download of new URL file:///D:/PRG/LayoutControlSolution/TestApp/bin/Debug/FlowChart.NET.DLL.\r\nWRN
: Comparing the assembly name resulted in the mismatch: Revision Number\r\nERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.\r\n"
  StackTrace:
      at MindFusion.FlowChartX.Ruler..ctor()
      at LayoutControl.MELayoutControl.InitializeComponent() in D:\PRG\LayoutControlSolution\LayoutControl\MELayoutControl.Designer.cs:line 34


Do I need also a new dll for the ruler control from you?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #13 - Nov 21st, 2006 at 12:11pm
Print Post  
Hi Dirk,

Yes, since the flowchart.net assembly is strong-named, the ruler.dll can work only with the flowchart.dll for which it was originally built. We'll rebuild all dlls now and upload them here.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: clipboard and ControlHost
Reply #14 - Nov 21st, 2006 at 12:25pm
Print Post  
Hi Dirk,

Here are some freshly-built dlls:
https://mindfusion.org/_temp/chost.zip

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint