设置和获取选中的样式为 1. 2. 3.

        #region  数字序列 1. 2. 3. 4. 5.  ...
private bool bOrder = false;
public bool SelectionOrderList
{
get
{
return (
(GetSelectionParaformat2wNumbering() == Paraformat2Numbering.ArabicNumbers) &&
(GetSelectionParaformat2wNumberingStyle() == Paraformat2NumberingStyle.Period)
); }
set
{
bOrder = value; if (value == true)
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.ArabicNumbers);
else
RemoveSelectionParaFormat2();
}
}
#endregion

更多样式

            //●●●●
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.Normal);
//1 2 3 4 5 ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.ArabicNumbers);
//1. 2. 3. 4. 5. ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.ArabicNumbers);
//1) 2) 3) 4) ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.ArabicNumbers);
//(1) (2) (3) (4) ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.ArabicNumbers);
////////////////////////////////////////////////////////////////////////// //a b c d e
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.LowerCaseLetter);
//a. b. c. d. e.
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.LowerCaseLetter);
//a) b) c) d) e)
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.LowerCaseLetter);
//(a) (b) (c) (d) (e)
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.LowerCaseLetter);
////////////////////////////////////////////////////////////////////////// //A B C D E
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.UpperCaseLetter);
//A. B. C. D. E.
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.UpperCaseLetter);
//A) B) C) D) E)
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.UpperCaseLetter);
//(A) (B) (C) (D) (E)
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.UpperCaseLetter);
////////////////////////////////////////////////////////////////////////// //I II III IIII IV
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.LowerCaseRoman);
//I. II. III. IIII. IV.
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.LowerCaseRoman);
//I) II) III) IIII) IV)
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.LowerCaseRoman);
//(I) (II) (III) (IIII) (IV)
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.LowerCaseRoman);
//////////////////////////////////////////////////////////////////////////

完整的类

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; //2013-11-27 02:00:13
////清除样式
//richTextBoxBulletClass r = new richTextBoxBulletClass();
//r.richTextBox = richTextBox1;
//r.RemoveSelectionParaFormat2(); ////属性获得 //richTextBoxBulletClass r = new richTextBoxBulletClass();
//r.richTextBox = richTextBox1;
//btn.Checked = r.SelectionOrderList; ////设置样式
//richTextBoxBulletClass r = new richTextBoxBulletClass();
//r.richTextBox = richTextBox1;
//r.SelectionOrderList = !r.SelectionOrderList; namespace WindowsForms
{
class richTextBoxBulletClass
{
public RichTextBox richTextBox;
public richTextBoxBulletClass()
{
richTextBox = new RichTextBox();
} #region PARAFORMAT2
[StructLayout(LayoutKind.Sequential)]
private class PARAFORMAT2
{
public int cbSize;
public int dwMask;
public short wNumbering;
public short wReserved;
public int dxStartIndent;
public int dxRightIndent;
public int dxOffset;
public short wAlignment;
public short cTabCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x20)]
public int[] rgxTabs; public int dySpaceBefore; // Vertical spacing before para
public int dySpaceAfter; // Vertical spacing after para
public int dyLineSpacing; // Line spacing depending on Rule
public short sStyle; // Style handle
public byte bLineSpacingRule; // Rule for line spacing (see tom.doc)
public byte bOutlineLevel; // Outline Level
public short wShadingWeight; // Shading in hundredths of a per cent
public short wShadingStyle; // Byte 0: style, nib 2: cfpat, 3: cbpat
public short wNumberingStart; // Starting value for numbering
public short wNumberingStyle; // Alignment, Roman/Arabic, (), ), ., etc.
public short wNumberingTab; // Space bet 1st indent and 1st-line text
public short wBorderSpace; // Border-text spaces (nbl/bdr in pts)
public short wBorderWidth; // Pen widths (nbl/bdr in half twips)
public short wBorders; // Border styles (nibble/border) public PARAFORMAT2()
{
this.cbSize = Marshal.SizeOf(typeof(PARAFORMAT2));
}
}
#endregion #region PARAFORMAT MASK VALUES public const uint WM_USER = 0x0400;
// RichEdit messages
public const uint EM_GETPARAFORMAT = (WM_USER + );
public const uint EM_SETPARAFORMAT = (WM_USER + ); // PARAFORMAT mask values
public const uint PFM_OFFSET = 0x00000004;
public const uint PFM_NUMBERING = 0x00000020; // PARAFORMAT 2.0 masks and effects
public const uint PFM_NUMBERINGSTYLE = 0x00002000;//设置项目编号的样式
public const uint PFM_NUMBERINGTAB = 0x00004000;//设置项目编号按下Tab键的信息
public const uint PFM_NUMBERINGSTART = 0x00008000;//设置项目编号的开始标识 //wNumbering
//Options used for bulleted or numbered paragraphs.
//To use this member, set the PFM_NUMBERING flag in the dwMask member.
//This member can be one of the following values.
public enum Paraformat2Numbering
{
zero = ,
Normal = , //No paragraph numbering or bullets.
ArabicNumbers = , //Uses Arabic numbers (1, 2, 3, ...).
LowerCaseLetter = , //Uses lowercase letters (a, b, c, ...).
UpperCaseLetter = , //Uses uppercase letters (A, B, C, ...).
LowerCaseRoman = , //Uses lowercase Roman numerals (i, ii, iii, ...).
UpperCaseRoman = //Uses uppercase Roman numerals (I, II, III, ...).
} //wNumberingStyle
//Numbering style used with numbered paragraphs.
//Use this member in conjunction with the wNumbering member.
//This member is included only for compatibility with TOM interfaces;
//the rich edit control stores the value but rich edit versions earlier than 3.0 do not use it to display the text or bullets.
//To use this member, set the PFM_NUMBERINGSTYLE flag in the dwMask member.
//This member can be one of the following values.
public enum Paraformat2NumberingStyle
{
RightParenthesis = 0x000,//Follows the number with a right parenthesis.
DoubleParenthesis = 0x100,//Encloses the number in parentheses.
Period = 0x200,//Follows the number with a period.
Plain = 0x300,//Displays only the number.
zero = 0x400//Continues a numbered list without applying the next number or bullet.
} #endregion #region SetSelectionParaFormat2 [DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, uint wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] PARAFORMAT2 lParam); public void SetSelectionParaFormat2(Paraformat2NumberingStyle style, Paraformat2Numbering Number)
{
PARAFORMAT2 p = new PARAFORMAT2();
p.dwMask = (int)(PFM_NUMBERING | PFM_OFFSET | PFM_NUMBERINGSTART | PFM_NUMBERINGSTYLE | PFM_NUMBERINGTAB); p.wNumbering = (short)Number;
//p.dxOffset = BulletIndent;
p.wNumberingStyle = (short)style;
p.wNumberingStart = ;
p.wNumberingTab = ; SendMessage(richTextBox.Handle, EM_SETPARAFORMAT, , p);
}
#endregion //获得 wNumbering的返回值
public Paraformat2Numbering GetSelectionParaformat2wNumbering()
{
PARAFORMAT2 p = new PARAFORMAT2();
SendMessage(richTextBox.Handle, EM_GETPARAFORMAT, , p);
return (Paraformat2Numbering)p.wNumbering;
} //获得wNumberingStyleg的返回值
public Paraformat2NumberingStyle GetSelectionParaformat2wNumberingStyle()
{
PARAFORMAT2 p = new PARAFORMAT2();
SendMessage(richTextBox.Handle, EM_GETPARAFORMAT, , p);
return (Paraformat2NumberingStyle)p.wNumberingStyle;
} #region 更多样式... ... private void test()
{
//●●●●
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.Normal);
//1 2 3 4 5 ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.ArabicNumbers);
//1. 2. 3. 4. 5. ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.ArabicNumbers);
//1) 2) 3) 4) ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.ArabicNumbers);
//(1) (2) (3) (4) ...
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.ArabicNumbers);
////////////////////////////////////////////////////////////////////////// //a b c d e
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.LowerCaseLetter);
//a. b. c. d. e.
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.LowerCaseLetter);
//a) b) c) d) e)
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.LowerCaseLetter);
//(a) (b) (c) (d) (e)
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.LowerCaseLetter);
////////////////////////////////////////////////////////////////////////// //A B C D E
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.UpperCaseLetter);
//A. B. C. D. E.
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.UpperCaseLetter);
//A) B) C) D) E)
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.UpperCaseLetter);
//(A) (B) (C) (D) (E)
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.UpperCaseLetter);
////////////////////////////////////////////////////////////////////////// //I II III IIII IV
SetSelectionParaFormat2(Paraformat2NumberingStyle.Plain, Paraformat2Numbering.LowerCaseRoman);
//I. II. III. IIII. IV.
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.LowerCaseRoman);
//I) II) III) IIII) IV)
SetSelectionParaFormat2(Paraformat2NumberingStyle.RightParenthesis, Paraformat2Numbering.LowerCaseRoman);
//(I) (II) (III) (IIII) (IV)
SetSelectionParaFormat2(Paraformat2NumberingStyle.DoubleParenthesis, Paraformat2Numbering.LowerCaseRoman);
////////////////////////////////////////////////////////////////////////// }
#endregion //清除选中的样式
public void RemoveSelectionParaFormat2()
{
SetSelectionParaFormat2(, );
} #region 数字序列 1. 2. 3. 4. 5. ...
private bool bOrder = false;
public bool SelectionOrderList
{
get
{
return (
(GetSelectionParaformat2wNumbering() == Paraformat2Numbering.ArabicNumbers) &&
(GetSelectionParaformat2wNumberingStyle() == Paraformat2NumberingStyle.Period)
); }
set
{
bOrder = value; if (value == true)
SetSelectionParaFormat2(Paraformat2NumberingStyle.Period, Paraformat2Numbering.ArabicNumbers);
else
RemoveSelectionParaFormat2();
}
}
#endregion }
}

richTextBoxBulletClass.CS

使用

//清除样式
richTextBoxBulletClass r = new richTextBoxBulletClass();
r.richTextBox = richTextBox1;
r.RemoveSelectionParaFormat2(); //属性获得 richTextBoxBulletClass r = new richTextBoxBulletClass();
r.richTextBox = richTextBox1;
btn.Checked = r.SelectionOrderList; //设置样式
richTextBoxBulletClass r = new richTextBoxBulletClass();
r.richTextBox = richTextBox1;
r.SelectionOrderList = !r.SelectionOrderList;

richTextBoxBulletClass的更多相关文章

  1. C# richTextBox编辑器

    附件:http://files.cnblogs.com/xe2011/CSHARP_RichTextBoxEditor.rar 完整的转到这里 http://www.cnblogs.com/xe201 ...

随机推荐

  1. u-boot Makefile整体解析

    一.概述   1.理解u-boot的makefile需要的准备 linux常用命令.shell脚本基础知识.makefile脚本基础知识 2.Makefile的元素 万变不离其宗,无论工程多么复杂,文 ...

  2. URL参数加密解密

    /// <summary>        /// DES加密字符串        /// </summary>        /// <param name=" ...

  3. 【转】.Net程序员玩转Android系列之三~快速上手

    原文:http://www.cnblogs.com/HouZhiHouJueBlogs/p/3962122.html 快速环境搭建和Hello World 第一步:JAVA SDK(JDK)的安装: ...

  4. 【GDOI 2011 DAY2 T3】零什么的最讨厌了 (快速求阶乘、中国剩余定理)

    问题描述: 林记在做数学习题的时候,经常遇到这种情况:苦思冥想了很久终于把问题解出来,结果发现答案是0,久而久之林记在得到习题答案是0的时候就没有了做出一道难题的成就感.于是林记决定:以后出题,答案一 ...

  5. SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-004-消除BEAN自动装配的歧义@QUALIFIER及自定义注解

    一. The @Qualifier annotation is the main way to work with qualifiers. It can beapplied alongside @Au ...

  6. android使用tabhost实现导航

    参考 http://blog.csdn.net/xixinyan/article/details/6771341 http://blog.sina.com.cn/s/blog_6b04c8eb0101 ...

  7. WordPress Quick Paypal Payments插件HTML注入漏洞

    漏洞名称: WordPress Quick Paypal Payments插件HTML注入漏洞 CNNVD编号: CNNVD-201310-491 发布时间: 2013-10-22 更新时间: 201 ...

  8. JAVA 数组常用技巧

    1.  在Java中输出一个数组(Print an array in Java) int[] intArray = { 1, 2, 3, 4, 5 }; String intArrayString = ...

  9. 模式串匹配KMP详解

    关于KMP模式串匹配网上蛮多的. 对于KMP有自己理解所以写下来希望能够对你们的学习有帮助. 之前暑假的时候学过,然后好长时间没用发现又忘了,现在再看看发现有了新的理解. ============== ...

  10. 获得WCF Client端的本地端口 z

    当WCF调用远程服务时,显示该调用的网速或流量.其中比较关键的一步就是需要获得WCF  Client端的本地端口,原来以为是个简单的事情,结果查了1个多小时谷歌,硬是没找到好的法子,只有自己动手了. ...