private void ToggleSelectionFormat(FontStyle fs) { if ((m_uBlockEvents > 0) || (m_bdc != BinaryDataClass.RichText)) { return; } try { Font f = m_rtbText.SelectionFont; if (f != null) { m_rtbText.SelectionFont = new Font(f, f.Style ^ fs); } else { NativeMethods.CHARFORMAT2 cf = UIUtil.RtfGetCharFormat(m_rtbText); cf.dwMask = 0; if ((fs & FontStyle.Bold) != FontStyle.Regular) { cf.dwMask |= NativeMethods.CFM_BOLD; cf.dwEffects ^= NativeMethods.CFE_BOLD; } if ((fs & FontStyle.Italic) != FontStyle.Regular) { cf.dwMask |= NativeMethods.CFM_ITALIC; cf.dwEffects ^= NativeMethods.CFE_ITALIC; } if ((fs & FontStyle.Underline) != FontStyle.Regular) { cf.dwMask |= NativeMethods.CFM_UNDERLINE; cf.dwEffects ^= NativeMethods.CFE_UNDERLINE; } if ((fs & FontStyle.Strikeout) != FontStyle.Regular) { cf.dwMask |= NativeMethods.CFM_STRIKEOUT; cf.dwEffects ^= NativeMethods.CFE_STRIKEOUT; } UIUtil.RtfSetCharFormat(m_rtbText, cf); } } catch (Exception ex) { MessageService.ShowWarning(ex); } UpdateUIState(true, true); }
public static void RtfSetSelectionLink(RichTextBox richTextBox) { try { NativeMethods.CHARFORMAT2 cf = new NativeMethods.CHARFORMAT2(); cf.cbSize = (UInt32)Marshal.SizeOf(cf); cf.dwMask = NativeMethods.CFM_LINK; cf.dwEffects = NativeMethods.CFE_LINK; IntPtr wParam = (IntPtr)NativeMethods.SCF_SELECTION; IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); Marshal.StructureToPtr(cf, lParam, false); NativeMethods.SendMessage(richTextBox.Handle, NativeMethods.EM_SETCHARFORMAT, wParam, lParam); Marshal.FreeCoTaskMem(lParam); } catch (Exception) { Debug.Assert(false); } }