设置和获取选中的样式为 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;

最新文章

  1. RUDP之二 —— Sending and Receiving Packets
  2. PHP基础 创建
  3. Linux下htop的使用
  4. SAP中的Currency Converting Factor
  5. C#+OpenGL编程之再见小桃子(The Tao Framework)
  6. 《JS高程》JS-Object对象整理
  7. BestCoder Round #85 hdu5778 abs(素数筛+暴力)
  8. windbg配置问题汇总
  9. C#中的泛型详解
  10. STM32中断优先级理解
  11. 【原】Java学习笔记031 - 常用类
  12. 从git仓库导入idea的gradle项目无法添加依赖包问题
  13. 20175221 MyCP(课下作业,必做)
  14. 【Gradle】-NO.101.Gradle.1.gradle.1.001-【Gradle Configuration】-(
  15. Idea默认的全局设置,如Maven等
  16. 设计模式 笔记 工厂方法 Factory Methon
  17. 8 -- 深入使用Spring -- 2... Spring的“零配置”支持
  18. eclipse菜单栏工具
  19. sqlite3.exe 使用
  20. C#中的托管与非托管

热门文章

  1. asp.net mvc4 Controller与Action执行过程的研究(学习笔记)
  2. bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分
  3. Torch vs Theano
  4. 制作qtopia-2.2.0和qt4文件系统
  5. Java 8 的 JVM 有多快?Fork-Join 性能基准测试
  6. Android 常用权限
  7. Java+JQuery实现网页显示本地文件目录(含源码)
  8. MySQL 备份表和数据
  9. Makefile第二讲:打印出内容和使用变量
  10. SQL SERVER 的 INFORMATION_SCHEMA 的使用