First Kind
Example of volume adjustment
#regionVolume controlPrivatePoint Mouse_offset; Private voidPicturebox7_mousedown (Objectsender, MouseEventArgs e) {Mouse_offset=NewPoint (-e.x,-e.y);// } Private voidPicturebox7_mousemove (Objectsender, MouseEventArgs e) {(Control) sender). Cursor= Cursors.arrow;//set mouse arrows when dragging if(E.button = =mousebuttons.left) {point Mousepos=control.mouseposition; Mousepos.offset (Mouse_offset. X, Mouse_offset. Y);//Set OffsetMousepos.y =Pointtoscreen (picturebox7.location). Y Point Mouse_new=(Control) sender. Parent.pointtoclient (Mousepos); if(Mouse_new.x <Panel1. location.x) {mouse_new.x=Panel1. location.x; } if(Mouse_new.x > Panel1. Width +Panel1. location.x) {mouse_new.x= Panel1. width+Panel1. location.x; } ((Control) sender). Location=mouse_new; Panel2. Width= mouse_new.x-Panel1. location.x; } } #endregion
The second Kind
namespace using System.Runtime.InteropServices;
Drag #region Form
[DllImport ("User32.dll")]
Public static extern bool ReleaseCapture ();
[DllImport ("User32.dll")]
Public static extern bool SendMessage (INTPTR hwnd, int wmsg, int wParam, int lParam);
// <summary>
// Pa_top Events
// </summary>
/// <param name= "Sender" ></param>
/// <param name= "E" ></param>
private void Pa_top_mousedown (object sender, MouseEventArgs e)
{
releasecapture ();
SendMessage (this. Handle, 0x0112, 0xf012, 0);
}
#endregion
Both forms and controls can be dragged in both ways
The second way is more suitable for dragging the form