• 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);
            }
        }
    }
  • 相关阅读:
    bzoj4152-[AMPPZ2014]The_Captain
    bzoj3209-花神的数论题
    [模板] 数位dp
    [西安交大附中集训] 自积
    [模板] 后缀数组
    [模板] 哈希表
    [西安交大附中集训] d6 删边(cip)
    java 发布订阅
    Spring Boot使用@Async实现异步调用:自定义线程池
    上传文件到服务器或者直接输出到输出流
  • 原文地址:https://www.cnblogs.com/xe2011/p/3446119.html
Copyright © 2020-2023  润新知