I have a 480 x 480 Panel in a Form upon which I draw. However, only things I draw in the area between (0,0) and (200, 100) appear. The application records the actions I perform outside this area, but their results do not appear.

It seems as if only the 200 x 100 area is being refreshed.

Any suggestions?

Recommended Answers

All 2 Replies

Hi clownContagion, welcome here!
If you posted some code, this would really help.
What would you do, if I asked you to repair my bike, but I would not show it to you?

EDIT: please use code tags if you post code.

Yeah, that was my fault. It completely slipped my mind.

Here's the Form class.

class A : Form
    {
        private static int FRAME_WIDTH = 600;
        private static int FRAME_HEIGHT = 600;
        private static int CANVAS_WIDTH = 480;
        private static int CANVAS_HEIGHT = 480;

        private Canvas canvas = new Canvas();
        private Panel btnsPanel = new Panel();

        private Button cursorButton = new Button();
        private Button nodeButton = new Button();
        private Button linkButton = new Button();
        private Button deleteButton = new Button();
        private Button clearButton = new Button();

        public A() : base()
        {
            this.Size = new Size(FRAME_WIDTH, FRAME_HEIGHT);
            SetupButtons();
            SetupCanvas();
        }

        public void SetupButtons()
        {
            cursorButton.Text = "Cursor";
            nodeButton.Text = "Node";
            linkButton.Text = "Link";
            deleteButton.Text = "Delete";
            clearButton.Text = "Clear";

            cursorButton.Click += ButtonClick_handler;
            nodeButton.Click += ButtonClick_handler;
            linkButton.Click += ButtonClick_handler;
            deleteButton.Click += ButtonClick_handler;
            clearButton.Click += ButtonClick_handler;

            btnsPanel.Size = new Size(100, 300);

            clearButton.Location = new Point(10, 50);
            cursorButton.Location = new Point(10, 110);
            nodeButton.Location = new Point(10, 140);
            linkButton.Location = new Point(10, 170);
            deleteButton.Location = new Point(10, 200);

            btnsPanel.Controls.Add(cursorButton);
            btnsPanel.Controls.Add(nodeButton);
            btnsPanel.Controls.Add(linkButton);
            btnsPanel.Controls.Add(deleteButton);
            btnsPanel.Controls.Add(clearButton);

            this.Controls.Add(btnsPanel);
        }

        public void SetupCanvas()
        {
            canvas.Location = new Point(100, 50);
            canvas.Size = new Size(CANVAS_WIDTH, CANVAS_HEIGHT);
            canvas.BackColor = Color.White;
            this.Controls.Add(canvas);
        }

        public static void Main()
        {
            Application.Run(new A());
        }
    }

And the Canvas (A type of Panel)

class Canvas : Panel
    {
        private Graphics g;
        private List<Element> elements = new List<Element>();

        public Canvas() : base()
        {
            g = CreateGraphics();
        }

        public void AddElement(Element e)
        {
            elements.Add(e);
            Refresh();
        }

        public void RemoveElement(Element e)
        {
            elements.Remove(e);
            Refresh();
        }

        public void Clear()
        {
            elements.Clear();
            Refresh();
        }

        public override void Refresh()
        {
            base.Refresh();
            foreach (Element e in elements)
            {
                e.Draw(g);
            }
        }
    }

As far as Graphics are concerned, an element is either a circle centered at the mouse click or a line stretching from the initial mouse click to the mouse's current location, provided it is being dragged.

I've omitted a few superfluous methods and data members for clarity; the drawing works as intended, just in the 200 x 100 area in the upper left of the Canvas, which leads me to believe the issue lies in one of the two classes above. I'm sure it's going to be either very silly or very nuanced.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.