[Gtk-sharp-list] RichTextBox.TextChanged (event) equivalent in GTk.?

Michael Hutchinson m.j.hutchinson at gmail.com
Thu Sep 25 13:02:01 EDT 2008


On Thu, Sep 25, 2008 at 12:50 PM, True Friend <true.friend2004 at gmail.com> wrote:
>
> Ok I have added it to the MainWindow's constructor as follows.
>
> this.textview1.Buffer.Changed += new EventHandler(OnTextBufferChanged);
>
> The evnt handler is as follows.
> -----------------------------------------------
> protected virtual void OnTextBufferChanged(object o, System.EventArgs e)
>     {
>         string temp = this.textview1.Buffer.Text;
>            string temp1 = Regex.Replace(temp, "[\x0011\x0012\u0060]", "\'");
>            string temp2 = Regex.Replace(temp1, "[\x0013\x0014]", "\"");
>            string temp3 = Regex.Replace(temp2, "[+\x0017\x0005\x0015]", "");
>            string temp4 = Regex.Replace(temp3, "\x0016", "-");
>         this.textview1.Buffer.Text = temp4;
>     }

When you set the text, you fire a Changed event, which sets the text... etc

Add a flag that you can use to break the loop:

bool changingText = false;

protected virtual void OnTextBufferChanged(object o, System.EventArgs e)
{
    if (changingText)
        return;

    //do stuff

    changingText = true;
    this.textview1.Buffer.Text = temp4;
    changingText = false;
}

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Gtk-sharp-list mailing list