Witam. Mam pewien problem z funkcjonalnością kodu, a że jestem początkujący nawet nie wiem jak określić temat pomocy.
Wiec tak:
Mam taka klasę(zajumaną skądś):
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace MuGoldenHand
{
public class cDrawPoint
{
private PictureBox mPictureBox;
public Rectangle rect;
public bool allowDeformingDuringMovement = false;
private bool mIsClick = false;
private bool mMove = false;
private int oldX;
private int oldY;
private int sizeNodeRect = 5;
Color color;
private PosSizableRect nodeSelected = PosSizableRect.None;
private enum PosSizableRect
{
None
};
public cDrawPoint(Rectangle r, PictureBox p, Color c)
{
color = c;
rect = r;
mIsClick = false;
this.mPictureBox = p;
mPictureBox.MouseDown += new MouseEventHandler(mPictureBox_MouseDown);
mPictureBox.MouseUp += new MouseEventHandler(mPictureBox_MouseUp);
mPictureBox.MouseMove += new MouseEventHandler(mPictureBox_MouseMove);
mPictureBox.Paint += new PaintEventHandler(mPictureBox_Paint);
}
public void Draw(Graphics g)
{
g.DrawRectangle(new Pen(color), rect);
foreach (PosSizableRect pos in Enum.GetValues(typeof(PosSizableRect)))
{
g.DrawRectangle(new Pen(color), GetRect(pos));
}
}
private void mPictureBox_Paint(object sender, PaintEventArgs e)
{
try
{
Draw(e.Graphics);
}
catch (Exception exp)
{
System.Console.WriteLine(exp.Message);
}
}
private void mPictureBox_MouseDown(object sender, MouseEventArgs e)
{
mIsClick = true;
nodeSelected = PosSizableRect.None;
nodeSelected = GetNodeSelectable(e.Location);
if (rect.Contains(new Point(e.X, e.Y)))
{
mMove = true;
}
oldX = e.X;
oldY = e.Y;
}
private void mPictureBox_MouseUp(object sender, MouseEventArgs e)
{
mIsClick = false;
mMove = false;
}
private void mPictureBox_MouseMove(object sender, MouseEventArgs e)
{
ChangeCursor(e.Location);
if (mIsClick == false)
{
return;
}
Rectangle backupRect = rect;
switch (nodeSelected)
{
default:
if (mMove)
{
rect.X = rect.X + e.X - oldX;
rect.Y = rect.Y + e.Y - oldY;
}
break;
}
oldX = e.X;
oldY = e.Y;
if (rect.Width < 5 || rect.Height < 5)
{
rect = backupRect;
}
TestIfRectInsideArea();
mPictureBox.Invalidate();
}
private void TestIfRectInsideArea()
{
// Test if rectangle still inside the area.
if (rect.X < 0) rect.X = 0;
if (rect.Y < 0) rect.Y = 0;
if (rect.Width <= 0) rect.Width = 1;
if (rect.Height <= 0) rect.Height = 1;
if (rect.X + rect.Width > mPictureBox.Width)
{
rect.Width = mPictureBox.Width - rect.X - 1; // -1 to be still show
if (allowDeformingDuringMovement == false)
{
mIsClick = false;
}
}
if (rect.Y + rect.Height > mPictureBox.Height)
{
rect.Height = mPictureBox.Height - rect.Y - 1;// -1 to be still show
if (allowDeformingDuringMovement == false)
{
mIsClick = false;
}
}
}
private Rectangle CreateRectSizableNode(int x, int y)
{
return new Rectangle(x - sizeNodeRect / 2, y - sizeNodeRect / 2, sizeNodeRect, sizeNodeRect);
}
private Rectangle GetRect(PosSizableRect p)
{
switch (p)
{
default:
return new Rectangle();
}
}
private PosSizableRect GetNodeSelectable(Point p)
{
foreach (PosSizableRect r in Enum.GetValues(typeof(PosSizableRect)))
{
if (GetRect(r).Contains(p))
{
return r;
}
}
return PosSizableRect.None;
}
private void ChangeCursor(Point p)
{
mPictureBox.Cursor = GetCursor(GetNodeSelectable(p));
}
/// <summary>
/// Get cursor for the handle
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
private Cursor GetCursor(PosSizableRect p)
{
switch (p)
{
default:
return Cursors.Default;
}
}
}
}
A teraz w czym problem
Jeśli zrobie tak
point.Add(new cDrawPoint(new Rectangle(xcord-1, ycord, 3,3), this.bMapBox, Color.Blue));
to nie moge ruszać kwadracikiem
a jeżeli dam tak i wyższe liczby to się da
point.Add(new cDrawPoint(new Rectangle(xcord-1, ycord, 5,5), this.bMapBox, Color.Blue));
Prosze o pomoc:D
usunięcie zbędnych pustych linii w kodzie - fp