Ich bin ein Student, und ich bin neu hier. Ich habe ein Kursprojekt, um ein Paint-ähnliches Programm zu erstellen. Ich habe eine Basisklasse Shape mit DrawSelf, enthält ect. Methoden und Klassen für Rechteck, Ellipse und Dreieck für jetzt. Auch ich habe zwei andere klassifiziert DisplayProccesor welche Klasse für Zeichnung ist, und DialogProcessor, die den Dialog mit dem Benutzer steuert. Dies sind Anforderungen an das Projekt.Wenn rotierende Form, bleibt es zusammen mit der gedrehten
public class DisplayProcessor
{
public DisplayProcessor()
{
}
/// <summary>
/// List of shapes
/// </summary>
private List<Shape> shapeList = new List<Shape>();
public List<Shape> ShapeList
{
get { return shapeList; }
set { shapeList = value; }
}
/// <summary>
/// Redraws all shapes in shapeList
/// </summary>
public void ReDraw(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
Draw(e.Graphics);
}
public virtual void Draw(Graphics grfx)
{
int n = shapeList.Count;
Shape shape;
for (int i = 0; i <= n - 1; i++)
{
shape = shapeList[i];
DrawShape(grfx, shape);
}
}
public virtual void DrawShape(Graphics grfx, Shape item)
{
item.DrawSelf(grfx);
}
}
Und Hier `s der andere:
public class DialogProcessor : DisplayProcessor
{
public DialogProcessor()
{
}
private Shape selection;
public Shape Selection
{
get { return selection; }
set { selection = value; }
}
private bool isDragging;
public bool IsDragging
{
get { return isDragging; }
set { isDragging = value; }
}
private PointF lastLocation;
public PointF LastLocation
{
get { return lastLocation; }
set { lastLocation = value; }
}
public void AddRandomRectangle()
{
Random rnd = new Random();
int x = rnd.Next(100, 1000);
int y = rnd.Next(100, 600);
RectangleShape rect = new RectangleShape(new Rectangle(x, y, 100, 200));
rect.FillColor = Color.White;
ShapeList.Add(rect);
}
}
Also, ich möchte eine Form drehen, die durch den Benutzer ausgewählt wird. Ich versuche es so. Es dreht sich, aber ich bekomme diese: http://www.freeimagehosting.net/qj3zp
public class RectangleShape : Shape
{
public override void DrawSelf(Graphics grfx)
{
grfx.TranslateTransform(Rectangle.X + Rectangle.Width/2, Rectangle.Y + Rectangle.Height/2);
grfx.RotateTransform(base.RotationAngle);
grfx.TranslateTransform(- (Rectangle.X + Rectangle.Width/2), -(Rectangle.Y + Rectangle.Height/2));
grfx.FillRectangle(new SolidBrush(FillColor), Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height);
grfx.DrawRectangle(Pens.Black, Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height);
grfx.ResetTransform();
}
}
Ich habe meine Frage bearbeitet. Ich hoffe es ist jetzt klarer. – vortex