Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct Area
- {
- public int minX;
- public int minY;
- public int maxX;
- public int maxY;
- public bool xForward;
- public bool yForward;
- public bool Lock;
- }
- Area Selection;
- private void PictureBox6_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- switch (e.Button) {
- case System.Windows.Forms.MouseButtons.Left:
- var _with1 = Selection;
- _with1.xForward = true;
- _with1.yForward = true;
- _with1.minX = e.Location.X;
- _with1.minY = e.Location.Y;
- _with1.Lock = true;
- if (CheckBox8.Checked == false) {
- PictureBox6.Image = My.Resources.Map;
- }
- break;
- }
- }
- private void PictureBox6_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if (Selection.Lock == true) {
- var _with2 = Selection;
- if (e.Location.X < 0) {
- _with2.minX = 0;
- } else if (e.Location.Y < 0) {
- _with2.minY = 0;
- } else if (PictureBox6.Width < e.Location.X) {
- _with2.maxX = PictureBox6.Width - 1;
- if (PictureBox6.Height > e.Location.Y) {
- if (e.Location.Y > _with2.minY) {
- if (_with2.yForward == true) {
- _with2.maxY = e.Location.Y;
- } else {
- if (e.Location.Y < _with2.maxY) {
- _with2.minY = e.Location.Y;
- } else {
- _with2.minY = _with2.maxY;
- _with2.maxY = e.Location.Y;
- _with2.yForward = true;
- }
- }
- } else {
- if (_with2.yForward == true) {
- _with2.maxY = _with2.minY;
- _with2.minY = e.Location.Y;
- _with2.yForward = false;
- } else {
- if (_with2.minY <= _with2.maxY) {
- _with2.minY = e.Location.Y;
- } else {
- _with2.maxY = e.Location.Y;
- }
- }
- }
- }
- } else if (PictureBox6.Height < e.Location.Y) {
- _with2.maxY = PictureBox6.Height - 1;
- if (PictureBox6.Width > e.Location.X) {
- if (e.Location.X > _with2.minX) {
- if (_with2.xForward == true) {
- _with2.maxX = e.Location.X;
- } else {
- if (e.Location.X < _with2.maxX) {
- _with2.minX = e.Location.X;
- } else {
- _with2.minX = _with2.maxX;
- _with2.maxX = e.Location.X;
- _with2.xForward = true;
- }
- }
- } else {
- if (_with2.xForward == true) {
- _with2.maxX = _with2.minX;
- _with2.minX = e.Location.X;
- _with2.xForward = false;
- } else {
- if (_with2.minX <= _with2.maxX) {
- _with2.minX = e.Location.X;
- } else {
- _with2.maxX = e.Location.X;
- }
- }
- }
- }
- } else {
- if (e.Location.X > _with2.minX) {
- if (_with2.xForward == true) {
- _with2.maxX = e.Location.X;
- } else {
- if (e.Location.X < _with2.maxX) {
- _with2.minX = e.Location.X;
- } else {
- _with2.minX = _with2.maxX;
- _with2.maxX = e.Location.X;
- _with2.xForward = true;
- }
- }
- } else {
- if (_with2.xForward == true) {
- _with2.maxX = _with2.minX;
- _with2.minX = e.Location.X;
- _with2.xForward = false;
- } else {
- if (_with2.minX <= _with2.maxX) {
- _with2.minX = e.Location.X;
- } else {
- _with2.maxX = e.Location.X;
- }
- }
- }
- if (e.Location.Y > _with2.minY) {
- if (_with2.yForward == true) {
- _with2.maxY = e.Location.Y;
- } else {
- if (e.Location.Y < _with2.maxY) {
- _with2.minY = e.Location.Y;
- } else {
- _with2.minY = _with2.maxY;
- _with2.maxY = e.Location.Y;
- _with2.yForward = true;
- }
- }
- } else {
- if (_with2.yForward == true) {
- _with2.maxY = _with2.minY;
- _with2.minY = e.Location.Y;
- _with2.yForward = false;
- } else {
- if (_with2.minY <= _with2.maxY) {
- _with2.minY = e.Location.Y;
- } else {
- _with2.maxY = e.Location.Y;
- }
- }
- }
- }
- PictureBox1.Refresh();
- PictureBox1.CreateGraphics.FillRectangle(new SolidBrush(Color.FromArgb(128, 255, 0, 0)), new Rectangle(_with2.minX, _with2.minY, _with2.maxX - _with2.minX, _with2.maxY - _with2.minY));
- PictureBox1.CreateGraphics.Dispose();
- }
- }
- private void PictureBox6_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if (Selection.Lock == true) {
- //Here you move the image
- Selection.Lock = false;
- }
- }
Add Comment
Please, Sign In to add comment