2012-10-11 25 views
6

के साथ रहता है मैं एक छात्र हूं और मैं यहां चारों ओर नया हूं। मेरे पास एक पेंट-जैसी प्रोग्राम बनाने के लिए एक कोर्स प्रोजेक्ट है। मेरे पास आधार श्रेणी आकार ड्रासल्फ के साथ है, ect शामिल है। आयत और एलीप्स और त्रिकोण के लिए विधियों और कक्षाएं अब के लिए। इसके अलावा मेरे पास दो अन्य वर्गीकृत डिस्प्लेप्रोसेसर है जो ड्राइंग के लिए कक्षा है, और डायलॉगप्रोसेसर, जो उपयोगकर्ता के साथ संवाद को नियंत्रित करता है। परियोजना के लिए थीस की आवश्यकता है।आकार घूर्णन करते समय, यह घूर्णन वाले

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); 
    } 
} 

और एक दूसरे निर्धारण, यहाँ:

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); 
    } 
} 

तो, मैं एक आकृति है, जो उपयोगकर्ता द्वारा चयन किया जाता है बारी बारी से करना चाहते हैं। मैं इस तरह कोशिश करता हूं। यह घूमता है, लेकिन मैं यह मिलता है: 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(); 
    } 
} 

उत्तर

1

मैंने इसे हल कर लिया है! समस्या यह थी कि मैं प्रत्येक आकार के लिए चयन आकर्षित करता हूं और जब मैं आकार घुमाता हूं, तो चयन अनचाहे रहता था। मैंने चयन के लिए DrawSelf विधि में वही परिवर्तन किया है और सबकुछ ठीक था! चीयर्स!

2

मैं कठिनाई अपने प्रश्न की व्याख्या हो रही है। मेरा अनुमान है कि जब आप पहले आकार को घुमाते हैं और इसे खींचते हैं। फिर एक और आकार खींचें, दूसरा आकार भी घुमाया जाता है।

ऐसा इसलिए है क्योंकि, सभी DrawSelf विधि एक ही ग्राफिक्स संदर्भ के साथ काम कर रही हैं, और एक विधि पर उपयोग किए गए किसी भी रूपांतरण के लिए उसी संदर्भ पर सभी लगातार कॉलों को प्रभावित करेगा।

आप प्रत्येक DrawSelf मेथिड के अंत में Graphics.ResetTransform विधि को कॉल करके इसे हल कर सकते हैं।

public override void DrawSelf(Graphics grfx) 
    { 
     base.DrawSelf(grfx); 

     //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.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(); 
    } 
+0

मैंने अपना प्रश्न संपादित किया है। मुझे उम्मीद है कि अब और स्पष्ट है। – vortex

संबंधित मुद्दे