移动图标

来源:互联网 发布:ubuntu swap 主分区 编辑:程序博客网 时间:2024/05/11 04:13
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;


namespace 移动图标
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Opacity = 0.5;
        }
       


        //#############拖动窗体#############
        private bool isMouseDown = false;
        private Point FormLocation;     //form的location
        private Point mouseOffset;      //鼠标的按下位置
        //#############################


        private void Form1_Load(object sender, EventArgs e)
        {
         


            this.Top = 20;
            this.Left = Screen.PrimaryScreen.Bounds.Width - 80;
            this.Width = 60;
            this.Height = 20;


          
         
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //美化窗体
            Graphics g = e.Graphics;
            Color FColor = Color.Red;
            Color TColor = Color.Yellow;
            Brush b = new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.ForwardDiagonal);
            g.FillRectangle(b, this.ClientRectangle);
        }


        private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Form2 zhuye = new Form2();
            zhuye.Show();
        }


        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
             if (e.Button == MouseButtons.Right)
            {
                this.contextMenuStrip1.Show(Control.MousePosition);
            }
            
        }
        private void 主页面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 zhuye = new Form2();
            zhuye.Show();
        }


        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("介绍说明", "欢迎使用");
        }


        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = true;
                FormLocation = this.Location;
                mouseOffset = Control.MousePosition;
            }
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            int _x = 0;
            int _y = 0;
            if (isMouseDown)
            {
                Point pt = Control.MousePosition;
                _x = mouseOffset.X - pt.X;
                _y = mouseOffset.Y - pt.Y;


                this.Location = new Point(FormLocation.X - _x, FormLocation.Y - _y);
            }
        }


        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }
       


        
       
    }
}
0 0