I am creating a usercontrol derived from Richtextbox.
The world is [beautiful]
I want to do the following operations on it
1) When the user keys in the ] , I need to create a link.
I have written the following code for this.
a) Select the text , Select (4,7) b) Set the mask and its effect
private void SetSelectionStyle(UInt32 mask, UInt32 effect)
{
ColorConverter Colour = new ColorConverter();
CHARFORMAT2_STRUCT cf = new CHARFORMAT2_STRUCT();
cf.cbSize = (UInt32)Marshal.SizeOf(cf);
cf.dwMask = CFM_LINK ; // mask
cf.dwEffects = effect;
cf.crTextColor = ColorTranslator.ToWin32(Color.Red);
IntPtr wpar = new IntPtr(SCF_SELECTION);
IntPtr lpar = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf));
Marshal.StructureToPtr(cf, lpar, false);
IntPtr res = SendMessage(Handle, EM_SETCHARFORMAT, wpar, lpar);
Marshal.FreeCoTaskMem(lpar);
}
With this code I have 2 problems
1) The selection stays even after the link has been created. 2) When I move the cursor, the link goes away
2) If the word beautiful is a) not in my dictionary - change the link colour to red b) in the dictionary change it to green
The CFM_LINK and CFM_COLOR is not working together .
Can somone help me in where am I going wrong
Thanks, Sujay