Example of dragging a picture in C #

Source: Internet
Author: User

This question comes from the forum, and there is no difficulty and no need to redraw the content. Of course there is a way to send Wm_syscommand and sc_move through the API, that is, to drag the untitled form, but the effect is not this good.

Using System;
Using System.Drawing;
Using System.Windows.Forms;
Namespace WindowsApplication2
... {
public partial class Form1:form
... {
static string Strdown = @ "Aaacaaeaicaaaasacqawaqaafgaaacgaaaagaaaaqaaaaaeaaqaaaaaaaaiaaaaa
Aaaaaaaaaaaaaaaaaaaaaaaa////aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Aaaaaaaaaaf4aaad8aaaa/aaaapwaaah+aaad/gaab/8aaa//aaan/waacf+aaah
9gaadbqaaa2waaajsaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Aaaaaaaa////////////////////////////////////////////8ap///gh///4
B///+af///ad///ga///wah//4ab//+aaf//gad//4aa///aap//4ah//+ah///g
D////j////////////////////////////////////////////8= ";
static string Strup = @ "Aaacaaeaicaaaaoacaawaqaafgaaacgaaaagaaaaqaaaaaeaaqaaaaaaaaiaaa
Aaaaaaaaaaaaaaaaaaaaaaaaaa////aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaf4aaad8aaaa/aaaapwaaah+aaad/gaab/8aaa//aaad/waagf+
Aaah9gaadbyaaa2yaaazsaaagbaaaagaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaa////////////////////////////////////////////8ap///
gh///4b///+af///ad///ga///wah//4ab//8aaf//aad//4aa///gap//4ad//
8af///ab///5a////5///////////////////////////////////////8= ";

Cursor Curup = new Cursor (New System.IO.MemoryStream (Convert.frombase64string (Strup)));
Cursor Curdown = new Cursor (New System.IO.MemoryStream (Convert.frombase64string (Strdown)));
Public Form1 ()
... {
InitializeComponent ();
This.pictureBox1.Cursor = Curup;
}

BOOL bdragging = false;
Point pclicked;

private void Picturebox1_mousedown (object sender, MouseEventArgs e)
... {

Bdragging = true;
pclicked = new Point (e.x, e.y);
This.pictureBox1.Cursor = Curdown;
}

private void Picturebox1_mousemove (object sender, MouseEventArgs e)
... {
if (bdragging)
... {
Point Omovetopoint;
Omovetopoint = this. PointToClient (Picturebox1.pointtoscreen) (New Point (e.x, e.y));
Omovetopoint.offset (Pclicked.x *-1, Pclicked.y *-1);
Picturebox1.location = Omovetopoint;
}
}
private void Picturebox1_mouseup (object sender, MouseEventArgs e)
... {
Bdragging = false;
This.pictureBox1.Cursor = Curup;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.