C#实现利用单选框实现更改文本的richTextBox字体、大小、加粗

功能

C#实现利用单选框实现更改文本的richTextBox字体、大小、加粗

程序

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 单选界面
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (jiazu.Checked)
                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style | FontStyle.Bold);
            else
                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Bold);

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            richTextBox1.Font = new Font("宋体", richTextBox1.Font.Size, richTextBox1.Font.Style);
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, 10, richTextBox1.Font.Style);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, 16, richTextBox1.Font.Style);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            richTextBox1.Font = new Font("楷体", richTextBox1.Font.Size, richTextBox1.Font.Style);
        }
    }
    
}

后续

如果想了解更多物联网、智能家居项目知识,可以关注我的程序设计专栏
或者关注公众号。
在这里插入图片描述

编写不易,感谢支持。

  • 2
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用PrintDocument类和PrintPreviewDialog类可以实现RichTextBox的打印和预览。 以下是示例代码: 打印: ```csharp private void printToolStripMenuItem_Click(object sender, EventArgs e) { PrintDocument doc = new PrintDocument(); doc.PrintPage += new PrintPageEventHandler(doc_PrintPage); PrintDialog dlg = new PrintDialog(); dlg.Document = doc; if (dlg.ShowDialog() == DialogResult.OK) { doc.Print(); } } private void doc_PrintPage(object sender, PrintPageEventArgs e) { Font font = richTextBox1.Font; Brush brush = new SolidBrush(richTextBox1.ForeColor); RectangleF rect = e.MarginBounds; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(richTextBox1.Text, font, brush, rect, sf); } ``` 预览: ```csharp private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e) { PrintDocument doc = new PrintDocument(); doc.PrintPage += new PrintPageEventHandler(doc_PrintPage); PrintPreviewDialog dlg = new PrintPreviewDialog(); dlg.Document = doc; dlg.ShowDialog(); } ``` 上述代码中,doc_PrintPage方法用于绘制RichTextBox的内容,包括字体、颜色、对齐方式等。在打印和预览中,只需创建PrintDocument和PrintPreviewDialog对象,然后将打印页面绘制事件与doc_PrintPage方法关联即可。在打印中,使用PrintDialog显示打印对话框,并调用Print方法进行打印。在预览中,直接显示PrintPreviewDialog即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

跋扈洋

编写不易,打赏支持一下我吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值