954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can't resize with ResizeDraw

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);
        }
    }
}
degamer106
Junior Poster
131 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

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

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

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

degamer106
Junior Poster
131 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

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..

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 
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. :'(

degamer106
Junior Poster
131 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

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

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You