This commit is contained in:
@@ -794,6 +794,11 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
public static CharFormatTwo GetCharFormat(RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
/*
|
||||
* You can still call SendMessage, passing the EM_GETCHARFORMAT message.
|
||||
You just need to check the dwMask field to see which attributes are
|
||||
consistent throughout the selection.
|
||||
*/
|
||||
CharFormat2 cf = new CharFormat2();
|
||||
cf.cbSize = Marshal.SizeOf(cf);
|
||||
if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_GETCHARFORMAT, selection, ref cf) == 0)
|
||||
@@ -805,6 +810,14 @@ namespace Volian.Controls.Library
|
||||
try
|
||||
{
|
||||
CharFormat2 cf2 = cft.CharFormat2;
|
||||
try
|
||||
{
|
||||
HandleRef hr = new HandleRef(richTextBox, richTextBox.Handle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETCHARFORMAT, selection, ref cf2) == 0)
|
||||
throw new Win32Exception();
|
||||
}
|
||||
@@ -846,13 +859,15 @@ namespace Volian.Controls.Library
|
||||
public static bool IsSuperScript(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return ((cft.dwEffects & CharFormatEffects.CFE_SUPERSCRIPT) == CharFormatEffects.CFE_SUPERSCRIPT);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_SUPERSCRIPT) == CharFormatMasks.CFM_SUPERSCRIPT) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_SUPERSCRIPT) == CharFormatEffects.CFE_SUPERSCRIPT));
|
||||
}
|
||||
|
||||
public static bool IsSubScript(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return ((cft.dwEffects & CharFormatEffects.CFE_SUBSCRIPT) == CharFormatEffects.CFE_SUBSCRIPT);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_SUBSCRIPT) == CharFormatMasks.CFM_SUBSCRIPT) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_SUBSCRIPT) == CharFormatEffects.CFE_SUBSCRIPT));
|
||||
}
|
||||
public static void ToggleSubscript(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
@@ -885,7 +900,8 @@ namespace Volian.Controls.Library
|
||||
public static bool IsBold(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return ((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_BOLD) == CharFormatMasks.CFM_BOLD) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD));
|
||||
}
|
||||
public static void ToggleBold(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
@@ -904,7 +920,8 @@ namespace Volian.Controls.Library
|
||||
public static bool IsUnderline(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return ((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_UNDERLINE) == CharFormatMasks.CFM_UNDERLINE) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE));
|
||||
}
|
||||
public static void ToggleUnderline(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
@@ -923,7 +940,8 @@ namespace Volian.Controls.Library
|
||||
public static bool IsItalic(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return ((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_ITALIC) == CharFormatMasks.CFM_ITALIC) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC));
|
||||
}
|
||||
public static void ToggleItalic(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
|
Reference in New Issue
Block a user