重新背景我也试过了public override Image BackgroundImage { get { return Image.FromFile("8.gif"); } set { base.BackgroundImage = value; } }效果和上面那个重新画一样的
我这儿怎么没效果?不好意思,我是用VB。NET的,您帮我看看,谢谢!Public Class Form1 Inherits System.Windows.Forms.Form#Region " Windows 窗体设计器生成的代码 " Public Sub New() MyBase.New() '该调用是 Windows 窗体设计器所必需的。 InitializeComponent() '在 InitializeComponent() 调用之后添加任何初始化 End Sub '窗体重写 dispose 以清理组件列表。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Windows 窗体设计器所必需的 Private components As System.ComponentModel.IContainer '注意: 以下过程是 Windows 窗体设计器所必需的 '可以使用 Windows 窗体设计器修改此过程。 '不要使用代码编辑器修改它。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) Me.ClientSize = New System.Drawing.Size(456, 317) Me.Name = "Form1" Me.Text = "Form1" End Sub#End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim myrich1 As New myrich myrich1.Location = New System.Drawing.Point(16, 8) myrich1.Name = "RichTextBox1" myrich1.Size = New System.Drawing.Size(416, 240) myrich1.TabIndex = 0 myrich1.Text = "RichTextBox1" myrich1.BackgroundImage = Image.FromFile("ls.jpg") Me.Controls.Add(myrich1) End Sub End ClassPublic Class myrich Inherits System.Windows.Forms.RichTextBox Public Overrides Property BackgroundImage() As Image Get End Get Set(ByVal Value As Image) MyBase.BackgroundImage = Value End Set End Property End Class
我的RICHTEXTBOX是一片白色
————————————————————————
jinbingg(bing),我就是没法设背景图片啊,你能设?
我的RICHTEXTBOX是一片白色
……估计只能把窗体设为白色了^_^玩笑实在不行只能把RICHTEXTBOX的背景色设置成和窗体背景图接近的颜色看看效果
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public UserControl1()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent(); this.SetStyle(ControlStyles.UserPaint,true); // TODO: 在 InitComponent 调用后添加任何初始化 } protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e); Font myFont=new Font("Arial Black",20);
e.Graphics.DrawString("100M",myFont,System.Drawing.Brushes.Red,5,5); Font myFont2=new Font("Arial Black",15);
e.Graphics.DrawString(this.Text,myFont2,System.Drawing.Brushes.Black,5,5);
} }说明一下,首先继承RichTextBox
public class UserControl1 : System.Windows.Forms.RichTextBox
然后申明
this.SetStyle(ControlStyles.UserPaint,true);然后问题出来了,不管是用重写OnPaint还是OnPaintBackground,效果都一样,都只能看到背景,看不到文字,也就是说,文字被覆盖了
解决方法就是文字也自己画说明一下
Font myFont=new Font("Arial Black",20);
e.Graphics.DrawString("100M",myFont,System.Drawing.Brushes.Red,5,5);
这里是画背景的,我随便写了几个字做背景,你可以改成画图这里是写里面的字
Font myFont2=new Font("Arial Black",15); //取得richtextbox的属性,我懒得取了,随便写了一个
e.Graphics.DrawString(this.Text,myFont2,System.Drawing.Brushes.Black,5,5); //写字,起始坐标需要自己微调这样的效果基本上就是你要的了,但是要做的工作还不止如此,还需要手工去控制里面的文字换行,控制每行的起始位置……另外,选中文字的效果也需要自己画……还有我没考虑到的,反正比较麻烦不知道有没有把图画到文字下面的画法,我没找到
不然如果能取到文字所在象素的集合也行……
{
get
{
return Image.FromFile("8.gif");
}
set
{
base.BackgroundImage = value;
}
}效果和上面那个重新画一样的
Inherits System.Windows.Forms.Form#Region " Windows 窗体设计器生成的代码 " Public Sub New()
MyBase.New() '该调用是 Windows 窗体设计器所必需的。
InitializeComponent() '在 InitializeComponent() 调用之后添加任何初始化 End Sub '窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub 'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer '注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(456, 317)
Me.Name = "Form1"
Me.Text = "Form1" End Sub#End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myrich1 As New myrich
myrich1.Location = New System.Drawing.Point(16, 8)
myrich1.Name = "RichTextBox1"
myrich1.Size = New System.Drawing.Size(416, 240)
myrich1.TabIndex = 0
myrich1.Text = "RichTextBox1"
myrich1.BackgroundImage = Image.FromFile("ls.jpg")
Me.Controls.Add(myrich1)
End Sub
End ClassPublic Class myrich
Inherits System.Windows.Forms.RichTextBox
Public Overrides Property BackgroundImage() As Image
Get End Get
Set(ByVal Value As Image)
MyBase.BackgroundImage = Value
End Set
End Property
End Class