# .NET and More > WPF, WCF, WF >  [RESOLVED] Auto-Resize Controls at Runtime

## kumika

I have created a stackpanel (Dim myPanel as New StackPanel) and placed it inside a Grid with its width set to Auto. I set the width for the panel to: myPanel.Width = 500. Now when running the window in other screens the parent grid displays fine but the panel is much smaller than I want. How do I set the Width for the stackpanel sothat it resizes correctly in every screen.  I guess there is no code needed in order to figure out the solution. Thanks for assisting.

----------


## techgnome

Use the Anchor properties to determine how you want it to resize....

-tg

----------


## kumika

Anchor properties works with the Winforms not the WPF windows. This is a WPF app. However, the control is set dynamically.

----------


## techgnome

Since this is a WPF issue, I'm going to ask the mods to move it to the WPF section...

*sigh*

-tg

----------


## kumika

> Since this is a WPF issue, I'm going to ask the mods to move it to the WPF section...
> 
> *sigh*
> 
> -tg


Well, since we are talking about Runtime rather than XAML coding, this must be a vb.net. Issue NOT a WPF issue. I know how to set width relatively in XAML. What I want is Runtime coding which is a VB.net issue. I hope I am correct. I stand to be corrected though.

----------


## marniel647

> Well, since we are talking about Runtime rather than XAML coding, this must be a vb.net. Issue NOT a WPF issue. I know how to set width relatively in XAML. What I want is Runtime coding which is a VB.net issue. I hope I am correct. I stand to be corrected though.


tech suggested to move this to wpf section because this section is all about .net winforms. so i think you can have the answer immediately when this post is transfer to wpf section

----------


## Lightning

Can't you use horizontalAllignment=stretch?

----------


## Joacim Andersson

This site is called VBForums (plural) for a reason. It's all about VB. Well, we do also have a few forums for other languages but those are clearly marked as such. All the others are VB forums and that include the WPF forum. This question is clearly about WPF, even though it's not about the XAML side of that coin. This forum is the general VB.Net forum, for all VB.Net question that doesn't fit into any of the other more specific forums we have.

So for you, the OP, to get the best and quickest answer directly related to your question I have now moved it to the WPF forum.

----------


## kumika

Using the .stretch property does not help in my case. What I have done, which proves to be the best solution is: <myPanel.width=workarea.width>. Thanks

----------


## kumika

I have found the answer. All I needed to do was: <mypanel.width=workarea.width>. In this way the panel width resizes universally, at least according to the three screens I used to test. Thanks

----------


## Joacim Andersson

Your two duplicate posts have been merged into one.

----------

