Controls don't overlap on design form, but do at runtime

  • Thread starter Thread starter Randy Hersom
  • Start date Start date
R

Randy Hersom

I left a Microsft DevDays some months ago with the idea that if you anchored
all of your controls to all four sides, then the screen would size up
proportionally when the form was maximized or made larger. My current test
form most emphatically does not do this - controls overlap on each other in
a most ugly fashion. My scroll bar next to a multi line text box ends up
half the width of the screen. The data grid on the top half and the edit box
on the bottom half both expand to well over half the screen. Does anybody
have any ideas on how to make a form size up gracefully?
 
Hi,

Anchoring simply forces the edges of your control to maintain a certain
distance from the given side of their parent. For your needs, you might have
to handle a Layout event for the controls involved. You might also want to
look into Docking, if you haven't already done so.

There's lots of info on layout using Anchoring/Docking/Custom methods on the
internet, I recommend you visit www.google.com.

-- Pete
 
I have concluded that Anchoring and Docking are not what I need.

My form is set to Maximized.
I dropped this chunk of code into my Form1.h

private:

void Form1_Layout(Object* sender, System::Windows::Forms::LayoutEventArgs*
e) {

this->dataGrid1->Left = (8);

this->dataGrid1->Top = (8);

this->dataGrid1->Height = ((int) this->get_Height()*.48);

this->dataGrid1->Width = ((int) this->get_Width()*.96);

this->textBox1->Top = ((int) this->get_Height()*.50);

this->textBox1->Left = (8);

this->textBox1->Height = ((int) this->get_Height()*.48);

this->textBox1->Width = ((int) this->get_Width()*.92);

this->vScrollBar1->Top = ((int) this->get_Height()*.50);

this->vScrollBar1->Left = ((int) 8+this->get_Width()*.92);

this->vScrollBar1->Height = ((int) this->get_Height()*.48);

this->vScrollBar1->Width = ((int) this->get_Width()*.04);

}

This doesn't seem to have the desired effect, or any effect at all for this
matter. What am I missing?



Thanks

Randy Hersom
 
So the C++ walkthrough that I needed went something like this:

Having written the fuction, MyResizeFunction, that resizes the screen the
way you want it done:

Search for "InitializeComponent" within Form1.h. The first find will be a
call to the function. Search again. This will be the function code.
If you see three dots on the line, click on them to expand the code so you
can edit it.
Find the call to this->ResumeLayout near the end of this function. It may
be a very long function.
Just before that line, insert a new line
this->Resize += new System::EventHandler (this,MyResizeFunction);

Compile and test. Your MyResizeFunction will now be called each time the
screen is resized.
 
Back
Top