Hi there,
I'm having trouble deleting hyperlinks. To prevent users from changing the hyperlink text, i protect the text. If i delete the hyperlink, one protected character (a space) is left behind and i cannot seem to get rid of it.
Here's my code (sample only, no checks are performed, etc):
Editor options:
wpdllInt1.Memo.SetBProp( BPropSel.wpVarBOptions, 7, BPropVal.on); //One-click hyperlinks
wpdllInt1.Memo.SetBProp( BPropSel.wpEditOptions, 23, BPropVal.on); //Auto detect www
wpdllInt1.Memo.SetIProp( (int)MemoIProp.HyperlinkCursor, (int)MemoCursor.HandPoint ); //Handpoint cursor for hyperlinks
wpdllInt1.Memo.SetBProp(BPropSel.wpProtectProp, 4, BPropVal.on); //Protect protected text
To insert a hyperlink i use the following code:
//Make sure there is a space between the hyperlink and the existing text
char currentChar = (char)wpdllInt1.Memo.CurrPar.GetChar( wpdllInt1.Memo.TextCursor.CPPosition-1 );
if( currentChar != 0 && currentChar != ' ' )
wpdllInt1.TextCursor.InputText(" ");
wpdllInt1.Memo.CurrAttr.SetStyles(8192); //Protect the link
wpdllInt1.TextCursor.InputHyperlink("HyperlinkCommand", "Hyperlink", false);
wpdllInt1.Memo.CurrAttr.ExcludeStyles(8192); //Text after link should be unprotected
wpdllInt1.TextCursor.InputText(" ");
Whenever the user clicks on the link, a popup menu appears, selecting the link and showing a 'Delete Link' option.
private void wpdllInt1_OnHyperlink(object Sender, int Editor, string URL, IWPTextObj TextObj)
{
TextObj.Select(2);
popupMenu1.ShowPopup(MousePosition);
}
To delete the link, i'm using the code:
wpdllInt1.Memo.TextCursor.DisableProtection();
wpdllInt1.Memo.TextCursor.InputText("\b"); //Since hyperlink was selected in _OnHyperlink event, i simply input a Backspace character.
wpdllInt1.Memo.TextCursor.EnabledProtection();
I've tried to use wpdllInt1.Memo.TextCursor.InputText("\b"); multiple times but this does not work.
note: Whenever i leave the protection disabled (ie not using EnabledProtection) i can manually type BS, BS to delete the hidden protected char.
Thanks,
Richard