// ***********************************************************************
// Assembly : HZH_Controls
// Created : 08-08-2019
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
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
{
///
/// Class FrmTransparent.
/// Implements the
///
///
public partial class FrmTransparent : FrmBase
{
///
/// The wm activate
///
private const int WM_ACTIVATE = 6;
///
/// The wm activateapp
///
private const int WM_ACTIVATEAPP = 28;
///
/// The wm ncactivate
///
private const int WM_NCACTIVATE = 134;
///
/// The wa inactive
///
private const int WA_INACTIVE = 0;
///
/// The wm mouseactivate
///
private const int WM_MOUSEACTIVATE = 33;
///
/// The ma noactivate
///
private const int MA_NOACTIVATE = 3;
///
/// Gets the create parameters.
///
/// The create parameters.
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
///
/// Gets or sets the frmchild.
///
/// The frmchild.
public FrmBase frmchild
{
get;
set;
}
///
/// Initializes a new instance of the class.
///
public FrmTransparent()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.Selectable, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.UserPaint, 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;
}
///
/// Sets the active window.
///
/// The handle.
/// IntPtr.
[DllImport("user32.dll")]
private static extern IntPtr SetActiveWindow(IntPtr handle);
///
/// WNDs the proc.
///
/// 要处理的 Windows 。
protected override void WndProc(ref Message m)
{
if (m.Msg == 33)
{
m.Result = new IntPtr(3);
}
else
{
if (m.Msg == 134)
{
if (((int)m.WParam & 65535) != 0)
{
if (m.LParam != IntPtr.Zero)
{
FrmTransparent.SetActiveWindow(m.LParam);
}
else
{
FrmTransparent.SetActiveWindow(IntPtr.Zero);
}
}
}
else if (m.Msg == 2000)
{
}
base.WndProc(ref m);
}
}
///
/// Handles the Load event of the FrmTransparent control.
///
/// The source of the event.
/// The instance containing the event data.
private void FrmTransparent_Load(object sender, EventArgs e)
{
if (frmchild != null)
{
frmchild.IsShowMaskDialog = false;
var dia = frmchild.ShowDialog(this);
this.DialogResult = dia;
}
}
}
}