I've taken over maintenance of a Winforms application running on .Net version 4. The startup object is the login form. I have three monitors. The login form opens centered on whatever monitor my mouse pointer is sitting on. I can't find any code in the form that sets it's position. I haven't seen a form do this before. Is there a setting that makes this happen or is this just normal behavior?
Check the form's StartPosition - seems like it's set on FormStartPosition.CenterScreen.
From MSDNs page on FormStartPosition Enumeration:
Member name Description
CenterParent The form is centered within the bounds of its parent form.
CenterScreen The form is centered on the current display, and has the dimensions specified in the form's size.
Manual The position of the form is determined by the Location property.
WindowsDefaultBounds The form is positioned at the Windows default location and has the bounds determined by Windows default.
WindowsDefaultLocation The form is positioned at the Windows default location and has the dimensions specified in the form's size.
Note that CenterScreen describes exactly what you described.
Related
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?
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
I added a new form to my Windows CE/CF/C# app, but the form is too large -- I have to drag it around to see all of it - I thought the CF automatically made forms scale to the size of the device?
Is there a property or properties I need to set, or a particular size I need to give the form so that it will take up the entire screen but no more than that?
No, the Forms are not auto-sized for WinCE (WinMo they are). You can set it's size manually, or Maximize it to get the effect you're after.
I need to fit the window's width and height to its content. I'm aware of existance of SizeToClient property of Window, however, if one chooses WidthAndHeight as the value of SizeToClient, window events are fired in invalid way, such that several components raise an exception during Loaded event: "Hwnd of zero is not valid" (for example GlassWindow's SetAeroGlassTransparency from Windows API CodePack).
Is there a workaround? I may calculate the window size manually, but I do not know, how to retrieve the window's chrome sizes (in other words, the real window's content margin sizes).
Details of WPF bug
Best regards -- Spook.
You could use SystemParameters to determine the size of the chrome. For example, SystemParameters.CaptionHeight.
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);
}