Okay so I've been running into trouble, I've figured out the majority of it. However, I can't seem to figure out how to save the location of a button. I could do it my way but my way is really ghetto and not recommended. The way I would do it is to go into settings, then set up an X integer and a Y integer to store the location of the object that was moved, so that the user can go back and re-open the program and the button be in it's new place. I also have an error with my algorithm for moving the control, for right now it's just experimental and follows the mouse on mouse move. Eventually I will put it on mouse down. But for now, I want the button to jump back to original position if it crosses a set line on the form. Well that much I have working. I can't figure out how to move the button around afterward.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace DLLOpen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public const int buttonDown = 0xA1;
public const int caption = 0x2;
public int rotation;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
protected override void OnMouseMove(MouseEventArgs mouseEv)
{
int mouseX = mouseEv.X;
int mouseY = mouseEv.Y;
int myMouseX = button1.Location.X - 10;
int myMouseY = button1.Location.Y - 10;
label1.Text = "Mouse X: " + myMouseX.ToString();
label2.Text = "Mouse Y: " + myMouseY.ToString();
if (rotation == 0)
{
button1.Location = new System.Drawing.Point(mouseX + 10, mouseY + 10);
if (mouseEv.Y <= 360)
{
rotation = 0;
button1.Location = new System.Drawing.Point(mouseX + 10, mouseY + 10);
label1.Text = "Mouse X: " + myMouseX.ToString();
label2.Text = "Mouse Y: " + myMouseY.ToString();
}
else if (mouseEv.Y >= 360)
{
button1.Location = new Point(215, 165);
rotation = 2;
label1.Text = "Mouse X: " + myMouseX.ToString();
label2.Text = "Mouse Y: " + myMouseY.ToString();
}
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
button1.Location = button1.Location;
rotation = 1;
}
}
}