111,120
社区成员
发帖
与我相关
我的任务
分享
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.Runtime.InteropServices;
namespace 准心
{
public partial class Form1 : Form
{
bool mousemove = true;
private Point mouseOffset;
Color col = Color.FromArgb(0, 255, 255, 255);
private bool isMouseDown = false;
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos(
IntPtr hwnd,
int hWndInsertAfter,
int x,
int y,
int cx,
int cy,
int wFlags
);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.BackColor = col;
pictureBox1.BackgroundImage = imageList1.Images[0];
SetWindowPos(this.Handle, -1, Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2, this.Width, this.Height, 0);
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset =-e.X ;
yOffset = -e.Y -
SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
if (mousemove )
Location = mousePos;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
private void 移动ToolStripMenuItem_Click(object sender, EventArgs e)
{
mousemove = true;
锁定ToolStripMenuItem.Visible = true;
移动ToolStripMenuItem.Visible = false;
}
private void 锁定ToolStripMenuItem_Click(object sender, EventArgs e)
{
mousemove = false;
锁定ToolStripMenuItem.Visible = false;
移动ToolStripMenuItem.Visible = true ;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}