如何用C#写一个透明控件?(WinForm程序)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用C#写一个透明控件?(WinForm程序)相关的知识,希望对你有一定的参考价值。

我在一个panel里放了一个控件A,我还想在这个panel里放一个透明的控件B,然后B控件执行BringToFront方法后希望仍能看见它后面的A控件,请问如何做这个透明的B控件呢?谢谢!
BackColor我试过了,我让它等于transparent,但是达不到透明的效果,只是显示了父控件的背景色,所以大家帮帮忙!

参考技术A 首先先从System.Windows.Forms.Panel 继承一个自定义控件,然后在控件的构造函数中添加下面的代码 :
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;

其中调用SetStyle函数进行设置ControlStyles.SupportsTransparentBackColor为true

然后设置控件的背景颜色为透明Color.Transparent.

把设计好的控件添加到WINFORM中来,发现自定义控件可以在其他控件上面时可以变成透明,但是如果放在图片控件上面却没有透明效果,为了这个问题,研究了半天,后来终于发现只需要简单的设置一下控件的parent属性为图片控件即可.代码如下 :

Panel21.Parent = pictureBox1;本回答被提问者采纳
参考技术B CuteEditor 6.0 在线HTML编辑器的领航者
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=144183
ComponentArt.Charting.WebChart.dll
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=144386
ComponentArt.Web.UI 2007.2源代码+实例+DLL
http://bbs.topsage.com/dispbbs_123_161434_1.html
ComponentArt.WebUI.2007.1破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143055
ComponentArt.WebUI.2007.1源代码
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143224
ComponentArt.Web.UI.2006.2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143212
ComponentArt.Web.UI.2006.2源代码
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143219
ComponentArt.Web.UI.2006.1
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=142983
Infragistics NetAdvantage for ASP.NET 2007 Vol 2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159861
Infragistics NetAdvantage AppStylist 2007 Vol 2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159859
Infragistics TestAdvantage WinForms 2007 For CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159870
Infragistics TestAdvantage WinForms 2007 for CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159868
Infragistics NetAdvantage for Windows Forms 2007 Vol 2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159863
Infragistics NetAdvantage 2007 for WPF
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159857
Infragistics NetAdvantage 2006 Vol2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159814
Infragistics NetAdvantage 2006 Vol2 for CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159854
Infragistics NetAdvantage 2006 Vol2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159814
ComponentOne Studio 2007 v1.5 for ASP.NET 2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159753
ComponentOne Studio 2007 v1.5 for ASP.NET 1.x
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159745
ComponentOne Studio 2006 v2 for ASP.NET 2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159739
ComponentOne Studio 2006 v2 for ASP.NET 1.x
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159734
ComponentOne Studio for Mobile Devices 2007 v1.5 CLR1x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159812
ComponentOne Studio for Mobile Devices 2006 v2 CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159811
ComponentOne Studio for Mobile Devices 2006 v2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159807
ComponentOne Studio 2007 v1.5 for .NET CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159802
ComponentOne Studio 2007 v1.5 for .NET CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159798
ComponentOne Studio for .NET 2006 v2 CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159780
ComponentOne Studio for .NET 2006 v2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159777
ComponentOne Studio for ActiveX 2007 v1.5
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159727
ComponentOne Studio for ActiveX 2006 v2 CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159725
ComponentOne Studio for ActiveX 2006 v2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159724
Telerik RadWindow for ASP.NET 2.0 v1.8.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156136
Telerik RadUpload for ASP.NET 2.0 v2.3.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156135
Telerik RadTreeView for ASP.NET 2.0 v6.2.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156134
Telerik RadTabStrip for ASP.NET 2.0 v3.5.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156132
Telerik RadToolbar for ASP.NET 2.0 v1.5.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156133
Telerik RadSplitter for ASP.NET 2.0 v1.2.2.1
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156131
Telerik RadSpell for ASP.NET 2.0 v3.1.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156130
Telerik RadRotator for ASP.NET 2.0 v2.6.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156129
Telerik RadPanelbar for ASP.NET 2.0 v4.2.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156128
Telerik RadMenu for ASP.NET 2.0 v4.2.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156127
Telerik RadInput for ASP.NET 2.0 v2.0.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156126
Telerik RadGrid for ASP.NET 2.0 v4.6.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156125
Telerik RadEditor for ASP.NET 2.0 v7.1.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156124
Telerik RadComboBox for ASP.NET 2.0 v2.7.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156122
Telerik RadDock for ASP.NET 2.0 v1.8.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156123
Telerik RadChart for ASP.NET 2.0 v3.2.1.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156121
Telerik RadCalendar for ASP.NET 2.0 v2.1.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156120
Telerik RadAjax for ASP.NET 2.0 v1.7.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156119
telerik r.a.d.upload
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143044
telerik r.a.d.window
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=142980
telerik r.a.d ToolBar
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143077
telerik r.a.d.Chart
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143075
telerik r.a.d.combobox
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143048
DotNetBar for VS2005 6.8.0.1
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=144521
DotnetCharting 4.3破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=144388
DotNET Charting WebForms
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=144461
dotnetCharting.WinForms
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=144455
TeeChart for .NET 3.2.2763.26084 完美DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165932
TeeChart for .NET 3.2.2699.17379 完美DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165929
Godiagram Web 2.6.2 for .NET 2.0
http://bbs.topsage.com/dispbbs_123_177906_1.html
Godiagram Win 2.6.2 for .NET 2.0
http://bbs.topsage.com/dispbbs_121_177907_1.html
DevExpress 7.3.4 完美破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165852
Dxperience 7.3.5 完美破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165851
DevExpress.LocalizationCHS.Dll
http://bbs.topsage.com/dispbbs_121_169983_1.html
NickLee.Web.UI
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143052
SolpartWebControls
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=142981
AspNetPager 6.0 for ASP.NET 1.x 自定义分页控件
http://bbs.topsage.com/dispbbs_123_161692_1.html
AspNetPager 6.0 for ASP.NET 2.0 自定义分页控件
http://bbs.topsage.com/dispbbs_123_161696_1.html
数据操作类 Socut.Data.dll for .NET 2.0 v3.1
http://bbs.topsage.com/dispbbs_123_161867_1.html
数据操作类 Socut.Data.dll for .NET 1.x v3.1
http://bbs.topsage.com/dispbbs_123_161866_1.html
Developer Express for .NET v7.3.5.0全套完美无限制版
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=166512

如何用C#编写文本编辑器

这个问题比较大,其实看你写什么样的文本编辑器。
做法:
1.
简单记事本:用winform
或者
wpf
放一个
textbox
控件,实现一下多行,放置几个菜单,添加上保存等功能就可以了。
2.
富文本编辑器,用 richtextbox
控件,实现编辑、剪贴、撤销等操作。
3.
特定的编辑器,比如说实现一个
markdown
编辑器,你就需要对特定描述语言的解析了。
参考技术A 这个问题比较大,其实看你写什么样的文本编辑器。
做法:
简单记事本:用WinForm
或者
WPF
放一个
TextBox
控件,实现一下多行,放置几个菜单,添加上保存等功能就可以了。
富文本编辑器,用
RichTextBox
控件,实现编辑、剪贴、撤销等操作。
特定的编辑器,比如说实现一个
MarkDown
编辑器,你就需要对特定描述语言的解析了。

以上是关于如何用C#写一个透明控件?(WinForm程序)的主要内容,如果未能解决你的问题,请参考以下文章

C#中winform窗体,如何用代码设置字体的样式(如粗体、斜体)?

对VS中的winform窗体,如何用代码实现子控件在父控件中的相对位置的设置?请问C#语言实现

如何用C#的winform程序对Excel表格进行增删修查

如何用C#的winform程序对Excel表格进行增删修查

c# winform程序怎么寻找焦点在哪个控件上?

如何用C#编写文本编辑器