tags:

views:

170

answers:

1

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);
    }
}
+1  A: 

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.

Rhys Jones
I was using the default MS Sans serif 8.25 font. I tried twiddling between 7.75 and 8.75 points. The only results was that occasionally descenders were being clipped by 2 pixels. Easist to see with the lowercase g where the horizontal stroke was obviously missing.
Dan Neely
I also tried a few other fonts. The only one that didn't truncate the descenders was Consolas, but because it's obviously different from the standard font I don't really want to use it. If i only do in one place it sticks out like a sore thumb, and changing the font appwide would be a major pita (alignment issues) even if I could get signoff.
Dan Neely
That has me stumped; I can't replicate the clipping at all. I copied your code into a new form and it does not cut the bottom off the g. Tried creating in the designer and that is OK too. I wonder if there is something in your form setup that is causing this behaviour?
Rhys Jones
That's interesting. I'm running XP32; and will be testing this on a few other machines later today to see if I can reproduce it elsewhere.
Dan Neely
Following up. I've tested my app on 4 additional PCs beyond my normal workstation. 2XP32 systems (one belonging to a coworker, one personal), a Vista32 Ultimate system (personal), and a W7RC64 system (personal). The control rendered text properly on the Vista and W7 systems. The other 2 XP systems did not. The differences between the renderings are that the XP system used a 2 pixel border for the control instead of a one pixel border, and that they drew the text on pixel farther below the top border (a net 2 pixels lower).
Dan Neely
...The image I'm linking to contains in order screenshots from W7, Vista, XP, and a comparison of the text around the "g" between the W7 and XP versions. The red lines were both placed a single pixel above the tops of the g's.http://www.orthogonaltonormal.com/midden/DomainUpDown.png Rhys: what version of windows did you try to replicate this in?
Dan Neely
I am running XP SP3; but the difference is that I am using the XP theme, and it looks like you are using classic. I can replicate it when I switch to classic mode. Then to looked at changing the borders, and found that if I set it to FixedSingle or None then the g displays properly. I will add the code to my answer. Of course you could switch to the XP theme also, which will work.
Rhys Jones
It looks like that's it. I guess the only question left is if this is a .net or windows bug. My MFC is extremely rusty and I never learned win32; is there an equivalent native control?The interesting bit is that NoBorder has a text area no larger than Fixed3d but aligns the text higher in it, resulting in a control that's several pixels shorter.
Dan Neely
I have not done any MFC programming for years... I don't know if there is an equivalent native control.
Rhys Jones