i'm at a loss as to why my parameter richtextbox is resizing its height at runtime. I'm assuming that it has something to do with my high def displays.
all other fields are simply textbox.
any suggestions as to fields I can check? Form.AutoScale is set to font.
http://imgur.com/a/S0dq0
It seems that this issue is directly related to the use of the font "Microsoft YaHei". Changing the font to San Serif immediately resolved the issue.
Related
Is it possible to set the textbox text to align at the center while using auto size property to false.I tried with Text align property, but it does't work.Here is my code.
textBox1.AutoSize = false;
textBox1.Size = new Size(100,35);
textBox1.TextAlign = HorizontalAlignment.Center;
Below is a screen sample :
I want the result to be as show in figure.
TextBox is one of the grand-daddy controls in the toolbox. Goes back all the way to 1987 and Windows version 2.0. Back when it was still a 16-bit real-mode operating system and had to run in 640 kilobytes of memory. It is also notorious for breaking the rules, painting itself without using WM_PAINT. The kind of thing Microsoft had to do to get acceptable perf from a 386SUX processor. The dearth of memory was a major reason to cut down on its features.
They did not do much to improve the control, although it certainly looks a heckofalot better than it did 28 years ago. Changing it behavior is very risky, TextBox is a major app-compat nightmare with 28 years of programmers trying to hack it to do more.
But there is no way to hack it to look the way you want it, it always renders the text top-aligned. You must have noticed the fight that it put up to stop you from writing that code. It is also very, very wrong code, hard-coding the size produces very undesirable accidents when it runs on a high DPI machine, displaying text with the descenders sheared-off. AutoSize should always be set to True for a single-line TextBox to prevent such accidents.
You can otherwise emulate it pretty easily, just embed it in a panel that is as tall as you want it and set its BorderStyle property to None. Use its Resize event to center it in the panel. Easy peasy.
As the question is about vertical arrangement and also for single mode there is a method but it would be working around with panels.
Place textbox inside a panel with paddings there you go :
How can I change the Font.Size in a RichTextBox .SelectionFont (which has two or three different FontFamily), without affecting the FontFamilyand the FontStyle
This one works fine, if I have only one Font.Family
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont.FontFamily, 12);
But, if I have more, it throws nullexception.
Perhaps this answer from the question: "Reset RTF in RichTextBox?" may help you. I quote:
More you ask?
I use most of this via a small utility class that wraps this for all the styles and font changes. This way you can change font-size and not change font name, etc.
I've had the same problem. Check the answer by LarsTech here:
Changing font for richtextbox without losing formatting
You'll find properties such as SelectionFontName, SelectionFontSize, ...
In VS2008 I designed a form for a C# dll. The dll is a plugin for a somewhat older app (ca. 2005): let's call it "OldApp". In VS form designer, the text in Label controls on my form is nicely rendered: antialiased and properly kerned. But when I bring up this form within OldApp (where the C# dll runs as a plugin), the text in Label controls looks ugly. It's legible, but the kerning is poor: the letters are spaced further apart and at seemingly random offsets. Anything I can do to make the text labels from within OldApp look as good as they do in VS's form designer? I doubt the specific font matters, but it's Arial, 7.2 pt (VS2008 default). I tried playing with the two relevant lines in Program.cs (see below), to no effect.
Application.EnableVisualStyles(); // tried using it and commenting it out
Application.SetCompatibleTextRenderingDefault(true); // tried true and false
I found a similar problem on MSDN forums that mentions adding the following line after the EnableVisualStyles() method.
Application.DoEvents()
Seems to be a bug in older .NET versions...which version are you using?
After an investigation I have some findings, so I'll just answer my own question:
The bad news: the old-style text rendering used by OldApp is what's causing the problem. I verified it by toggling the UseCompatibleTextRendering property for the label control in VS. The font distortion I see is the same one I see in OldApp. Which means that the Application.SetCompatibleTextRenderingDefault(false) line in my code has no effect. OldApp will ignore it and do old-style rendering anyway.
As suggested by DeviantSeev using a bigger font helps a bit. It doesn't get rid of the bad kerning, it just makes it less noticeable. I increased the font from 7.2pt to 8pt only (not 12pt), because the dialog box becomes too big otherwise. The way to do this is in the form's Font property (not the control's). This way, you'll change all controls uniformly (if their Font property is set to default).
The font sizes in VS appear to be discrete rather than continuous, or maybe there's an int() rounding off involved. Increasing the font from 7.2pt to 7.4pt results in very little change, while at 7.5pt the font makes a sudden jump in size.
Forms have an AutoScaleMode property. If it's set to Font and the form is resizeable, the form will resize in VS in proportion to the change in font size. This way, in VS you can find an acceptable middle ground between a (legible) font size and a bloated dialog. However, be careful: the auto-scale operation can suddenly go awry, for example if you change the Font units from points to pixels, inches, etc. You may suddenly end up with microscopic controls or a form bigger than your screen and hitting undo won't fix it. You really don't want to re-design your form again, so save it before any font unit change and then again when you're happy with what you see.
I have such trouble: in large names, as shown in imagealt text http://www.freeimagehosting.net/uploads/2c46b75236.jpg
, somehow letter-spacing for Tahoma font is decreasing.
This issue is shown up in two components that I use, so I don't think this is bug of the components.
I have tested with another fonts,
Arial - situation the same;
MS Sans Serif - the same;
Trebuchet MS - situation is good, symbols type correctly;
Times New Roman - situation is good too, but font with notches
Can you help? Using .NET without WPF.
What controls are you using? Are these them:
Elegant Grid
GtkTreeView
You've only shown one screen shot there. Which control is that?
Any chance of some example source code? Something which shows the behaviour in GtkTreeView would be best as it's free...
If I have a Control, I can know the Font it is using by the Font Property. Now how can I know the average Size of the Font( or lets say I would like to know what would it be the width of the 'M' char)
I know that Graphics.MeasureString() would solve my problem but implies creating a graphic object since I'm not in any paint event.. or wouldn't like to use the CreateGraphics. or nothing like that. I'm raising a grid and would like to set my column Width since I have all my columns text information.
(THis is for Winforms..... NOT WPF)
I am afraid there might not be a guaranteed accurate measurement, you can try TextRenderer.MeasureText.
A good post in SO here on "Accuracy of TextRenderer.MeasureText results"