c#怎么设置richtextbox透明
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#怎么设置richtextbox透明相关的知识,希望对你有一定的参考价值。
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace LL
public class UserRichTextBox : UserControl
public UserRichTextBox()
//为用户控制启用双缓冲等控件样式,否则RichTextBox输入时,会有残影
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent();
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
this.alphaRichTextBox1 = new LL.AlphaRichTextBox();
this.SuspendLayout();
//
// alphaRichTextBox1
//
this.alphaRichTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.alphaRichTextBox1.Location = new System.Drawing.Point(0, 0);
this.alphaRichTextBox1.Name = "alphaRichTextBox1";
this.alphaRichTextBox1.Size = new System.Drawing.Size(150, 150);
this.alphaRichTextBox1.TabIndex = 0;
this.alphaRichTextBox1.Text = "";
//
// UserRichTextBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.alphaRichTextBox1);
this.Name = "UserRichTextBox";
this.ResumeLayout(false);
#endregion
public AlphaRichTextBox alphaRichTextBox1;
protected override void OnLoad(EventArgs e)
base.OnLoad(e);
//为测试效果,特加载背景图片
//this.BackgroundImageLayout = ImageLayout.None;
//this.BackgroundImage = Image.FromFile(@"E:\\Visual Studio 2010\\Projects\\LL\\LL\\Resources\\title.png");
public class AlphaRichTextBox : RichTextBox
//关键点:支持透明背景
protected override CreateParams CreateParams
get
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
richtextbox是不能设置透明的,我这有个重写过的透明richtextbox,供你参考 参考技术A .opacity = 0
c#怎么让richtextbox不可编辑?
如果只是把它的enabled属性设置为fasle的,颜色会变的,而且也设置背景颜色backcolor为白色也没用.....
请问怎样才能让richtextbox不可编辑?而且看起来和平常的richtextbox一样?
xxx.BackColor = System.Drawing.Color.White; 参考技术D 把readonly属性设为true 第5个回答 2019-05-01 很多人说直接将readonly属性设为true,这样的话richtextbox无法添加图片;
我这里介绍一个方法吧,叫做焦点转移,当richtextbox遇到鼠标点击事件,则将其焦点转移到其他控件上面,这样richtextbox就无法进行编辑了,代码如下:
'rtb_dhk富文本控件鼠标按下事件
Private Sub rtb_dhk_MouseDown(sender As Object, e As MouseEventArgs) Handles rtb_dhk.MouseDown
btn_send.Focus() '让btn_send控件得到焦点,这样就让rtb_dhk富文本控件失去焦点
End Sub
'rtb_dhk富文本控件鼠标点击事件
Private Sub rtb_dhk_MouseClick(sender As Object, e As MouseEventArgs) Handles rtb_dhk.MouseClick
btn_send.Focus() ' 让btn_send控件得到焦点,这样就让rtb_dhk富文本控件失去焦点
End Sub
以上是关于c#怎么设置richtextbox透明的主要内容,如果未能解决你的问题,请参考以下文章
C# winform中 怎么让RichTextBox支持透明。通过继承还是重绘了?最好有代码,菜鸟学习中。
C# WinForm怎么让richTextBox响应回车事件?