RTF widget and undo disabling (sometimes only)

R

Random Task

Hi,

I have successfully created a class derived from the RTF widget that can
syntax highlight XML as fast as you type :)

The only problem I have is that if the user does an 'undo' then syntax
highlighting is undone. Is it possible to disable the undo stack during
specific operations ?

Jim
 
N

Nicholas Paldino [.NET/C# MVP]

Jim,

You can override the WndProc method on your control and then handle the
EM_UNDO message (I believe you are using an RichTextBox). You can decide
whether to process this or not.

Hope this helps.
 
R

Random Task

Nicholas said:
Jim,

You can override the WndProc method on your control and then handle the
EM_UNDO message (I believe you are using an RichTextBox). You can decide
whether to process this or not.

Hope this helps.
I am a newbie to having to write code at this level ... I just tried the
below code and it looks like I can't overide this on the RickTextBox ...

Is there something else i should be trying?

And thanks very much ... everyone normally ignores this question

Jim

public class MyHighlightable: RichTextBox
{
public bool ishighlighting;
public MyHighlightable(): base()
{
}

/*
RichTextBoxSyntaxHighligher.cs(29):
'Zeligsoft.Helpers.MyHighlightable.WndProc(ref
Zeligsoft.Helpers.Message)': no suitable method found to
override
*/
protected override void WndProc(ref Message message)
{
switch (message.Msg)
{
case (int)Msgs.EM_UNDO:
{
if (ishighlighting)
{
return;
}
else
{
base.WndProc(ref message);
}
break;
}
default:
{
base.WndProc(ref message);
}
}
}

}
 
R

Random Task

Ooops ... some one created a "Message" class in namespace ...

My bad ...
Jim
 
R

Random Task

Nicholas said:
Jim,

You can override the WndProc method on your control and then handle the
EM_UNDO message (I believe you are using an RichTextBox). You can decide
whether to process this or not.

Hope this helps.

Thanks for the help ... unfortunately it still doesn't work ... it
appears there is no "disable undo queue" that i can call during the
period of time where i highlight the code in the RTF ... my boss
unfortunately wont let me simply disable undo in the editor :)

Maybe there are some other ideas ... but like I said your the first to
even offer a suggestion on this :)

Cheers,
Jim

ps here's the code i tried to catch events ...


/// <summary>
///
/// </summary>
public class MyHighlightableRTF: RichTextBox
{
public bool ishighlighting;

public MyHighlightableRTF(): base()
{

}

protected override void WndProc(ref System.Windows.Forms.Message message)
{
switch (message.Msg)
{
case (int) 0x0304://EM_UNDO:
{
if (ishighlighting)
{
return;
}
else
{
base.WndProc(ref message);
}
break;
}
case (int) 0x00C7:
{
if (ishighlighting)
{
return;
}
else
{
base.WndProc(ref message);
}
break;
};
case (int) 0x00C6: //EM_CANUNDO 0x00C6
{
if (ishighlighting)
{
return;
}
else
{
base.WndProc(ref message);
}
break;
}
case (int) 0x0114://WM_HSCROLL
{
if (ishighlighting)
{
return;
}
else
{
base.WndProc(ref message);
}
break;
}
case 0x0115: //(int)WM_VSCROLL
{
if (ishighlighting)
{
return;
}
else
{
base.WndProc(ref message);
}
break;
}
case 0x00CD: //EM_EMPTYUNDOBUFFER
{
if (ishighlighting)
{
return;
}
else
{
base.WndProc(ref message);
}
break;
}
default:
{
base.WndProc(ref message);
break;
}
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top