Rich Text

Hi all,

I have a small problem and need your help.
I'm trying to implement a rich text diagram. It mimics GoText but is in rich text format instead. It should be a full RTF editor (including toolbars such as Font, Bold, Italic, Color, etc etc etc).
I've looked at Demo1.RichText that was given in GoDiagram 3.0.3 samples. It is very slow when it runs (much slower than GoText). Anybody knows why?
It uses the standard way of implementing your own Control class that inherits your desired .NET WinForm class (in our case RichTextBox) and implementing IGoControlObject interface.
Anybody knows why it's slow in run-time? (i.e. when editing or inputting text into it)
Any way of optimizing it or making it much faster?
I tried writing a much simpler class:
public class RtfControl : System.Windows.Forms.RichTextBox, Northwoods.Go.IGoControlObject { public RtfControl() { this.AllowDrop = false; this.AutoSize = false; this.ScrollBars = RichTextBoxScrollBars.None; } public GoControl GoControl { get { return _myGoControl; } set { _myGoControl = value; } } public GoView GoView { get { return _myGoView; } set { _myGoView = value; } } private GoControl _myGoControl = null; private GoView _myGoView = null; }
public Form1() { InitializeComponent();
GoControl ctrl = new GoControl(); ctrl.Selectable = false; ctrl.ControlType = typeof(RtfControl); // defined below ctrl.Size = new SizeF(200, 200); ctrl.Position = new PointF(300, 300); goView.Document.Add(ctrl);
goView.Refresh(); }
This code is very simple. Yet, it is still slow (as slow as Demo1.RichText).
Please help!
Thanks

Yeah, it is pretty bad. If you google RichTextBox and slow, you seem to get a lot of hits.



Have you considered HTML instead of RichText? The WebBrowser control may be a better choice. There’s a sample here in the forum for adding it. I’m not sure what’s involved in creating an editor out of it.

Although I’m not “Nas_c”, I am the one who started the thread/topic. I was using my friend’s (Nas_c) account until I got my own, which I will be using from now on. So I am replying to my own thread/topic.

Thanks Jake for your reply. However, I do notice that when I use the RichTextBox on it's own, it's alot faster than when I integrate in your GoDiagram API. It seems like the moment I use the RichTextBox in GoDiagram, slowliness increases exponentially. Why?
Here's a sample code of RichTextBox by itself without GoDiagram and it runs at fair speed. The previous code I posted (RichTextBox in GoDiagram) was alot slower. Why?
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { Font temp = richTextBox1.SelectionFont; Font hola = new Font(temp.FontFamily, temp.SizeInPoints + 2, temp.Style); richTextBox1.SelectionFont = hola; } private void button2_Click(object sender, EventArgs e) { richTextBox1.SelectionColor = Color.Green; } private void button1_Click(object sender, EventArgs e) { Font temp = richTextBox1.SelectionFont; Font hola = new Font(temp.FontFamily, temp.SizeInPoints, temp.Style | FontStyle.Bold); richTextBox1.SelectionFont = hola; } private void button4_Click(object sender, EventArgs e) { Font temp = richTextBox1.SelectionFont; Font hola = new Font(temp.FontFamily, temp.SizeInPoints, temp.Style | FontStyle.Italic); richTextBox1.SelectionFont = hola; } }
Please advice. How can I use RichTextBox in GoDiagram while maintaining acceptable/decent running speed?
Thanks
Sido

Bump.

Anybody has any idea?
Jake?
Thank you.

I’ll take a look, right now I have no idea.

When the control is in edit mode, it’s getting a ton of “Paint” calls… that’s why it’s slow. Now I just have to figure out how to fix it.

Hi Jake,

Thanks for your reply.
I read on Internet that you can actually send messages to disable re-painting, making it faster. Perhaps it is our solution, but I don't know how to integrate it with GoDiagram. Here is the sample code I got from Internet:
SOURCE:
http://geekswithblogs.net/pvidler/archive/2003/10/14/182.aspx
CODE:
///
/// Maintains performance while updating.
///
///
///
/// It is recommended to call this method before doing
/// any major updates that you do not wish the user to
/// see. Remember to call EndUpdate when you are finished
/// with the update. Nested calls are supported.
///
///
/// Calling this method will prevent redrawing. It will
/// also setup the event mask of the underlying richedit
/// control so that no events are sent.
///
///
public void BeginUpdate()
{
// Deal with nested calls.
++updating;

if ( updating > 1 )
return;

// Prevent the control from raising any events.
oldEventMask = SendMessage( new HandleRef( this, Handle ),
EM_SETEVENTMASK, 0, 0 );

// Prevent the control from redrawing itself.
SendMessage( new HandleRef( this, Handle ),
WM_SETREDRAW, 0, 0 );
}

///
/// Resumes drawing and event handling.
///
///
/// This method should be called every time a call is made
/// made to BeginUpdate. It resets the event mask to it's
/// original value and enables redrawing of the control.
///
public void EndUpdate()
{
// Deal with nested calls.
--updating;

if ( updating > 0 )
return;

// Allow the control to redraw itself.
SendMessage( new HandleRef( this, Handle ),
WM_SETREDRAW, 1, 0 );

// Allow the control to raise event messages.
SendMessage( new HandleRef( this, Handle ),
EM_SETEVENTMASK, 0, oldEventMask );
}
Can this help? I need to have something fast soon. Your help is appreciated. Thanks.

I found it. In GoControl.Paint, we are setting Visible=true on the control, which appears to force another Paint on a RichText control.

Thanks Jake.

From your description, it looks to me like a bug in your API. Unless we can change it ourselves, when can we expect a fix for this?
Thanks.
Sido

GoShape.DrawRectangle(g, view, GoShape.Pens_Black, GoShape.Brushes_LightGray, r.X, r.Y, r.Width, r.Height);

Two errors: "Pens_Black" and "Brushes_LightGray" are not recognizable.

Are they new elements in GoDiagram 4.0? Are they private fields?

I am currently still using GoDiagram 3.0.3.

Thanks.

Tried it with GoDiagram 4.0 and still not recognizable. Any way around this?

For those experiencing similar issue and/or would like to know the solution to the problem discussed in this topic/thread:
Jake said it is a bug in GoDiagram and that it will be fixed in release 4.1.
Sido