(二十二)c#Winform自定义控件-半透明窗体
官网
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492 idkey=6e08741ef16fe53bf0314c1c9e336c4f626047943a8b76bac062361bab6b4f8d">
目录
https://www.cnblogs.com/bfyx/p/11364884.html
准备工作
这个窗体继承子基类窗体FrmBase,如果你对FrmBase还不了解,请移步 (十七)c#Winform自定义控件-基类窗体 查看
开始
添加一个Form,命名FrmTransparent,继承自FrmBase
代码不多,直接上完整代码了
// 版权所有 黄正辉 交流群:568015492 QQ:623128629
// 文件名称:FrmTransparent.cs
// 创建日期:2019-08-15 16:05:00
// 功能描述:FrmTransparent
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms; namespace HZH_Controls.Forms
{
public partial class FrmTransparent : FrmBase
{
private const int WM_ACTIVATE = ; private const int WM_ACTIVATEAPP = ; private const int WM_NCACTIVATE = ; private const int WA_INACTIVE = ; private const int WM_MOUSEACTIVATE = ; private const int MA_NOACTIVATE = ; public FrmBase frmchild
{
get;
set;
}
public FrmTransparent()
{
InitializeComponent(); base.SetStyle(ControlStyles.UserPaint, true);
base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
base.SetStyle(ControlStyles.DoubleBuffer, true); MethodInfo method = base.GetType().GetMethod("SetStyle", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod);
method.Invoke(this, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, new object[]
{
ControlStyles.Selectable,
false
}, Application.CurrentCulture);
} protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
base.ShowInTaskbar = false;
base.ShowIcon = true;
}
[DllImport("user32.dll")]
private static extern IntPtr SetActiveWindow(IntPtr handle); protected override void WndProc(ref Message m)
{
if (m.Msg == )
{
m.Result = new IntPtr();
}
else
{
if (m.Msg == )
{
if (((int)m.WParam & ) != )
{
if (m.LParam != IntPtr.Zero)
{
FrmTransparent.SetActiveWindow(m.LParam);
}
else
{
FrmTransparent.SetActiveWindow(IntPtr.Zero);
}
}
}
else if (m.Msg == )
{
}
base.WndProc(ref m);
}
} private void FrmTransparent_Load(object sender, EventArgs e)
{
if (frmchild != null)
{
frmchild.IsShowMaskDialog = false;
var dia = frmchild.ShowDialog(this);
this.DialogResult = dia;
}
}
}
}
namespace HZH_Controls.Forms
{
partial class FrmTransparent
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmTransparent));
this.SuspendLayout();
//
// FrmTransparent
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(, );
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FrmTransparent";
this.Opacity = 0.5D;
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "FrmTransparent";
this.Load += new System.EventHandler(this.FrmTransparent_Load);
this.ResumeLayout(false); } #endregion
}
}
主要就是构造函数和load事件里面的那几句话
用处及效果
用途:一般用在蒙版,比如弹出窗口的时候,显示一个半透明蒙版
最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星 星吧
(二十二)c#Winform自定义控件-半透明窗体的更多相关文章
- (二十)c#Winform自定义控件-有后退的窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (二十三)c#Winform自定义控件-等待窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (三十)c#Winform自定义控件-文本框(三)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- winform 自定义控件:半透明Loading控件
winform 自定义控件:半透明Loading控件 by wgscd date:2015-05-05 效果: using System;using System.Drawing;using Sys ...
- [分享] IT天空的二十二条军规
Una 发表于 2014-9-19 20:25:06 https://www.itsk.com/thread-335975-1-1.html IT天空的二十二条军规 第一条.你不是什么都会,也不是什么 ...
- Bootstrap <基础二十二>超大屏幕(Jumbotron)
Bootstrap 支持的另一个特性,超大屏幕(Jumbotron).顾名思义该组件可以增加标题的大小,并为登陆页面内容添加更多的外边距(margin).使用超大屏幕(Jumbotron)的步骤如下: ...
- Web 前端开发精华文章推荐(HTML5、CSS3、jQuery)【系列二十二】
<Web 前端开发精华文章推荐>2014年第一期(总第二十二期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML ...
- 二十二、OGNL的一些其他操作
二十二.OGNL的一些其他操作 投影 ?判断满足条件 动作类代码: ^ $ public class Demo2Action extends ActionSupport { public ...
- WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇]
原文:WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇] 在[上篇]中,我们分别站在消息交换和编程的角度介绍了SOAP Fault和FaultException异常.在服务执行过 ...
随机推荐
- 前端动画 wow.js 效果
让花里胡哨的特效变简单 wow.js动画class介绍 引入css样式以及js插件 <link rel="stylesheet" type="text/css&qu ...
- WinForm控件之【ComboBox】
基本介绍 下拉文本框应用较为广泛,在winfrom控件当中使用设置也是相对的简单,主要用于存在多种选择的单选操作场景. 常设置属性.事件 DataSource:绑定加载项的数据源,设置属性Displa ...
- Java用Zip进行压缩
这个总结源于Java编程思想第四版18.11节的案例: 完整代码地址: Java编程思想:压缩 相关Api地址: ZipStream ZipEntry ZipFile 进行压缩时: 1.创建Check ...
- Jmeter--录制脚本-用户参数化-添加断言
使用jmeter实现的场景 1.使用badboy录制脚本 2.使用jmeter自带元件进行用户参数化 3.给请求添加断言(给请求添加检查点) 使用badboy录制脚本导入jmeter 1.输入http ...
- 安卓开发之详解getChildFragmentManager和getsupportFragmentManager和getFragmentManager详解
安卓开发之详解getChildFragmentManager和getsupportFragmentManager和getFragmentManager详解 getFragmentManager()所得 ...
- Linux 安装MySql——ubuntu版
这里简单地阐述一下rpm.deb.tar.gz的区别. rpm格式的软件包适用于基于Red Hat发行版的系统,如Red Hat Linux.SUSE.Fedora. deb格式的软件包则是适用于基于 ...
- PhpCms V9中的{date('Y-m-d',$r[inputtime])}问题解决方法
不少朋友会碰到这个问题:在PhpCms V9中的首页或者文章内容页调用发布时间{date('Y-m-d',$r[inputtime])}调用显示1970-01-01,然后尝试用截断的方法也没有成功,应 ...
- python中的内存机制
首先要明白对象和引用的概念 (例子:a=1, a为引用,1为对象,对象1的引用计数器为1,b=1此时内存中只有一个对象1,a,b都为引用,对象的引用计数器此时为2,因为有两个引用) a=1,b=1 i ...
- java练习---15
package cn.lyh; public class L { //斐波那契数列 public static void main(String[] args) { int []arr = new i ...
- Java面试题-基础篇三(干货)
这些JAVA基础题确定都会了吗? 31.String s = new String("xyz");创建了几个StringObject?是否可以继承String类? 两个或一个都有可 ...