使控件透明(WinForms应用程序) [英] Making a Control transparent (WinForms Application)
问题描述
嘿,
我本来是试图将背景图像添加到Richtextbox的,当时我很快发现它不能简单地实现.我一直在网上阅读,偶然发现有人说了一些有关创建新用户控件的方法,即添加一个富文本框,然后实现此代码以使其与文本框而不是标签配合使用:
Hey there,
I was originally trying to add a background image to a Richtextbox when I quickly found out it could not be simply achieved. I kept reading on online and stumbled upon someone who said something about creating a new usercontrol adding a richtextbox and then implementing this code to work with a textbox rather than a label:
public class TransparentLabel : Label {
public TransparentLabel() {
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
}
protected override CreateParams CreateParams {
get {
CreateParams parms = base.CreateParams;
parms.ExStyle |= 0x20; // Turn on WS_EX_TRANSPARENT
return parms;
}
}
}
所以我尝试了:
So I tried:
public class UserControl1 : RichTextbox
{
public UserControl1()
{
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
}
protected override CreateParams CreateParams
{
get
{
CreateParams parms = base.CreateParams;
parms.ExStyle |= 0x20;
return parms;
}
}
}
但是我最终遇到以下错误,并且不确定如何解决此问题:
错误1类型"Stickies.UserControl1"的声明中缺少部分修饰符;存在这种类型的另一个局部声明
此错误在以下行:
公共类UserControl1:RichTextbox
对于我的错误的任何帮助或对其他方法的任何帮助都将非常有用.
谢谢.
But I end up with the following error and I am unsure how to fix it:
Error 1 Missing partial modifier on declaration of type ''Stickies.UserControl1''; another partial declaration of this type exists
This error is on the following line:
public class UserControl1 : RichTextbox
Any help with my error or any help on another approach would be really helpful.
Thank you.
推荐答案
从错误消息中,我认为如果您故意在项目的所有部分中将另一个类文件声明为"partial class UserControl1",必须将UserControl1声明为"partial".
http://msdn.microsoft.com/en-us/library/wa80x488 (v = vs.80).aspx [
From the error message I would think you have another class file in your project declared as "partial class UserControl1" if this is intentional all parts of the UserControl1 must be declared as "partial".
http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx[^]
这篇关于使控件透明(WinForms应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!