111,094
社区成员




int start = 0;
int end = 0;
public testForm()
{
InitializeComponent();
richTextBox1.TextChanged +=new EventHandler(richTextBox1_TextChanged);
richTextBox1.SelectionChanged += new EventHandler(richTextBox1_SelectionChanged);
}
void richTextBox1_SelectionChanged(object sender, EventArgs e)
{
start = end;
end = richTextBox1.SelectionStart;
}
void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (end > start)
{
richTextBox1.Select(start, end - start);
}
richTextBox1.SelectionFont = new Font("宋体", 12);
richTextBox1.Select(start, 0);
}
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// richTextBox1
this.richTextBox1.Font = new Font("隶书", 13, System.Drawing.FontStyle.Regular)
}
[StructLayout(LayoutKind.Sequential), ComVisible(true)]
public struct HandleRef
{
internal object m_wrapper;
internal IntPtr m_handle;
public HandleRef(object wrapper, IntPtr handle)
{
this.m_wrapper = wrapper;
this.m_handle = handle;
}
public object Wrapper
{
get
{
return this.m_wrapper;
}
}
public IntPtr Handle
{
get
{
return this.m_handle;
}
}
public static explicit operator IntPtr(HandleRef value)
{
return value.m_handle;
}
public static IntPtr ToIntPtr(HandleRef value)
{
return value.m_handle;
}
}
[StructLayout(LayoutKind.Sequential, Pack=4)]
public class CHARFORMATA
{
public int cbSize = Marshal.SizeOf(typeof(CHARFORMATA));
public int dwMask;
public int dwEffects;
public int yHeight;
public int yOffset;
public int crTextColor;
public byte bCharSet;
public byte bPitchAndFamily;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=0x20)]
public byte[] szFaceName = new byte[0x20];
}
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] CHARFORMATA lParam);