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 组件的更多相关文章

  1. easyUI panel组件

    easyUI panel组件: 属性的使用: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  2. Javascript - ExtJs - Ext.form.Panel组件

    FormPanel组件(Ext.form.FormPanel) logogram:Ext.form.Panel | xtype:form Ext.form.Panel.配置 frame }//旗下所有 ...

  3. android 控件设置透明度

    问题:java文件中引用组件设置透明度:mGuideLayout.getBackground().setAlpha(125); 一直报null 修改办法:对应的布局文件中添加 android:back ...

  4. css中怎么设置透明度的问题

    小伙伴们是不是在找怎么样去设置页面的透明度的方法呢...别找了,我这儿就有,而且肯定够用了. 我自己会用到的就有两种,可以和大家分享一下. 1.用opcity的方法去设置透明度.代码如下: .div ...

  5. IOS 设置透明度导致底层View始终可见

    正确效果如图:下面的toolBar应该看不见它下面的View, 避免方法:[self.view  addSubView:aSubView];这个aSubView一定不能设置不透明度,应将其设置为Cle ...

  6. cocos2dx对所有子节点设置透明度

    看到cocos2dx2.2.5发布了,修复了输入框的bug,于是我们的项目也升级到了2.2.5, 升级过程还是比较顺利,没想到后来发现设置透明度无效了. 经过调试发现要调用一下setCascadeOp ...

  7. java 图片加水印,设置透明度。说明非常具体

    package com.yidao.common; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.aw ...

  8. sublime text3使用插件SublimeTextTrans设置透明度

    推荐一款在windows上设置sublime2和sublime3背景透明度的插件:SublimeTextTrans, 下载地址:https://github.com/vhanla/SublimeTex ...

  9. (求助)对某一颜色,设置透明度 alpha 后,其他使用该颜色的地方 受到影响!!!!原因未知

    对某一颜色,设置透明度 alpha 后,其他使用该颜色的地方 受到影响!!!!原因未知,有谁碰到过这样的问题?????? 测试了以下三款手机,结果如下: 1.android 4.4.2: 不受影响 2 ...

随机推荐

  1. Ubuntu14.04 64位运行32位程序

    最近公司新增的机器安装Ubuntu14.04 64bit导致之前在32bit下编译的Qt工具软件无法运行. 于是google的了一下找到一些解决办法,但不能保证全部32bit的Qt程序都能正常,测试了 ...

  2. metronic后台模板学习 -- 所用外部插件列表

    插件名称 描述 URL jQuery 1.11.0 js库,不用介绍了 http://www.jquery.com jQuery Migrate plugin 1.2.1 jQuery 老版本过渡迁移 ...

  3. poj 1190 生日蛋糕

    中文题 题目分析 搜索题,非常好的剪枝 由于深度一定(m),所以使用深度优先搜索,自上而下的设定蛋糕序号,最顶层的为第1层,……,最底层的蛋糕为第m层,很明显满足题目条件的前i层的(从顶层(也就是编号 ...

  4. UVa 10747 - Maximum Subsequence

    题目大意:给出n个数,从中选取k个,使得乘积最大,并且尽量使和最大 分析:首先按照数的绝对值大小排序.然后就要分三大类情况讨论: (1)前k个中选到0:如果选到0的话,乘积一定是0,所以尽量选大的数, ...

  5. iOS学习笔记---c语言第九天

    高级指针 指向结构体变量的指针,称为结构体指针 可以使用->指向内容. %p打印地址 void pLenth(cPoint *p1,cPoint *p2) //求两点间的距离  用的开方函数sq ...

  6. TextView所有属性

    android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web/email/phone/map/all) android: ...

  7. 《C标准库》——之<ctype.h>

    在没读<ctype.h>的源码之前,我一直以为我们平时用的isalnum.isdigit.isalpha等这些函数,是靠判断写出来的. 比如: int isdigit(int c){ re ...

  8. leetcode 132. Palindrome Partitioning II ----- java

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  9. POJ 1488 Tex Quotes --- 水题

    POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...

  10. hihoCoder:#1079(线段树+离散化)

    题目大意:给n个区间,有的区间可能覆盖掉其他区间,问没有完全被其他区间覆盖的区间有几个?区间依次给出,如果有两个区间完全一样,则视为后面的覆盖前面的. 题目分析:区间可能很长,所以要将其离散化.但离散 ...