943,670 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1396
  • C# RSS
Sep 21st, 2008
0

Can't resize with ResizeDraw

Expand Post »
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:

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Test1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. private Rectangle m_Rect;
  15.  
  16. public Form1()
  17. {
  18. Point p = new Point(ClientRectangle.Width / 2 - 100 / 2,
  19. ClientRectangle.Height / 2 - 100 / 2);
  20. Size s = new Size(100, 100);
  21. m_Rect = new Rectangle(p, s);
  22.  
  23.  
  24. InitializeComponent();
  25. ResizeRedraw = true;
  26. }
  27.  
  28. private void Form1_Paint(object sender, PaintEventArgs e)
  29. {
  30. Brush b = new SolidBrush(Color.Red);
  31. Pen pen = new Pen(new SolidBrush(Color.Black));
  32.  
  33. e.Graphics.DrawRectangle(pen, m_Rect);
  34. e.Graphics.FillRectangle(b, m_Rect);
  35. }
  36. }
  37. }
Reputation Points: 10
Solved Threads: 0
Junior Poster
degamer106 is offline Offline
131 posts
since Mar 2006
Sep 22nd, 2008
0

Re: Can't resize with ResizeDraw

ResizeRedraw does not resize anything, it just tells the control to redraw if its size is changed.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Sep 22nd, 2008
0

Re: Can't resize with ResizeDraw

Ok, ty. Now, how do I make the syntax work? It's not doing what it's supposed to.
Reputation Points: 10
Solved Threads: 0
Junior Poster
degamer106 is offline Offline
131 posts
since Mar 2006
Sep 22nd, 2008
0

Re: Can't resize with ResizeDraw

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..
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Sep 22nd, 2008
0

Re: Can't resize with ResizeDraw

Click to Expand / Collapse  Quote originally posted by LizR ...
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.
Reputation Points: 10
Solved Threads: 0
Junior Poster
degamer106 is offline Offline
131 posts
since Mar 2006
Sep 22nd, 2008
0

Re: Can't resize with ResizeDraw

Possibly because the components arent initialized by that point, try it in the form load event.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Dynamic Loop + Array
Next Thread in C# Forum Timeline: Business object in web application





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC