Visual Studio Windows Forms Controls are overlapping on different machines [duplicate] - c#

I have a form application in C#. When I change the monitor's DPI, all the controls move.
I used the code this.AutoScaleMode = AutoScaleMode.Dpi, but it didn't avoid the problem.
Does anyone have an idea?

EDIT: As of .NET 4.7, windows forms has improved support for High DPI. Read more about it on learn.microsoft.com It only works for Win 10 Creators Update and higher though, so it might not be feasible to use this yet depending on your user base.
Difficult, but not impossible. Your best option is to move to WPF of course, but that might not be feasible.
I've spent A LOT of time with this problem. Here are some rules/guidelines to make it work correctly without a FlowLayoutPanel or TableLayoutPanel:
Always edit/design your apps in default 96 DPI (100%). If you design in 120DPI (125% f.ex) it will get really bad when you go back to 96 DPI to work with it later.
I've used AutoScaleMode.Font with success, I haven't tried AutoScaleMode.DPI much.
Make sure you use the default font size on all your containers (forms, panels, tabpage, usercontrols etc). 8,25 px. Preferrably it shouldn't be set in the .Designer.cs file at all for all containers so that it uses the default font from the container class.
All containers must use the same AutoScaleMode
Make sure all containers have the below line set in the Designer.cs file:
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); // for design in 96 DPI
If you need to set different font sizes on labels/textboxes etc. set them per control instead of setting the font on the container class because winforms uses the containers font setting to scale it's contents and having f.ex a panel with a different font size than it's containing form is guaranteed to make problems. It might work if the form and all containers on the form use the same font size, but I haven't tried it.
Use another machine or a virtual windows install (VMware, Virtual PC, VirtualBox) with a higher DPI setting to test your design immediatly. Just run the compiled .exe file from the /bin/Debug folder on the DEV machine.
I guarantee that if you follow these guidelines you will be ok, even when you have placed controls with specific anchors and don't use a flowpanel. We have an app built this way deployed on hundreds of machines with different DPI setups and we no longer have any complaints. All forms/containers/grids/buttons/textfield etc sizes are scaled correctly as is the font. Images work too, but they tend to get a little pixellated at high DPI.
EDIT: This link has a lot of good info, especially if you choose to use AutoScaleMode.DPI: link to related stackoverflow question

note: this will not fix the controls moving , when dpi change. this will only fix blurry text!!.
How to fix blurry Windows Forms in high-dpi settings:
Go the the Forms designer, then select your Form (by clicking at
its title bar)
Press F4 to open the Properties window,
then locate the AutoScaleMode property
Change it from Font (default) to Dpi.
Now, go to Program.cs (or the file where your Main method is located) and change it to look like:
namespace myApplication
{
static class Program
{
[STAThread]
static void Main()
{
// ***this line is added***
if (Environment.OSVersion.Version.Major >= 6)
SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
// ***also dllimport of that function***
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
}
}
Save and compile. Now your form should look crispy again.
source:
http://crsouza.com/2015/04/13/how-to-fix-blurry-windows-forms-windows-in-high-dpi-settings/

I finally found solution to problem of both Screen Orientation and DPI handling.
Microsoft has already provided a document explaining it but with a little flaw that will kill DPI handling completely.
Just follow solution provided in the document below under "Creating Separate Layout Code for Each Orientation"
http://msdn.microsoft.com/en-us/library/ms838174.aspx
Then IMPORTANT part!
Inside the code for Landscape() and Portrait() methods at the very end of each add these lines:
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
So, the code for these 2 methods would be like:
protected void Portrait()
{
this.SuspendLayout();
this.crawlTime.Location = new System.Drawing.Point(88, 216);
this.crawlTime.Size = new System.Drawing.Size(136, 16);
this.crawlTimeLabel.Location = new System.Drawing.Point(10, 216);
this.crawlTimeLabel.Size = new System.Drawing.Size(64, 16);
this.crawlStartTime.Location = new System.Drawing.Point(88, 200);
this.crawlStartTime.Size = new System.Drawing.Size(136, 16);
this.crawlStartedLabel.Location = new System.Drawing.Point(10, 200);
this.crawlStartedLabel.Size = new System.Drawing.Size(64, 16);
this.light1.Location = new System.Drawing.Point(208, 66);
this.light1.Size = new System.Drawing.Size(16, 16);
this.light0.Location = new System.Drawing.Point(192, 66);
this.light0.Size = new System.Drawing.Size(16, 16);
this.linkCount.Location = new System.Drawing.Point(88, 182);
this.linkCount.Size = new System.Drawing.Size(136, 16);
this.linkCountLabel.Location = new System.Drawing.Point(10, 182);
this.linkCountLabel.Size = new System.Drawing.Size(64, 16);
this.currentPageBox.Location = new System.Drawing.Point(10, 84);
this.currentPageBox.Size = new System.Drawing.Size(214, 90);
this.currentPageLabel.Location = new System.Drawing.Point(10, 68);
this.currentPageLabel.Size = new System.Drawing.Size(100, 16);
this.addressLabel.Location = new System.Drawing.Point(10, 4);
this.addressLabel.Size = new System.Drawing.Size(214, 16);
this.noProxyCheck.Location = new System.Drawing.Point(10, 48);
this.noProxyCheck.Size = new System.Drawing.Size(214, 20);
this.startButton.Location = new System.Drawing.Point(8, 240);
this.startButton.Size = new System.Drawing.Size(216, 20);
this.addressBox.Location = new System.Drawing.Point(10, 24);
this.addressBox.Size = new System.Drawing.Size(214, 22);
//note! USING JUST AUTOSCALEMODE WILL NOT SOLVE ISSUE. MUST USE BOTH!
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); //IMPORTANT
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; //IMPORTANT
this.ResumeLayout(false);
}
protected void Landscape()
{
this.SuspendLayout();
this.crawlTime.Location = new System.Drawing.Point(216, 136);
this.crawlTime.Size = new System.Drawing.Size(96, 16);
this.crawlTimeLabel.Location = new System.Drawing.Point(160, 136);
this.crawlTimeLabel.Size = new System.Drawing.Size(48, 16);
this.crawlStartTime.Location = new System.Drawing.Point(64, 120);
this.crawlStartTime.Size = new System.Drawing.Size(248, 16);
this.crawlStartedLabel.Location = new System.Drawing.Point(8, 120);
this.crawlStartedLabel.Size = new System.Drawing.Size(48, 16);
this.light1.Location = new System.Drawing.Point(296, 48);
this.light1.Size = new System.Drawing.Size(16, 16);
this.light0.Location = new System.Drawing.Point(280, 48);
this.light0.Size = new System.Drawing.Size(16, 16);
this.linkCount.Location = new System.Drawing.Point(80, 136);
this.linkCount.Size = new System.Drawing.Size(72, 16);
this.linkCountLabel.Location = new System.Drawing.Point(8, 136);
this.linkCountLabel.Size = new System.Drawing.Size(64, 16);
this.currentPageBox.Location = new System.Drawing.Point(10, 64);
this.currentPageBox.Size = new System.Drawing.Size(302, 48);
this.currentPageLabel.Location = new System.Drawing.Point(10, 48);
this.currentPageLabel.Size = new System.Drawing.Size(100, 16);
this.addressLabel.Location = new System.Drawing.Point(10, 4);
this.addressLabel.Size = new System.Drawing.Size(50, 16);
this.noProxyCheck.Location = new System.Drawing.Point(168, 16);
this.noProxyCheck.Size = new System.Drawing.Size(152, 24);
this.startButton.Location = new System.Drawing.Point(8, 160);
this.startButton.Size = new System.Drawing.Size(304, 20);
this.addressBox.Location = new System.Drawing.Point(10, 20);
this.addressBox.Size = new System.Drawing.Size(150, 22);
//note! USING JUST AUTOSCALEMODE WILL NOT SOLVE ISSUE. MUST USE BOTH!
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); //IMPORTANT
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; //IMPORTANT
this.ResumeLayout(false);
}
Works like charm for me.

It looks like this is a problem with Windows. Taking out these two lines fixed everything.
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
This is where I got the solution:
Anchor not work during changing text size to 125% # Telerik forums

It is really hard to design DPI aware applications in Windows Forms. You would have to use layout containers that resize properly when the DPI is changed (such as TableLayoutPanel or FlowLayoutPanel). All controls need resizing as well. The configuration of those containers can be a challenge.
For simple applications it can be done within a reasonable amount of time, but for big applications it is really alot of work.

From experience:
don't use DPI awareness with windows forms unless critical
to this end always set AutoScaleMode property to None on all forms and user controls in your app
The result: WYSIWYG type of interface when DPI settings change

I struggled with this for a while eventually I found a super simple solution for windows 10 and potentially other systems.
In your WinForms App.config file paste this:
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
Then create a app.manifest file and paste or comment in this line:
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
After doing the above I was able to get great DPI results on my 4k screens.
Check out this and this for more information.

If you want your WinForms application to be DPI-Aware application, In addition to Trygve good answer, If you have big project you may want to scale your forms and their content automatically, You can do this by creating ScaleByDPI function:
ScaleByDPI function will receive a Control parameter that is usually a form, and than recursively iterate through all sub controls (if (control.HasChildren == true)), and scale location and sizes off your application controls & sizes and sizes of fonts to the OS configured DPI. You can try to implement it also for images, icons & graphics.
Special notes for ScaleByDPI function:
a. For all controls with default Font sizes, you will need to set their Font.Size to 8.25.
b. You can get devicePixelRatioX and devicePixelRatioY values by (control.CreateGraphics().DpiX / 96) and (control.CreateGraphics().DpiY / 96).
c. You will need scale Control.Size & Control.Location by algorithm that based on control.Dock & control.Anchor values. Be noticed that control.Dock may have 1 of 6 possible values and that control.Anchor may have 1 of 16 possible values.
d. this algorithm will need set values to next bool variables isDoSizeWidth, isDoSizeHeight, isDoLocationX, isDoLocationY, isDoRefactorSizeWidth, isDoRefactorSizeHeight, isDoRefactorLocationX, isDoRefactorLocationY, isDoClacLocationXBasedOnRight, isDoClacLocationYBasedOnBottom.
e. If your project uses a control library other then Microsoft controls, this controls may need a special treatment.
More info on above (d.) bool variables:
*Sometimes a group of controls (may be a buttons) need to be placed one after another on same vertical line, and their Anchor value include Right but not Left, or they need to be placed one after another on same horizontal line, and their Anchor value include Bottom but not Top, in this case you need to re-calculate controls Location values.
*In case of controls that Anchor contains Top & Bottom and\or Left & Right, you will need to re-factor controls Size & Location values.
Uses of ScaleByDPI function:
a. Add next command to the end off any Form constructor: ScaleByDPI(this);
b. Also when adding any control dynamically to a Form call to ScaleByDPI([ControlName]).
When you set Size or Location of any control dynamically after constructor ended, create and use one of next functions in order to get the scaled values of Size or Location: ScaleByDPI_X \ ScaleByDPI_Y \ ScaleByDPI_Size \ ScaleByDPI_Point
In order to mark your application as being DPI-aware, add the dpiAware element to your application's assembly manifest.
Set GraphicsUnit of all Control.Font to System.Drawing.GraphicsUnit.Point
In *.Designer.cs files of all containers, set AutoScaleMode value to System.Windows.Forms.AutoScaleMode.None
in controls like ComboBox & TextBox, changing Control.Size.Hieght have no affect. In this case changing Control.Font.Size will fix control's height.
If form StartPosition value is FormStartPosition.CenterScreen, you will need to recalculate the location of the window.

Since a Winform application form may content controls AND images, allowing the system to resize YOUR window is NOT a solution, but if you could manage to have one form per DPI resolution, with properly scaled images... And that's not a good idea, since as the screen size grow, the font size diminishes.
When using a different DPI resolution the system forces your form to redefine its control's size, location and font, BUT NOT IMAGES, the solution is to change the form's DPI at runtime, when loading, so that everything goes back to original size and location.
This is possible solution, which I've tested it with a card game application where I've gott some 80 image buttons, TabControls etc.
In each form form_Load event, add this code snippet:
Dim dpi As Graphics = Me.CreateGraphics
Select Case dpi.DpiX
Case 120
'-- Do nothing if your app has been desigbned with 120 dpi
Case Else
'-- I use 125 AND NOT 120 because 120 is 25% more than 96
Me.Font = New Font(Me.Font.FontFamily, Me.Font.Size * 125 / dpi.DpiX)
End Select
Besides, a quick trick for testing various resolutions on the same computer, without restarting:
From control panel, change the resolution.
Do not restart! Instead close your session and open a new one with same user.
There is another caveat: If you set a control's size and position at runtime, then you should apply the same DPI factor (eg. 125 / Dpi.Dpix) to the new coordinates. So you'd better set up a DPIFactor global variable from application.startup event.
Last but not least:
DO NOT open your application in Visual Studio from another resolution than the original one, or ALL YOUR CONTROLS will move and resize as you open each form, and there is no way back...
Hope this helps, happy programming.

Related

How to create an 1 pixel wide window using C# and WinForm

I would like to create an application that have a small window displayed at the bottom corner of desktop. On startup, the window shall be very small and ideally, just a couple of pixels in width.
Here is the code I used to do it:
public partial class DurationT64 : Form
{
private Size fullSize;
private Point fullPos;
private Point compactPos;
public DurationT64()
{
InitializeComponent();
var workingArea = Screen.PrimaryScreen.WorkingArea;
this.MinimumSize = new Size(0, this.Height);
this.MaximumSize = new Size(this.Width, this.Height);
// fullPos: the window location when it is in full size form.
fullPos = new Point(workingArea.Right - this.Width, workingArea.Bottom - this.Height);
this.Location = fullPos;
// fullSize: the size of the windown when it is in full size form.
fullSize = new Size(this.Width, this.Height);
this.Size = fullSize;
// compactPos: the window location when it is in compact size form.
compactPos = new Point(workingArea.Right - 30, fullPos.Y);
this.Width = 1;
this.Location = compactPos;
}
}
As you can see that in this example, I intended to create a window of just 1 pixel in width, placed closed to the right edge of the primary monitor.
However, I realized that the window doesn't go as small as I was expected. It goes down to 20 pixels wide but no less than that. Please refer to this screen capture image below for example:
an image shows that the window is wider than it suppose to be
I did some research regards to this problem and noticed that there was a solution proposed by Zach Johnson (#zach-johnson) back in 2009. Here is the link to it Overcome OS Imposed Windows Form Minimum Size Limit.
However, nether methods proposed in that link (the intercepting WM_ message one proposed by Zach and the SetBoundsCore one proposed by #Ace) works for me.
Can anyone please give me some solution to this question? Preferably, a solution purely based on C#/Winform and does not rely on native Win32 window message loop, if possible.
Many thanks!
It is rather straight-forward, Winforms ensures that the window cannot be made smaller than the system-imposed minimum size of a window, exposed as the SystemInformation.MinWindowTrackSize property in .NET. This is a "safety" setting, it ensures that the user cannot make the window too small when he resizes it, thus losing control over it. Same consideration applies to code.
Bypassing this limit requires no magic, you need to do two things:
Set the FormBorderStyle property to None so the user cannot resize the window.
Set the size after the window is created. The Load event is best.
Some comments about your existing code: be careful about tinkering with the Width/Height/Size properties, you are doing too much of it in your constructor and it cannot work correctly. In the constructor they don't yet match the actual size of the window. And will not be close at all on modern machines with high-resolution monitors, auto-scaling to match the DPI of the video adapter is important today. You have to postpone until the window is created and scaling is complete, the Load event is the proper place for code like this. One of the few reasons to actually use Load.
And note that your Location property calculation is inadequate, it does not consider the location of the taskbar. It doesn't work on my machine, I like the taskbar on the right.
Minimum repro:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
}
protected override void OnLoad(EventArgs e) {
this.Width = 1;
base.OnLoad(e);
}
}
Do keep in mind that you'll need hawk-eyes to find it back on the screen :)

Keep my form above the taskbar?

My overall goal is to render a second (or third, fourth...) mouse cursor. To this end, I have created a frameless, topmost, transparent window. I can draw on this window (I have 4 buttons on it to show that it's properly covering the whole desktop) - but when I click on the taskbar, it is brought to the top and overlays my buttons and drawn line.
How can I keep my window above the taskbar?
Alternatively, is there a way that I can draw on the "final" version of the screen?
Here's the code from my .Designer.cs file:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.CausesValidation = false;
this.ClientSize = new System.Drawing.Size(332, 332);
this.ControlBox = false;
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Screen";
this.ShowIcon = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultBounds;
this.TopMost = true;
this.TransparencyKey = System.Drawing.Color.White;
Without analysing the exact motivation of doing this and whether this approach is the best way through, you should note that the taskbar's behaviour is equivalent to the one of any other window: TopMost can be used without any restriction. On the other hand, it is considered outside the "WorkingArea" and thus, depending upon the properties you are using, it might be ignored. Take a look at the sample codes below to understand this better.
Main Form covering all the available space above the taskbar:
this.ClientSize = new System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Left, Screen.PrimaryScreen.WorkingArea.Top);
Main Form covering the whole available space of the screen:
this.ClientSize = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Left, Screen.PrimaryScreen.WorkingArea.Top);
Thus, you can locate your form on top of the taskbar without any problem by bearing the mind that it represents the difference between WorkingArea and Bounds of the screen.
CLARIFICATION: this answer highlights what might be the reason for the taskbar to be treated differently than any other part of the screen. It does not imply that you have to make your form as big as the whole screen to put it over the taskbar; you can put it over the taskbar whenever you want with an as small size as you wish. What you have to bear in mind is that WorkingArea does not provide the whole dimensions of the screen, but just the area ABOVE the taskbar; if you want to bring the taskbar into consideration, consider Bounds.
I'll go with varocarbas answer,but there is something that i want to add which i think might be useful.
A few things are there that i guess may be helpful,when i read your question the first idea that struck my mind was to create a GlobalHook to monitor message WM_CBT,this message is send to GlobalHook procedure when the system is about to Maximize,Minimize,Restore or Focus a Window.When any hook is trapped you can override any required events to block that window from becoming the topmost window,thus giving your Form a chance to remain the topmost Window.This method will be highly helpful if it worked as i am expecting.
If you are interested in this, here are the methods that are required to make a GlobalHook work.
SetWindowsHookEx(),used to tell the system to create a GlobalHook.
HookProc,Represents the method called when a hook catches a monitored event.
HookType,Enumerates the valid hook types passed into a call to SetWindowsHookEx.
CallNextHook.If using interoperability is messy,try this open source library that contains WindowsAPI functions in a managed wrapper.Hope this helps you,meanwhile i'm also trying to get the stuff working for you.
I've been struggling for a few hours with this same problem. I thought of a nice solution: just change the bottom padding of the form dynamically whenever the form is maximized.
If Me.WindowState = FormWindowState.Maximized then
Dim pd As New Padding
pd.Left = Me.Padding.Left
pd.Right = Me.Padding.Right
pd.Top = Me.Padding.Top
pd.Bottom = Me.Height - Screen.PrimaryScreen.WorkingArea.Height
Me.Padding = pd
end if
This way the form is not above the taskbar, but at least your controls are!
Note: in designing your forms you can leave the bottom-padding 0.
If you want your form to be able to minimize/normal resize, then you may want to reset the bottom padding to 0 in another form event.
I actually found the solution about 15 minutes after I posted. (Isn't that always the way? Research for hours, but as soon as you ask for help, you figure it out on your own. :)
I have an event that is calling my code with position updates. If I simply call "BringToFront" in this event, it works just fine. The event is called many times per second, but if I throttle my behavior back to 1/4 second, it still works great.

BorderStyle.Fixed3D renders flat on Windows 8

When I put a System.Windows.Forms.ListView on a form in a WinForm application (using C#/.NET 4.5), it gets rendered as a flat rectangle, even though the BorderStyle property is set to Fixed3D. This is also true for TextBox and a number of other controls.
This is the code generated by the Form Designer for the ListView. The form is just a plain Form and has no other controls at the moment.
...
this.listView1.Location = new System.Drawing.Point(10, 115);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(250, 97);
this.listView1.TabIndex = 2;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
...
If I open older programs (done with VB6 or .NET 2), control borders are rendered with 3D look (that is, controls are rendered with a proper 3D border) instead of being flat.
Is there anything I can do to force the 3D look for these controls under .NET 4.5?
This surely works however I think it also applies to all your controls on your forms, just remove the line Application.EnableVisualStyles() in the Main() method in Program.cs file.

How to use system font settings for a Windows C# app

For a windows application (C#), is it possible to adjust the entire application (including all forms) to use system font settings for size rather than using fixed sizes?
This is for users with visual impairment who have set a bigger font size on their machines. Is it possible for the application to adjust the font according to what the user has.
You should set the AutoScaleMode property of all your forms to the value AutoScaleMode.Font if you want your application to be scaled by system font, or AutoScaleMode.Dpi if you want it to be scaled by windows DPI settings.
Here you can find some more info - http://msdn.microsoft.com/en-us/library/ms229605.aspx
In the constructors of your forms (before calling InitializeComponent()), I would try setting the Font property of your forms equal to System.Drawing.SystemFonts.DefaultFont. If your controls (ex: textboxes) don't specify a specific font then I believe they inherit their font properties from their parent containers (i.e. forms).
There are other more specific system fonts (like the default setting for the Caption's font) in the System.Drawing.SystemFonts class. You may want to investigate those further as well.
// Get dpi width
float x = this.CreateGraphics().DpiX;
// if screen is width
if (x == 120)
// Get big image from Resources
this.BackgroundImage = Properties.Resources.BigImage;
else if (x==96)
{
// Get small image from Resources
this.BackgroundImage = Properties.Resources.loading49;
this.BackColor = ColorTranslator.FromHtml("#E6E6E6");
this.button2.Size = new Size(85, 30);
this.button1.Size = new Size(75, 24);
this.textBox1.Size = new Size(150, 40);
}

DomainUpDown (spinner) control is cutting off the bottom pixel of displayed text

I'm using winforms and the DomainUpDown control's height is locked at 20 pixels, which results in "y"'s and other characters with descenders cut off on the bottom.
My initial thought about how to fix the problem was to change the controls height, but I couldn't do so. In the designer I only have controls to drag it's size by width. The property page immediately reverts any change to height I make. Attempts to change the value in code silently fail; no error, no exception, but no change to the value either.
In this sample form the "g" in the DomainUpDown will be cut.
public partial class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DomainUpDown domainUpDown1 = new System.Windows.Forms.DomainUpDown();
public Form1()
{
this.domainUpDown1.Location = new System.Drawing.Point(16, 8);
this.domainUpDown1.Size = new System.Drawing.Size(212, 20);
this.domainUpDown1.Text = "why are descenders like g cut?";
this.ClientSize = new System.Drawing.Size(328, 64);
this.Controls.Add(this.domainUpDown1);
}
}
I see the same fixed height behaviour when using DomainUpDown controls. You can adjust the size of the font that is used, which changes the height of the control to match the text. Perhaps adjusting the size of your text slightly can help with the clipping of the characters with "descenders". I see no clipping using the default 8.25pt font.
EDIT:
After replicating on XP running the classic theme and with Dan's testing, the problem appears to be the thickness of the borders and padding, which cut off the g.
Setting the BorderStyle to either FixedSingle or None fixes the problem.
domainUpDown1.BorderStyle = BorderStyle.FixedSingle;
or
domainUpDown1.BorderStyle = BorderStyle.None;
You will need to see what looks best in your application. Oh, and setting your theme to XP (rather than classic) will work too.

Categories

Resources