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

相关推荐
无限远的弧光灯5 分钟前
c语言学习_函数递归
c语言·开发语言·学习
趣多多代言人12 分钟前
从零开始手写嵌入式实时操作系统
开发语言·arm开发·单片机·嵌入式硬件·面试·职场和发展·嵌入式
胖大和尚23 分钟前
C++项目学习计划
开发语言·c++·学习
开开心心_Every25 分钟前
全能视频处理工具介绍说明
开发语言·人工智能·django·pdf·flask·c#·音视频
86Eric33 分钟前
C# 入门学习教程(二)
c#·操作符·语句
vvilkim1 小时前
Nuxt.js 全面测试指南:从单元测试到E2E测试
开发语言·javascript·ecmascript
Tipriest_1 小时前
Python异常类型介绍
开发语言·python·异常
Swift社区1 小时前
Swift 解 LeetCode 321:拼接两个数组中的最大数,贪心 + 合并全解析
开发语言·leetcode·swift
ruan1145142 小时前
Java Lambda 类型推断详解:filter() 方法与 Predicate<? super T>
java·开发语言·spring·stream
广东数字化转型2 小时前
java jar 启动应用程序
开发语言·python