zoukankan      html  css  js  c++  java
  • richTextBoxFontClass

    使用

    private void button1_Click(object sender, EventArgs e)
    {
        RichTextBoxCtrl.richTextBoxFontClass r = new RichTextBoxCtrl.richTextBoxFontClass();
        r.richTextBox = richTextBox1;
        r.ToggleBold();
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    
    ////使用
    //RichTextBoxCtrl.richTextBoxFontClass r = new RichTextBoxCtrl.richTextBoxFontClass();
    //r.richTextBox = richTextBox1;
    //r.ToggleBold();
    
    namespace RichTextBoxCtrl
    {
        class richTextBoxFontClass
        {
           
            public richTextBoxFontClass()
            {
                richTextBox = new RichTextBox();
            }
            public RichTextBox richTextBox;
    
            //粗体
            public void ToggleBold()
            {
                if (richTextBox.SelectionFont == null)
                    richTextBox.SelectionFont = richTextBox.Font;
    
                FontStyle style = richTextBox.SelectionFont.Style;
    
                if (richTextBox.SelectionFont.Bold)
    
                    style &= ~FontStyle.Bold;//恢复正常
                else
                    style |= FontStyle.Bold;
    
                richTextBox.SelectionFont = new Font(richTextBox.SelectionFont, style);
            }
    
            //斜体
            public void ToggleItalic()
            {
                if (richTextBox.SelectionFont == null)
                    richTextBox.SelectionFont = richTextBox.Font;
    
                FontStyle style = richTextBox.SelectionFont.Style;
    
                if (richTextBox.SelectionFont.Italic)
                    style &= ~FontStyle.Italic;//恢复正常
                else
                    style |= FontStyle.Italic;
    
                richTextBox.SelectionFont = new Font(richTextBox.SelectionFont, style);
            }
    
            //下划线
            public void ToggleUnderLine()
            {
                if (richTextBox.SelectionFont == null)
                    richTextBox.SelectionFont = richTextBox.Font;
    
                FontStyle style = richTextBox.SelectionFont.Style;
    
                if (richTextBox.SelectionFont.Underline)
                    style &= ~FontStyle.Underline;//恢复正常
                else
                    style |= FontStyle.Underline;
    
                richTextBox.SelectionFont = new Font(richTextBox.SelectionFont, style);
            }
    
            //删除线
            public void ToggleStrikeout()
            {
                if (richTextBox.SelectionFont == null)
                    richTextBox.SelectionFont = richTextBox.Font;
    
                FontStyle style = richTextBox.SelectionFont.Style;
    
                if (richTextBox.SelectionFont.Strikeout)
                    style &= ~FontStyle.Strikeout;//恢复正常
                else
                    style |= FontStyle.Strikeout;
                richTextBox.SelectionFont = new Font(richTextBox.SelectionFont, style);
            }
        }
    }
  • 相关阅读:
    使用FastJson parseObject方法时,json字符串解析成对象后,部分属性丢失问题处理
    IDEA启动Tomcat时 , 报错提示:this web application instance has been stopped already
    Servlet基本概念记录(随笔...不完全...)
    有关MacBook的简单操作收集
    Elasticsearch 相关资料收集
    redis入门
    整理最近面试遇到的一些问题
    java中的一些概念整理
    windows相关操作
    java基础知识优秀博客整理
  • 原文地址:https://www.cnblogs.com/xe2011/p/3446119.html
Copyright © 2011-2022 走看看