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;
        }
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?