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. Nginx启动出错 error while loading shared libraries:

    在centos5.7 32位上编译安照 nginx-1.1.16 出错 [root@localhost conf]# /usr/local/nginx/sbin/nginx/usr/local/ngi ...

  2. C# UdpClient 设置超时时间

    /********************************************************************** * C# UdpClient 设置超时时间 * 说明: ...

  3. 前端学习资源(js)

    JavaScript JavaScript | MDN JavaScript 秘密花园 JavaScript 标准参考教程(alpha) 给 JavaScript 初心者的 ES2015 实战 Col ...

  4. Dubbo_Admin安装

    1.下载dubbo 我上传地址:http://download.csdn.net/detail/liweifengwf/7784901 官方地址:http://code.alibabatech.com ...

  5. ABySS 拼接工具

    ABySS, that stands for Assembly By Short Sequences, is a de novo, parallel, paired-end sequence asse ...

  6. Python天天美味(13) - struct.unpack

    转载自:http://www.cnblogs.com/coderzh/archive/2008/05/04/1181462.html Python中按一定的格式取出某字符串中的子字符串,使用struc ...

  7. SQL根据现有表新建一张表

    SQL根据现有表新建表,新建的这张表结构要跟现有表结构相同,但不要现有表里面的数据! 执行DML语句依据数据库类型而定: SQLITE -----复制表结构及数据到新表 CREATE TABLE TA ...

  8. android中的空格及汉字的宽度

    在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格:  窄空格:  一个汉字宽度的空格:   [用两个空格(  )占一个汉字的宽度时,两个空格比 ...

  9. 精美的HTML5 Loadding页面

    以前我们大部分的Loading动画都是利用gif图片实现的,这种图片实现Loading动画的方法虽然也很不错,但是作为HTML5开发者来说,如果能利用HTML5和CSS3实现这些超酷的Loading动 ...

  10. init/main.c

    /* * linux/init/main.c * * Copyright (C) 1991, 1992 Linus Torvalds */ #include <stdarg.h> #inc ...