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

相关推荐
神仙别闹2 分钟前
基于Python+Neo4j实现新冠信息挖掘系统
开发语言·python·neo4j
码观天工10 分钟前
.NET 原生驾驭 AI 新基建实战系列(五):Milvus ── 大规模 AI 应用的向量数据库首选
c#·.net·milvus·向量数据库·高性能
猫猫头有亿点炸32 分钟前
C语言大写转小写2.0
c语言·开发语言
A达峰绮42 分钟前
设计一个新能源汽车控制系统开发框架,并提供一个符合ISO 26262标准的模块化设计方案。
大数据·开发语言·经验分享·新能源汽车
BS_Li1 小时前
C++类和对象(上)
开发语言·c++·类和对象
XiaoyuEr_66881 小时前
C#中属性和字段的区别
开发语言·c#
火星papa1 小时前
C# 利用log4net 工作台打印和保存到文件
c#
ghost1431 小时前
C#学习第19天:多线程
开发语言·学习·c#
钢铁男儿1 小时前
C# 类的基本概念(声明类)
c#