c# 可以设置透明度的 Panel 组件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms; namespace TransparentPanelTest
{
public class TransparentPanel : Control
{
private Color _borderColor;
private int _borderWidth = 1;
private DashStyle _borderStyle = DashStyle.Solid;
private int _opacity = 125; public TransparentPanel()
{ } #region Property
[Category("Custom"), Description("Border Color")]
public Color BorderColor
{
set { _borderColor = value; }
get { return _borderColor; }
} [Category("Custom"), Description("Border Width"), DefaultValue(1)]
public int BorderWidth
{
set
{
if (value < 0) value = 0;
_borderWidth = value;
}
get { return _borderWidth; }
} [Category("Custom"), Description("Border Style"), DefaultValue(DashStyle.Solid)]
public DashStyle BorderStyle
{
set { this._borderStyle = value; this.Invalidate(); }
get { return this._borderStyle; }
} [Bindable(true), Category("Custom"), DefaultValue(125), Description("背景的透明度. 有效值0-255")]
public int Opacity
{
get { return _opacity; }
set
{
if (value > 255) value = 255;
else if (value < 0) value = 0;
_opacity = value;
this.Invalidate();
}
}
#endregion protected override void OnPaintBackground(PaintEventArgs e)
{
//do not allow the background to be painted
} protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
} protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (this._opacity > 0)
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(this._opacity, this.BackColor)),
this.ClientRectangle);
}
if (this._borderWidth > 0)
{
Pen pen = new Pen(this._borderColor, this._borderWidth);
pen.DashStyle = this._borderStyle;
e.Graphics.DrawRectangle(pen, e.ClipRectangle.Left, e.ClipRectangle.Top, this.Width - 1, this.Height - 1);
pen.Dispose();
}
} }
}
c# 可以设置透明度的 Panel 组件的更多相关文章
- easyUI panel组件
easyUI panel组件: 属性的使用: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- Javascript - ExtJs - Ext.form.Panel组件
FormPanel组件(Ext.form.FormPanel) logogram:Ext.form.Panel | xtype:form Ext.form.Panel.配置 frame }//旗下所有 ...
- android 控件设置透明度
问题:java文件中引用组件设置透明度:mGuideLayout.getBackground().setAlpha(125); 一直报null 修改办法:对应的布局文件中添加 android:back ...
- css中怎么设置透明度的问题
小伙伴们是不是在找怎么样去设置页面的透明度的方法呢...别找了,我这儿就有,而且肯定够用了. 我自己会用到的就有两种,可以和大家分享一下. 1.用opcity的方法去设置透明度.代码如下: .div ...
- IOS 设置透明度导致底层View始终可见
正确效果如图:下面的toolBar应该看不见它下面的View, 避免方法:[self.view addSubView:aSubView];这个aSubView一定不能设置不透明度,应将其设置为Cle ...
- cocos2dx对所有子节点设置透明度
看到cocos2dx2.2.5发布了,修复了输入框的bug,于是我们的项目也升级到了2.2.5, 升级过程还是比较顺利,没想到后来发现设置透明度无效了. 经过调试发现要调用一下setCascadeOp ...
- java 图片加水印,设置透明度。说明非常具体
package com.yidao.common; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.aw ...
- sublime text3使用插件SublimeTextTrans设置透明度
推荐一款在windows上设置sublime2和sublime3背景透明度的插件:SublimeTextTrans, 下载地址:https://github.com/vhanla/SublimeTex ...
- (求助)对某一颜色,设置透明度 alpha 后,其他使用该颜色的地方 受到影响!!!!原因未知
对某一颜色,设置透明度 alpha 后,其他使用该颜色的地方 受到影响!!!!原因未知,有谁碰到过这样的问题?????? 测试了以下三款手机,结果如下: 1.android 4.4.2: 不受影响 2 ...
随机推荐
- 定制x86 Linux系统
/************************************************************************************* * 定制x86 Linux ...
- busybox inetd tftpd
/*************************************************************************** * busybox inetd tftpd * ...
- setTimeout方法
//不建议传递字符串 setTimeout(alert("hello"),1000); //推荐调用方式 setTimeout(function(){alert("hel ...
- 循环列表的Java实现,解决约瑟夫环问题
import java.util.Scanner; /** * 循环列表的Java实现,解决约瑟夫环问题 * * @author LIU * */ public class LinkedList { ...
- win7建立无线wifi热点的几个常见的问题
命令行开启WiFi方法: 开启WiFi.bat netsh wlan set hostednetwork mode=allow netsh wlan set hostednetwork ssid=ss ...
- Matlab优化存储器读写来改善程序性能
最近用Matlab写程序的时候终于遇到了程序执行效率的问题,于是在Google上面搜索了一篇提高代码性能的文章,简单的概括一下. 文章是通过优化寄存器读写来提高执行速度的,主要体现在三个方面: 在做循 ...
- LA 3644 易爆物 并查集
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- c#部分---输入班级人数,输入语文数学英语成绩,打印语文前两名,数学后两名,英语平均分
1.开始收集输入项 2.用冒泡排序,统计语文成绩,并附带把语数英三门课全排列 3.数学成绩排序,附带把三门课全排序‘ 4.最后算英语的平均分:
- spark中streamingContext的使用详解
两种创建方式 val conf = new SparkConf().setAppName(appName).setMaster(master);val ssc = new StreamingConte ...
- 奇怪的电梯(HDU1548) (Dijkstra)或者(BFS)
问题 E: 奇怪的电梯 时间限制: 1 Sec 内存限制: 64 MB提交: 35 解决: 16[提交][状态][讨论版] 题目描述 有一天桐桐做了一个梦,梦见了一种很奇怪的电梯.大楼的每一层楼都 ...