richTextBoxBulletClass
设置和获取选中的样式为 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的更多相关文章
- C# richTextBox编辑器
附件:http://files.cnblogs.com/xe2011/CSHARP_RichTextBoxEditor.rar 完整的转到这里 http://www.cnblogs.com/xe201 ...
随机推荐
- 转载“用USBOOT制作DOS启动盘”
使用软件: Usboot和MaxDOS_5.6s_U盘版. 由于我的U盘容量比较小,暂时只能做DOS启动功能,其它功能如Windows PE,等我以后测试成功后再补充说明. U盘是啥? 读音优盘,可以 ...
- 【web安全】第一弹:利用xss注入获取cookie
首先一定要先来吐槽一下tipask系统.这是一枚开源的类似百度知道的系统,但是漏洞多多,最基本的XSS注入都无法防御. 言归正传: [准备1] cookie接收服务器. 平时喜欢用sae,所以在sae ...
- Js Carousel
http://getbootstrap.com/javascript/#carousel http://owlgraphic.com/owlcarousel/#demo https://www.mob ...
- VC菜菜鸟:建立第一个基于Visual C++的Windows窗口程序
建立第一个基于VisualC++的Windows窗口程序: 发表于:http://blog.csdn.net/it1988888/article/details/10306585 a)执行命令:新建 ...
- nginx提示No input file specified怎么办
用了网上提供的各种方法都不行,即便html能正常打开,php文件依然有问题.而后继续尝试了修改权限 chown -vR www:www /folder 功能都正常. nginx.conf 的 user ...
- 第 16 章 观察者模式【Observer Pattern】
以下内容出自:<<24种设计模式介绍与6大设计原则>> <孙子兵法>有云:“知彼知己,百战不殆:不知彼而知己,一胜一负:不知彼,不知己,每战必殆”,那怎么才能知己知 ...
- bzoj 3153: Sone1 Toptree
3153: Sone1 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 511 Solved: 202[Submit][Status][Discuss ...
- Mongodb与关系型数据库
MongoDB没有固定的关系约束 没有事务, 安全性不高 不一定保证数据的一致性. ACID不符合 NoSQL 放弃了传统关系型数据库严格的事务一致性和范式约束,采用弱一致性模型. http://os ...
- Linux 下报错:A Java RunTime Environment (JRE) or Java Development Kit (JDK) must解决方案
一.报错环境:在Linux mint下,前几天还用得很好的的eclipse,今天开机不知为什么这样. Linux 下报错:A Java RunTime Environment (JRE) or Jav ...
- Docker在云环境中的应用实践初探:优势、局限性与效能评测
作者 商之狄 发布于 2014年11月10日 本文依据笔者所在团队的一些近期开发和应用的实践,整理出一些有意义的信息,拿出来和社区分享.其中既包括在云端应用Docker与相关技术的讨论,同时也有实施过 ...