Hi,

In on of the lecture notes that was given to me by my prof, I was told that setting the ResizeRedraw value to true would allow whatever I drew on the form to be, well, resized. However, it does not seem to work. Here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test1
{
    public partial class Form1 : Form
    {
        private Rectangle m_Rect;

        public Form1()
        {
            Point p = new Point(ClientRectangle.Width / 2 - 100 / 2,
            ClientRectangle.Height / 2 - 100 / 2);
            Size s = new Size(100, 100);
            m_Rect = new Rectangle(p, s);

            
            InitializeComponent();
            ResizeRedraw = true;
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Brush b = new SolidBrush(Color.Red);
            Pen pen = new Pen(new SolidBrush(Color.Black));
            
            e.Graphics.DrawRectangle(pen, m_Rect);
            e.Graphics.FillRectangle(b, m_Rect);
        }
    }
}

ResizeRedraw does not resize anything, it just tells the control to redraw if its size is changed.

Ok, ty. Now, how do I make the syntax work? It's not doing what it's supposed to.

its not clear whats not working, it most likely is working as the code you showed looked to be compilable, and the redraw would tell the component to redraw if it were resized..

its not clear whats not working, it most likely is working as the code you showed looked to be compilable, and the redraw would tell the component to redraw if it were resized..

Well, the code does compile. It's just that when I maximize or minimize the window or drag the sides of the window and let go, the rectangle, which is centered, doesn't get redrawn. I don't know if it has to do with the ResizeRedraw = true; statement being in the constructor but according to my professor, it's supposed to work. Strangely enough, the resizing works when I place all the statements in the constructor to build the Rectangle in the Form1_Paint() method. Problem is, I don't understand why that is and why it isn't working when those statements are in the constructor. :'(

Possibly because the components arent initialized by that point, try it in the form load event.

This article has been dead for over six months. Start a new discussion instead.