WinForms Label shifts position on screen after deployment - winforms

In writing WinForms Apps in Visual Studio 2010, .NET, I often place a label on a form, set its AutoSize property to false and then drag it across a portion of the form.
The label may contain 2 or more paragraphs, which I line up against the left side of the screen.
Its Anchor property is set to Left, or Top, Left depending on where I place it on the form.
On my development machine (Windows 10) the label has the appearance that I desire. However, upon deploying it to another machine (whose monitor may have a different resolution) the text in the label is now shifted. A second or even third paragraph in the label no longer displays lined up against the left side of the form, but is spread out, as though I had tabbed the text to a different position.
My question is this: Is there anyway that I can prevent this behavior from occurring when deploying my App to another computer?
How can I get the deployed App to keep the label's text from shifting or spreading out?

Related

How to fix the order of items within a ToolStripContainer

I have a ToolStripContainer with a MenuStrip and a ToolStrip inside, both at the top. They're arranged as usual on Windows with the menu bar above the toolbar. Now, Windows Forms and DPI scaling support has always been a bit iffy. While everything looks fine at 100 %, I'm currently using 110 % DPI scaling and the menu bar and toolbar switch positions in the ToolStripContainer (I'd suspect it's the same with higher scaling factors, though):
My guess as to why this happens is that the designer places both controls at specific locations, even though they are arranged by the container, and with DPI scaling the ToolStripContainer gets locations for its children that would be consistent with placing the toolbar above the menu bar, as if someone dragged the bars around and reordered them (which is possible interactively, after all).
Short of replacing the MenuStrip with a MainMenu, is there a simple(ish) way of ensuring that regardless of DPI scaling the order of both remains consistent? I've got about 50 different windows to change in pretty much the same manner and would also rather avoid putting extra code into the codebehind file¹.
Things I've tried so far:
All changes in the designer have been applied at 100 % scale.
Change the z-order of the toolbar and menu bar in an attempt to control their order. This works with panels and docking, but doesn't apply to ToolStripContainer, apparently.
Docking the MenuStrip at the top. Doesn't work; the designer just removes Dock = None from the code and displays Top as the default value, but with scaling applied, it's back to Dock = None in the designer (and even without touching the Form in the designer, the result at runtime is the same).
¹ These are demo applications for a control library and the main point here is to keep the code clean and still providing a good experience out of the box. So a designer-only solution where the code is hidden away in already-awful code that no one reads would be preferable.
They are very frustrating components to work with. Because they can be dragged and moved it looks like the Location is the key, even though they behave a bit like they're docked. In OnLoad or OnShown have you simply tried resetting the desired location?
menuStrip.Location = new Point();
toolStrip.Location = new Point(0, toolStrip.Height);

ReportViewer Renders/Prints Charts Incorrectly In Print Layout

I have an rdlc file opened through a report viewer control (in a WPF application) that renders incorrectly on some machines when in print preview. On some machines the chart body is larger than the chart area and gets cut off. It is printed this way as well. On other machines, the chart is rendered and prints correctly.
All PCs are running the same .net version, have the same DPI settings, and have the same printer selected. All other content (a matrix, table etc.) render and print correctly on both all machines. What else should I be looking for?
Picture: Incorrect Rendering on Left, Correct on Right
I've seen similar issues if the user had different options set in the print dialog, things like shrink to fit or not, etc.

Hide a control without leaving empty space

I have a WinForms project based heavily on the DevExpress Windows Forms suite. I am working on a control that appears as below:
I use the term programme to differentiate between training programmes for people, from program, meaning computer program. In the image there are 3 ProgrammeGroup user controls. Each has a header, with 2 combos, and below that, a ProgrammeDetail user control with programme details.
When the top, left combo shows a value of Yes or blank, the programme details must be visible, otherwise not. When making a ProgrammeDetail control invisible, I also set its Height to zero, and the outer ProgrammeGroup control shrinks on auto-size.
However, if I set the Yes/No combo on the middle ProgrammeGroup to No, that
ProgrammeGroup shrinks, but leaves a gap between the header only middle control and the bottom control. This gap is visible in the following image:
How can I lay my ProgrammeGroup controls out so that if one shrinks in height, all those below it are moved up, meaning no empty gap. I am hoping that one of the many different panels in the DevExpress WinForms suite can help me do this, but I am stumped at finding one.
Solution to this problem is using FlowLayoutPanel which automatically align controls inside it next to each other.
The best way to adjust sizes and locations of child controls is to place them onto LayoutControl. This control is specially designed for such tasks. To hide unnecessary layout items/groups, use the BaseLayoutItem.Visibility property.
I should also note that LayoutControl is flexible and supports different modes including the Flow Layout Mode.
See Also:
Customization Form

Telerik theme is defeating right-alignment

I have a Windows form control that was built using Telerik RadTools for Windows Forms. The form is styled nicely using the "Office 2010 Silver" theme. However, at runtime, the theme seems to throw-off the alignment of some of my labels.
I have several rows of labels and textboxes on my form. I want the labels' right sides to all line up. This is easily done in the Visual Studio designer. However, I believe my Telerik theme is throwing things off because it slightly changes the font, which alters the labels' sizes as well. Since the designer only stores the x,y coordinates of my controls, the labels' right edges no longer line-up.
Is there a way to code around this?
I fixed this by doing the following on all labels:
Set AutoSize to false.
Set x-location to that of the widest label.
Set size equal to that of the widest label.
Set TextAlignment to right.
Since all labels will have the same width and the same starting (left) location, their positions will now be fixed. Setting the alignment to the right takes care of the problem.

WinForms Control position in Simplified Chinese

We have a WinForms application that includes controls such as picture boxes that are positioned on a form. The base application is in English.
We've translated this application to a number of different languages (French, Spanish, Danish, Greek, etc.) and most recently to Simplified Chinese. The translated application works perfectly on our operation systems (English).
One of our customers installed the application on their operation system, Windows XP in Simplified Chinese. The layout of our application is broken. Simply put, the elements are pushed to the bottom right by a factor that is proportional to the distance between the element and the top left corner. For example, an element at the top right corner in design view is pushed off screen to the right whereas the items at the bottom of the page are pushed downwards and to the right.
The application supports switching languages while in use. When the locale is en-US, there are no layout issues. When switching to Simplified Chinese, the issue appears, but only on the Simplified Chinese operating system. The screen resolution and DPI are the same.
Do you have any ideas? I'm sure it must be a simple configuration setting somewhere, but I have been unable to solve this issue.
The size of the system base font matters as well. Which is indeed something you can change on XP. This will invoke the form's auto-scaling logic, designed to ensure that the controls grow larger to fit the larger font size.
This is by design, controlled by the form's AutoScaleMode property. Don't change it, rescaling is important. Just make sure the form layout still looks good, use properties like Anchor and Dock, controls like TableLayoutPanel, FlowLayoutPanel. Or the Resize event for tricky ones.
Paste this into your form to test this logic without having to change system settings:
protected override void OnLoad(EventArgs e) {
this.Font = new Font(this.Font.FontFamily, this.Font.SizeInPoints * 125 / 96);
}

Resources