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. NSNumber 、 NSValue 、 日期处理 、 集合类 、 NSArray(一)

    1 基本数据类型的封装 1.1 问题 我们所学的所有基本数据类型,如int.float.double.char等,都不是对象,不能向它们发送消息.然而,在Foundation中的许多类,如NSArra ...

  2. vi的用法 【转】

        vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的任何版本,vi编辑器 ...

  3. Mapnik 教程

    mapnik::parameters 参数解析 mapnik::parameters params; params["encoding"] = "utf-8" ...

  4. HOG参数简介及Hog特征维数的计算(转)

    HOG构造函数 CV_WRAP HOGDescriptor() :winSize(64,128), blockSize(16,16), blockStride(8,8),      cellSize( ...

  5. uva624 CD   01背包+输出最优解

    link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. leetcode 99 Recover Binary Search Tree ----- java

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  7. svn 安装 、使用(1)

    写在开头: 虽然网络极大的方便了我们查找答案,而且有很多人写各样的博客.但每个人在实际中的情况不一样,遇到的问题也不一样,大牛们会把步骤写的很简单,可能真的是怕麻烦,但显然就有一些东西已经不适合一部分 ...

  8. Android——计算器

    layout文件: <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:andr ...

  9. Python3字典中items()和python2.x中iteritems()有什么区别

    在Python2.x中,items( )用于 返回一个字典的拷贝列表[Returns a copy of the list of all items (key/value pairs) in D],占 ...

  10. FileReader/FileWriter复制文件

    public class Test{ /*FileReader/FileWriter读写乱码,待处理*/ public static void main(String[] args) throws I ...