in various case i have seen that when we run apps in various pc with different monitor size then win form behave differently. sometime the form get bigger and as a result few control on that form will not visible.so please tell me how to design win apps in such a way that what ever the monitor size would be the form size and control position will behave same way in all the pc monitor size.please guide me.thanks.
Use Anchor Property of the Control. Default Anchor is Top,Left. If you want Control Width to increase with Form, Set it to Top, Left, Right. Adjust the Anchors according to your requirement.
You have many options in terms of layout of controls. Anchoring is the most common way, but you should also investigate docking and table layout panels.
Related
I usually work with two monitors and two differents resolutions. 1366x768 and 1920x1080.
My prob is that my WPF application doesn't fit the monitor with biggest resolution when it runs on monitor 1366x768.
I found differents solutions but none of them work for me.
My last attempt is :
Screen actualScreen = Screen.FromHandle(new WindowInteropHelper(App.Current.MainWindow).Handle);
App.Current.MainWindow.Height = actualScreen.Bounds.Height;
App.Current.MainWindow.Width = actualScreen.Bounds.Width;
Any idea?
Rather than trying to layout your screen using a fixed resolution size, use other properties of the GUI controls to:
Dock along side another control (beside, above, or below).
Add minimum padding between the control and the control it docks next to.
Set a minimum size for the control. That can force scroll bars on the Application window if the user resizes it too small or the monitor's resolution is not large enough to fit your applications layout.
Those are some of the "responsive design" properties of a control in WPF.
My advice when laying out a Panel: start with placing the primary control and then fit the other controls on that Panel in relation to that primary Control (using the Alignment/Margin properties).
I know this is duplicated question but I checked all other related question and their answers did not help ( the result still the same as shown in screenshot 2)
I am new to c# windows forms. As shown in screenshot1, I have Form1 with some controls and each group of controls were put in a panel. I designed the application in PC1 as shown in Screenshot1 which is fit the screen resolution and worked well.
My application was developed in 1366 x 768 screen resolution (as shown in Screenshot1) but when I run this application in different computer (PC2) with different monitor size and different screen resolution the form appeared too big and part of the application is missing or is out of the screen.
However I solved this issue using Anchors but another issues came up which is: the user control does not re-size itself ( as shown in screenshot2) and part of it is cut or went under panel1 . I do not know if the problem is related to user control or related to all controls in Form1 (they should resize themselves)
I even tried the following code but the result still the same:
this.WindowState = FormWindowState.Maximized;
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
Screen.PrimaryScreen.WorkingArea
I have been searching to solve this issue the whole day yesterday but I failed, Please help me with any idea/suggestion it might work. Thank you
If you are working with Windows Forms and you cannot switch to WPF then you will prefer to do all the design in the lowest resolution at which you must run.
In WinForms you are setting the Size of every element so they will not re size according to the app size. What they will do is to be distributed along the empty space (if you program them to do so) increasing the free space between them, that's all.
Another option are LayoutPanels as Sinatr said as they try to offer the WPF panel functionality.
By default in WinForms, all controls that you place on the form while designing it have a fixed size. If you don't do anything special, whatever size the controls are when you place them are the size that they are always going to have, no matter what machine you're running on.
As you've noticed, that isn't always going to give good results. The way you work around it is to use a fluid layout, with liberal use of the TableLayoutPanel and/or FlowLayoutPanel container controls, as well as the Anchor and Dock properties for individual child controls. If you take special care to lay out the controls on your form correctly, they can be dynamically resized and rearranged to fit the available screen space.
This code
this.WindowState = FormWindowState.Maximized;
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
Screen.PrimaryScreen.WorkingArea
doesn't do anything. The only thing you need there is the very first line. Once you make the form maximized, it will fill the entire screen. You don't need to force it by setting its Size or Location properties. In fact, those have no effect on a maximized form.
The problem is presumably that the controls placed on your form do not resize themselves automatically (as discussed above). If you had a big enough screen, you'd see empty space where the form was filling the screen but had no controls on it. You have the opposite problem: on a smaller screen, controls don't fit and therefore overlap each other.
It isn't a perfect situation. Even if you code up a perfect dynamic layout, if you try to run the application on a system with a screen that is significantly smaller than your design intended, you're going to end up with buttons that are too small to poke. That's why applications are not, in general, designed this way. A screenful of buttons is terrible UI. The only time this kind of design is acceptable is when you're designing for a touch screen UI, like a restaurant POS. And in that case, you already have a pretty good idea what size screens your clients are going to be using, since it's all specialty hardware.
Has a program written in a notebook with a resolution of 1600x900, all the elements are placed normally, and the same program on a monitor with 1920x1080 scale from 125% windows are placed incorrectly. How on WinForms c# consider it and how to redraw?
You need to consider using the anchor and Dock properties this is how you position your controls on the form and control their positions in various scales
you can find here very useful article about using
anchoring and docking
By making use of anchors and docks then you should be able to create a WinForm which scales to any size monitor.
It would be helpful if you could edit your question and include the designer code so we can see what's happening.
In order to make the form resize as you want, You can use table layout panels to set your layout and then you can use the anchor property of the controls to set, where they should move when the form is resized.
The anchor property simply anchors the control to a location, for example if you anchor a text box to may be left, then on resize it will be at left. Or if you anchor it to say both left and right, if will expand in both directions. Just explore them and it should work fine for you.
I have a form on which i want to place certain controls. I want them to be positioned on the form according to the form size, that is, far apart when the form is maximised and close when it is smaller in size.
How to do it?
Thanks.
There are two properties on every windows form control Dock and Anchor Using these you could beautifully place controls and test for different sizes of forms. Check these links and do look out for behaviour by playing around with these properties.
Anchor & Dock
Dock Controls
I have a panel that has lots of labels and checkboxes. I want to grab all these controls and resize them?
How would I do this? Would this be like going through the panel for all the controls then resizing them?
Or do you think it would be better to re render the whole form again with the new sizes. However this would require me to do another request to the webservice to get the information.
I need to resize the controls because I want allow user to switch from portrait mode to landscape.
Use Dock, or for more precise control use the Anchor property. By setting Anchor to Left, Right, Top, Bottom the control will scale with the window. By setting Anchor to Right the control will move with the right border. By setting Anchor to Top and Bottom the control will scale vertically, but have a fixed width.
you can also use tablelayoutpanel and flowlayoutpanel controls.
For mobile, I think these controls are not available.
First of all, you should not just store the values from the web service in controls. They should be safely tucked away in one or more objects somewhere, to be easily accessed from your form.
I'm afraid you ahve to resize and/or change location of your controls depending on which mode you are in.
For developing resolution aware applications for .NET CF, see here:
http://msdn.microsoft.com/en-us/library/ms838174.aspx