I am developing an application with Visual Studio 2010. my application works fine in 1024 x 768 resolution but it doesn't fit in my laptop's screen which happen to have 1366 x 768. my question is how to make my application automatically resize according to the resolution ?

Thanks !

Recommended Answers

All 10 Replies

Use the Screen class to get the size of the display and resize the form.

I can't insert the lib

using System.Windows.Forms;

Error 1 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) C:\Users\westony\documents\visual studio 2010\Projects\LearningCsharp\LearningCsharp\MainWindow.xaml.cs 15

I am using VS 2010 Ultimate?


Are there any other options ?

Are you doing a console or a WinForms application?

If you are doing a console application, you are on your own. If WinForms then you have major issues since it should already be included.

its WPF

In this case you need to either, include the windows forms library reference or use P/Invoke.

Out of interest though, why don't you just set this.WindowState = WindowState.Maximized (This can be set in XAML as well in the Window tag WindowState="Maximized" This will make your form fill the full screen. The rest is up to you be defining anchor points, minimum and maximum sizes and using the various layout controls :)

That's the problem I am new in the layouts cuz I never been before a front-end dev...


Okay i will make it full size but how to make elements too be fluid(changing sizes and look every time the same) to the different resolutions

You can anchor controls, these are the little circles on each edge of the control. They will expand or reduce automatically to keep their distance from the edge of the form.

I suggest experimenting a little, it will prove better than me trying to explain it to you (which would be a very very long essay)

I can't disagree with you, but I cant insert

using System.Windows.Forms;

I can't disagree with you, but I cant insert

Like I said, you have to add the reference to your project, just like you would any other library.

Use the Screen class to get the size of the display and resize the form.

Okay I have another question, because I have exp with Flash Builder 4.5 I know that I can use dynamics in MXML where I can say

<s:canvas id="cans" width="500">
    <button content="Click Me!" width="{cans.width - 200}" />
<s:/canvas>

But its look like that in WPF I cant use that width="{cans.width - 200}"

Or I can't find it ...

So is there way that I can use this method or I have to use some other one ?

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.