WinForms layouts randomly screwed up - c#

I have written several WinForms apps in my life, and every once in awhile something will go wrong with the layout at run-time. Today, while I was fiddling with the fonts in my application (mainly whether fonts were bold or not), I found that a control (which was anchored to all four sides of a TabPage) was extra-wide at runtime, going beyond the right edge of the page. I fiddled with the fonts again and the problem disappeared. Then I tried to replicate what I thought caused the problem in the first place, but it did not recur.
Another problem I sometimes have is that a Form with no MaximizeBox will randomly start maximized--maybe not on a development machine, but on a user's machine.
Can anyone tell me if they've had one of these problems and found the cause or solution?

Make sure you are familiar with the Anchor and WindowState properties, and set them to the correct values.

Related

MSAA -- Dragon Cannot Interact with TableLayoutPanel

I am modifying a Winforms application to be accessible via Dragon Professional 15. I have also recently added support for screen readers (including JAWS and MAGic) so the application has been, for the most part, reviewed in order to ensure that the AccessibleName (and, where appropriate, AccessibleRole) property is filled out.
Dragon does fairly well with most of this application but there are parts with which it utterly fails to operate. After a lot of trial and error, I was able to determine that the cause of the problem was the use of TableLayoutPanels in my application. Any control that resides in a TableLayoutPanel is not consumable by Dragon (ie. when I speak the AccessibleName value, Dragon cannot find the control). As an example, the button in this document tree works just fine in the following configuration:
(NB: The noFocusCueButton class derives from Button and has only minor changes concerning visual aspects of the class.)
In this configuration, I can speak the AccessibleName of the noFocusCueButton and Dragon will recognize it and click it. However, as soon as I move to this configuration:
...Dragon can no longer detect and interact with the noFocusCueButton. I have searched for some property on the TableLayoutPanel that might explain this but I do not see anything obvious. I have also searched for other people encountering this problem but have not come up with anything. Any SO experts out there know anything about this?
In what can only be described as "the story of my life", I found the problem in less than a few minutes after posting the question (though I had spent hours on it beforehand).
Evidently, at some point, the AccessibleRole property of the TableLayoutPanel had been set to List. Setting it back to Default fixed the problem.

Form size in design mode is not the same when run

I have been developing winform applications for a long time and I've never noticed something very simple, almost basic so I went back to the basics, I made a big form with a button on the extreme and I noticed that the size of the form changes completely when run:
design
run
As you can see the form size gets smaller and the button is hidden.
The properties are the default ones AutoSize false and AutoScaleMode Font.
This question is similar to this but unfortunately the answer there is not useful since the recommendation is the default.
Note: This is automatically solved when my notebook gets connected to another display
Below are some steps you can try if one of them can solve your issue:
If the problem occurs only when you connecting with other monitor, try to change the settings when connecting, does this happens to other PCs too? Or try to use another PC or install a VM (Virtual Machine) to run it there.
Check your DPI settings, for example in Windows 7, is that Smaller - 100% (default), or Medium - 125%, or Larger - 150%?
Try to set Form's property AutoScaleMode to Dpi or Font for each case.
If the problem still persists, try to create the sample form with the help from Creating a DPI-Aware Application.
I once tried to use FlowLayoutPanel control to arrange some identical elements such as buttons, pictureboxes. If possible, try to use it when applicable.
Last one, try WPF instead, it seems complicated at first, but you will get used to it soon and find out interesting things that Winforms doesn't have. You can arrange control to a grid (similar to a table), then put your controls to each cell with no problem. My suggestion if you plan to learn from ABC: WPF Tutorial.
Leave comment if you need more help, I will come back to see if any further I can provide. Because I've come into this obstacle when creating an app before :)
Set button "Anchor" (Right*, bottom) in property window

WPF usercontrol layout changed in production

I build a usercontrol in our develop environment, and it looked exactly as I wanted it to look.
In our test and acceptation environment it looks exactly the same.
But, when we released it to our production environment the buttons at the bottom of the screen moved up a bit and are now slightly over a textbox.
How can I make my usercontrol so that it looks the way I want to in every environment? And what made this error possible? I believe we use the same version of Windows.
As we couldn't find a solution, we decided to check our architecture of the form and found some ambiguities. I had made a mess of the stack panels and solved it with lots of white space. After making a proper form the problem didn't occur anymore.

Why is Visual Studio altering my Winforms when editing them on another computer?

I am having a rather odd issue that I have been unable to find the answer to. I have 2 PCs that I am doing coding on - one a desktop PC and one a notebook (QuadHD resolution). Each has Windows 8.1 & Visual Studio 2013 Update 5 installed.
I have localized all my Forms and it seems that when I edit the Winform on my notebook, it causes very odd resizing issues to occur. For example, if I simply change the "Language" property from one language to another (that I have already translated), the entire form is skewed and re-sized, completely destroying all the layout of the form in the selected language. On another form, the "ImageScaling" property is erroneously changed from 16x16 to 40x40.
The issue seems to be related to the changing of the 'Language' property. Almost like there's some sort of resizing logic & layout logic being applied when this property is changed.
When I perform the same operation on my desktop PC, I get no such odd modifications (as I'd expect). This obviously renders my notebook completely useless for being able to do any WinForms work!
I initially thought this might be related to some quirk with the QuadHD display (i.e. 3.2k x 1.8k). I have tried to reduce the screen resolution to a regular HD quality, however this doesn't seem to resolve the issue.
Does anyone have any hints about what I could try to fix this problem?
Thanks.
The only workaround I have been able to come across so far is to ensure that your Windows Settings->Display->Scaling is 100% BEFORE making any modifications to the form (including changing any seemingly innocuous properties such as 'Language').
On high-resolution screens, this unfortunately makes the content almost unreadable but at least the forms are not completely ruined/resized when you edit them.
You will unfortunately need to do all your edits in this mode and commit them before reverting your scaling back to its original setting.

Form controls displaced when installed on another computer

I know there will be folks who will vote this question down or ask for close. But if there is any kind of information or code I can provide you to know more about my program I will let you know. So please keep reading and see if you have had a similar problem.
I am running a Win7 64bit with .Net Framework ver 4.5.
I have created a Winform application. And to create my form elements I have taken advantage of a library called Metroframework that gives the program a metro look and feel. It contains some standard controls and as well as user controls that inherit from the original Form class. This is the opening view of my program.
However, for some strange reason, when I came to install my program on two other computers (one running Win7 and the other Win8), I noticed that some of my form elements have changed their location and some have just disappeared or just have been displaced. This has frightened me knowing the amount of time I have spent to put this elements in place.
Everything looks fine on my own computer both in dev environment and after building my application in release version. At first I thought this is a screen resolution problem on the other two devices, but that was not the case either. And even if it was, why should this happen?
Can anyone please help me solve this problem? I will share any part of my code you need. But I really have no idea where the source of this problem is!
The main influence on the layout variations on different machines is theForm.AutoScaleModeproperty.
In theory the default setting should work fine but I found that sometimes it is best to switch it off completely, that is going from Dpi or Font to None..
MSDN explains a little about the intended effect.
BTW: The is also a ContainerControl.AutoScaleMode property, so you could choose different modes for some parts of your forms as described here:
The AutoScaleMode property specifies the current automatic scaling
mode of this control. Scaling by Font is useful if you want to have a
control or form stretch or shrink according to the size of the fonts
in the operating system, and should be used when the absolute size of
the control or form does not matter. Scaling by Dpi is useful when you
want to size a control or form relative to the screen. For example,
you may want to use dots per inch (DPI) scaling on a control
displaying a chart or other graphic so that it always occupies a
certain percentage of the screen.
To remain true to the pixel-precise layout use:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
The last value in the AutoScaleMode enumeration is Inherited which most often would be chosen for nested containers.
Update: The choice of ContainerControlsis rather limited:
System.Windows.Forms.Form
System.Windows.Forms.PropertyGrid
System.Windows.Forms.SplitContainer
System.Windows.Forms.ToolStripContainer
System.Windows.Forms.ToolStripPanel
System.Windows.Forms.UpDownBase
System.Windows.Forms.UserControl
Maybe the most useful is the UserControl. Note that it doesn't expose the AutoScale property in its instances but only in the class definition. Also note that you can't add controls to an instance in the desiger, but you could assemble them in maybe a Panel and then set a UserControl (with AutoScale=Font) to be the Panel's Parent.. You'll need to allow for some extra space in any case, though..

Categories

Resources