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

相关推荐
yujunl1 分钟前
AI工具帮助程序员做网页的经历
开发语言
6+h2 分钟前
【java IO】字符流详解
java·开发语言
ZHOUPUYU2 分钟前
PHP文件处理与安全实战——从上传下载到高级操作的完整指南
开发语言·php
小年糕是糕手3 分钟前
【35天从0开始备战蓝桥杯 -- 补充包】
开发语言·前端·数据结构·数据库·c++·算法·蓝桥杯
Zzj_tju1 小时前
Java 从入门到精通(六):抽象类与接口到底怎么选?
java·开发语言
@PHARAOH2 小时前
HOW - Go 开发入门(一)
开发语言·后端·golang
人工智能AI技术8 小时前
315曝光AI投毒!用C#构建GEO污染检测与数据安全防护方案
人工智能·c#
myloveasuka9 小时前
Java与C++多态访问成员变量/方法 对比
java·开发语言·c++
2301_821700539 小时前
C++编译期多态实现
开发语言·c++·算法
奥地利落榜美术生灬9 小时前
c++ 锁相关(mutex 等)
开发语言·c++