csvigoss 2018-04-17 01:22 采纳率: 0%
浏览 1520
已结题

用C#设计窗口程序,实现鼠标能随意拖拽

作为多屏视频监控
要实现:
10x10的方格,(用什么控件没有限制)显示一百个画面,用户用鼠标拖动可以把鼠标覆盖的格子单独输出。
比如能任意拖拽出3x4, 5x6的画面。
只需实现这个拖拽功能就行,求各位大神指点下 本人小白。

  • 写回答

2条回答

  • 过客1996 2018-04-17 02:19
    关注

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;

    namespace WindowsApplication1
    {

    public partial class Form1 : Form
    {
        Point pt;
        bool moves = true;
    
        public Form1()
        {
            InitializeComponent();
        }
    

    private void button1_Click(object sender, EventArgs e)
    {
    if (moves == true)
    {
    MessageBox.Show("sfdfdf");
    }
    }

        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
        }
    
        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int px = Cursor.Position.X - pt.X;
                int py = Cursor.Position.Y - pt.Y;
                button1.Location = new Point(button1.Location.X + px, button1.Location.Y + py);
                pt = Cursor.Position;
                moves = false;
            } 
        }
    
        private void button1_MouseUp(object sender, MouseEventArgs e)
        {
            moves = true;
        }
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料