Hi,
I’m using Visual Studio .NET 2003 and my application is a dialog window, with some buttons and a picturebox. I’ve activated the maximize window option and I’d like that when the window is maximized the picturebox will enlarge to occupy the same percentage of the window as in normal conditions. I think I should set the anchor property of the picturebox but this property is not present among control properties listed by Visual Studio (maybe because my form is a dialog window?). What can I do?
Thank you.

PictureBox has an Anchor property because it inherits from Control. If it's not listed in the designer view for some reason, you can set it in the form load event in your code view. When in doubt, go to the source! :)

PictureBox has an Anchor property because it inherits from Control. If it's not listed in the designer view for some reason, you can set it in the form load event in your code view. When in doubt, go to the source! :)

Hi Inanna,
thank you for your answer. Unfortunately I'm new in programming Visual Studio (I'm programming in C++). Can you please be more specific in describing what I should do? How can I set the Anchor property? And I've checked that my picture box actually is a "picture control" (name that appears in the dialog editor window of Visual Studio), does this make any difference?

Can you please be more specific in describing what I should do?

Happy to. :) Double click on the form you want to anchor the control in. To keep it simple, and to avoid accidentally double clicking on another control, just double click the title bar of your form. That'll take you to a new event handler called something like 'myform_Load'. Inside that subroutine, you can set your anchor property thusly.

myControl.Anchor = AnchorStyles.Top | AnchorStyles.Left

That sets the anchor to the default. Not really useful, but you can add more to the default. :) Say you want to anchor to the right too.

myControl.Anchor |= AnchorStyles.Right

Fiddle with it until you get an effect you like.

Happy to. :) Double click on the form you want to anchor the control in. To keep it simple, and to avoid accidentally double clicking on another control, just double click the title bar of your form. That'll take you to a new event handler called something like 'myform_Load'. Inside that subroutine, you can set your anchor property thusly.

myControl.Anchor = AnchorStyles.Top | AnchorStyles.Left

That sets the anchor to the default. Not really useful, but you can add more to the default. :) Say you want to anchor to the right too.

myControl.Anchor |= AnchorStyles.Right

Fiddle with it until you get an effect you like.

Hi!
Setting the Anchor property gives me the compiler error:
‘Anchor’: is not a member of ‘Cstatic’
This happens, I think, because I’m working with a dialog form and not with a standard document form. So in a dialog form control properties are different, and the anchor property is not present for static controls. I’ve found some useful tips in codeguru.com:
http://www.codeguru.com/cpp/w-d/dislog/
and it seems that the only possible solution is to write the full code to handle resizing. I’m going to try codeguru tips, I’ll tell you the result.
Thank you

Hi!
Setting the Anchor property gives me the compiler error:
‘Anchor’: is not a member of ‘Cstatic’
This happens, I think, because I’m working with a dialog form and not with a standard document form. So in a dialog form control properties are different, and the anchor property is not present for static controls. I’ve found some useful tips in codeguru.com:
http://www.codeguru.com/cpp/w-d/dislog/
and it seems that the only possible solution is to write the full code to handle resizing. I’m going to try codeguru tips, I’ll tell you the result.
Thank you

I've tried DlgResizeHelper class from
http://www.codeguru.com/cpp/w-d/dislog/resizabledialogs/article.php/c1913/
it perfectly works and it's what I was looking for in order to resize controls in my dialog window. Problem solved!
Thank you

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