设置和获取选中的样式为 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. 支付宝Demo 报错

    支付宝SDK-------DEMO第一次编译肯定是会报错的: 修正的方法为:   打开项目属性->Build Settings 找到 Library SearchPaths   看见里面的参数了 ...

  2. 将UIImage保存到iOS照片库和对应程序沙盒中-b

    1.保存到iOS照片库需要引入QuartzCore.framework框架,具体代码如下:.h文件#import <QuartzCore/QuartzCore.h>UIImageView ...

  3. 集合工具类 - CollectionUtil.java

    集合工具类,提供数组转LIST.数组转SET.合并集合.计算笛卡儿积等方法. 源码如下:(点击下载 -  CollectionUtil.java.ArrayUtil.java.commons-lang ...

  4. UML 类图的关系

    1.  关联关系 1.1 单向关联 . public class ClassA { private ClassB bVar; } public class ClassB { //... } 1.2  ...

  5. BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛

    Description 混乱的奶牛 [Don Piele, 2007] Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 <= S ...

  6. Android开源项目发现---ImageView 篇(持续更新)

    1. PhotoView 支持双击或双指缩放的ImageView 在ViewPager等Scrolling view中正常使用,相比上面的AndroidTouchGallery,不仅支持ViewPag ...

  7. python 替换windows换行符为unix格式

    windows 默认换行符为 \r\n; unix默认换行符为 \n; 所以当win下编辑的脚本在linux下显示末尾多了^M: 换行符修改为同一的unix格式脚本如下: def run(path,f ...

  8. vi的撤销命令

    'u' : 撤销上一个编辑操作 'ctrl + r' : 恢复,即回退前一个命令 'U' : 行撤销,撤销所有在前一个编辑行上的操作 使用u 和 CTRL+R 命令可以恢复到任何编辑过的状态

  9. C++11内存模型的一些补充阅读材料

    <Intel Threading Building Block> O'REILLY Chapter 7 Mutual Exclusion - Atomic Operation - Memo ...

  10. The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

    The server is temporarily unable to service your request due to maintenance downtime or capacity pro ...