官网

http://www.hzhcontrols.com

前提

入行已经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自定义控件-半透明窗体的更多相关文章

  1. (二十)c#Winform自定义控件-有后退的窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  2. (二十三)c#Winform自定义控件-等待窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  3. (三十)c#Winform自定义控件-文本框(三)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  4. winform 自定义控件:半透明Loading控件

    winform  自定义控件:半透明Loading控件 by wgscd date:2015-05-05 效果: using System;using System.Drawing;using Sys ...

  5. [分享] IT天空的二十二条军规

    Una 发表于 2014-9-19 20:25:06 https://www.itsk.com/thread-335975-1-1.html IT天空的二十二条军规 第一条.你不是什么都会,也不是什么 ...

  6. Bootstrap <基础二十二>超大屏幕(Jumbotron)

    Bootstrap 支持的另一个特性,超大屏幕(Jumbotron).顾名思义该组件可以增加标题的大小,并为登陆页面内容添加更多的外边距(margin).使用超大屏幕(Jumbotron)的步骤如下: ...

  7. Web 前端开发精华文章推荐(HTML5、CSS3、jQuery)【系列二十二】

    <Web 前端开发精华文章推荐>2014年第一期(总第二十二期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML ...

  8. 二十二、OGNL的一些其他操作

    二十二.OGNL的一些其他操作 投影 ?判断满足条件 动作类代码: ^ $   public class Demo2Action extends ActionSupport {     public ...

  9. WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇]

    原文:WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇] 在[上篇]中,我们分别站在消息交换和编程的角度介绍了SOAP Fault和FaultException异常.在服务执行过 ...

随机推荐

  1. JAVA包装类解析和面试陷阱分析

    包装类 什么是包装类 虽然 Java 语言是典型的面向对象编程语言,但其中的八种基本数据类型并不支持面向对象编程,基本类型的数据不具备“对象”的特性——不携带属性.没有方法可调用. 沿用它们只是为了迎 ...

  2. CDQZ集训DAY5 日记

    又一个爆炸的一天…… 早上起来发现貌似是周末,七中放假(别人家的学校(一周一放,一放两天)……)然而感觉状态不是很好,感觉药丸. 题目一上来就装弱,有诈.第一题上来先打暴力,T2不知道怎么打.T3暴力 ...

  3. Bzoj 1079 着色方案 题解

    1079: [SCOI2008]着色方案 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2237  Solved: 1361[Submit][Stat ...

  4. Thread API的详细介绍

    import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurr ...

  5. 【最小生成树之Prim算法】-C++

    [最小生成树之Kruskal算法] 没有看过的可以先看↑,会更简单. [模板]最小生成树 这一篇博客主要是介绍另外一种算法:Prim算法. prim算法就好像是一棵"生成树"在慢慢 ...

  6. redux、react-redux、redux-thunk、redux-saga使用及dva对比

    一.redux使用 Redux的核心概念其实很简单:将需要修改的state都存入到store里,发起一个action用来描述发生了什么,用reducers描述action如何改变state tree ...

  7. [原创]mininet安装

    mininet安装: on Ubuntu 13.04: sudo apt-get install minineton Ubuntu 12.10: sudo apt-get install minine ...

  8. mysql数据库建表分类字段--尽量少用字符串--原因探索

    虽然一直都知道,类型 之类的字段 直接用字符窜会很方便,不过最好还是不要用字符串:但是也不是特别清楚为什么不要用,时间久了 就忍不住用一下字符窜试试,这一试 还挺好用的,吓得我 感觉探究了一下 为什么 ...

  9. cve-2018-2893 WebLogic

    最近爆出来了新的漏洞cve-2018-2893 一.背景介绍 WebLogic是美国Oracle公司出品的一个Application Server,确切的说是一个基于JAVAEE架构的中间件,WebL ...

  10. [leetcode] 650. 2 Keys Keyboard (Medium)

    解法一: 暴力DFS搜索,对每一步进行复制还是粘贴的状态进行遍历. 注意剪枝的地方: 1.当前A数量大于目标数量,停止搜索 2.当前剪贴板数字大于等于A数量时,只搜索下一步为粘贴的状态. Runtim ...