c#异形窗体遮罩效果

c#异形窗体遮罩效果,移动,关闭,最大化,最小化,还原操作

复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private Point mouseOffset;                 //记录鼠标指针的坐标 
        private bool isMouseDown = false;      //记录鼠标按键是否按下
        public Form1()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
           
            InitializeComponent();
        }
       

            private void Form1_Load(object sender, EventArgs e)
        {
            TransparencyKey = Color.White;
            Image BackgroundImage = Bitmap.FromFile("111.png");
            BitmapRegion BitmapRegion = new BitmapRegion();//此为生成不规则窗体和控件的类
          //  BitmapRegion.CreateControlRegion(this, new Bitmap("feichuan5.jpg"));
            BitmapRegion.CreateControlRegion(this, new Bitmap("feichuan5a.png"));
        }

        private void button_start_Click(object sender, EventArgs e)
        {
            MessageBox.Show("程序以启动");
        }

        private void button_close_Click(object sender, EventArgs e)
        {
            MessageBox.Show("程序已将关闭");
            this.Close();
        }

        private void button_max_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
        }

        private void button_min_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void button_to_default_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            int xOffset;
            int yOffset;

            if (e.Button == MouseButtons.Left)
            {
                xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                yOffset = -e.Y - SystemInformation.CaptionHeight -
                  SystemInformation.FrameBorderSize.Height;
                mouseOffset = new Point(xOffset, yOffset);
                isMouseDown = true;
            }
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                Location = mousePos;
            }
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            //   修改鼠标状态isMouseDown的值
            //   确保只有鼠标左键按下并移动时,才移动窗体
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;
            }
        }
    }
}

工程代码:

https://download.csdn.net/download/txwtech/88746025https://download.csdn.net/download/txwtech/88746025

相关推荐
yong999031 分钟前
MATLAB倍频转换效率分析与最佳匹配角模拟
开发语言·前端·matlab
已黑化的小白35 分钟前
Rust 的所有权系统,是一场对“共享即混乱”的编程革命
开发语言·后端·rust
csbysj202038 分钟前
TypeScript 元组
开发语言
Laity______1 小时前
指针(2)
c语言·开发语言·数据结构·算法
是苏浙1 小时前
零基础入门C语言之C语言实现数据结构之顺序表经典算法
c语言·开发语言·数据结构·算法
5967851541 小时前
C# 弹出框DialogForm
开发语言·c#
FnTop1 小时前
实用教程:打造支持参数配置的 Git Bash 文件清理脚本
开发语言·git·bash
提娜米苏2 小时前
Bash Shell脚本学习——唇读数据集验证脚本
开发语言·学习·bash
lkbhua莱克瓦242 小时前
Java基础——集合进阶5
java·开发语言·集合·泛型
聪明努力的积极向上2 小时前
【C#】System.Text.Encoding.Default 属性在framework和.netcore中的区别
开发语言·c#·.netcore