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 ...
随机推荐
- python字典中的元素类型
python字典默认的是string item={"browser " : 'webdriver.irefox()', 'url' : 'http://xxx.com'} 如果这样 ...
- nagios安装配置
http://www.codeweblog.com/nagios%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/ 上线的服务器有时会被人攻击,导致服务不可用,今天安装配置了 ...
- Notes of Linked Data concept and application - TODO
Motivation [反正债多了不愁,再开个方向.] Data plays a core role in most business systems, data storage and retrie ...
- CollectionsAPI
鉴于总用,总结一下: 类别 方法 查找 binarySearch. 返回 enumeration.checkedSortedMap 判断 max.min 移动 reverse(List).revers ...
- jce
jdk8:jce 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html jdk ...
- Android——BaseAdapter相关
layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- 作业:用HTML制作邮箱登陆界面
<body leftmargin="200" rightmargin="200"> <font size="45" > ...
- 在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke 解决办法
增加IsHandleCreated 判断 if (this.IsHandleCreated) { this.Invoke(new EventHandler(delegate { ...... })); ...
- Linux系统编程@多线程编程(一)
多线程编程 涉及操作系统原理概念 时间片 进程状态 上下文: 对进程来说,就是进程的执行环境,具体就是各个变量和数据,包括所有的寄存器变量.打开的文件.内存信息等. 进程的写时复制:由于一般 fork ...
- phpstorm用正则删除PHP代码空行小技巧
有很多小伙伴会遇到代码空行特别多,但是一行一行删除肯定很烦躁,这时候就需要用到批量删除空行. 怎么批量删除空行呢? 我的办法是用正则把所有空行找到,然后一键全部替换. 首先把Match Case和Re ...