When test trimming is set to anything other than "None" the text in an Editor has a vertical Offset when text is trimmed.
Bug or feature?
If Features: How can I avoid this?
Many thanks.
Urs Scherrer
Hi Daniel,
I tried setting Text Trimming to other values than None and I dint see Editor text having any vertical offset when the text is trimmed. Can you please send us a sample with this issue reproduced in it? Once we receive the sample we can look further into this issue.
Please let me know if you have any questions.
Sincerely,
Sahaja Kokkalagadda
Associate Software Developer, Windows Forms
http://ko.infragistics.com/
Please see sample here: http://1drv.ms/1T9V9JU
After reviewing “TextEditor text having vertical offset when its appearance.TextTrimming property is set to anything other than None” issue, we found that it is an issue in .Net Graphics object.
Here is the reason why it’s not feasible to fix this issue on our side. When you try to draw text with DrawString method of the Graphics class, and the StringFormat.Trimming is set to something different than StringTrimming.None, the text offsets vertically when it is trimmed. As the offset is different with different fonts and font sizes it is not feasible to fix this for all combinations of fonts / font size.
Dear Sahaja
Many thanks for your answer.
Do I understand correctly: Problem has to be resolved by Microsoft? It's a .Net Problem?
I created a testproject using DrawString to write text tirmmed and not trimmed using this Code below.
There I can't see any vertical Offset happening.
Please recheck your Code!
Kind regards,
Please modify your Paint () event so that the text is actually trimmed, by modifying the Width of your new Rectangle () you can get the text trimmed. You can do something like this to observe this behavior.
private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawString("Long text attached to test form's graphics object.", this.Font, Brushes.Black, this.rect, new StringFormat() { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }); }
private void ButtonResize_Click(object sender, EventArgs e) { var button = sender as Button; if (button != null) { if (button.Text == "Extend") { button.Text = "Collapse"; this.rect = new Rectangle(0, 0, 300, 20); } else { button.Text = "Extend"; this.rect = new Rectangle(0, 0, 100, 20); } }
this.Invalidate(); }
Sincerely,Sahaja KokkalagaddaAssociate Software Developer, Windows Formshttp://ko.infragistics.com/
I modified the Code a little bit (see below). With this Code I also get an Offset when trimming is set to "None".
Probably text is wrapped when it's too Long. The wrapped text needs more space in vertical which causes a different Location inside the rect.
Can I avoid wrapping anyhow?
You can avoid wrapping by setting the UltraTextEditor.Multiline property to false. Please let me know if you have any questions.
Hi Urs,
Not really. It's just a different way of drawing text. GDI Plus is the newer DotNet way to draw text. But it has a lot of problems, especially with text measurement and alignment. Newer versions of Visual Studio actually default to the old style (GDI), presumably because of the GDI Plus problems.
So reverting to GDI is a good option and will make your text drawing a lot more consistent and reliable.
Dear Mike
Many thanks for your valuable input.
The original Problem was coming form Ultragrid: Columns with trimmed text beside columns without trimmed text look ugly because text is not on the same height.
I now reactivaed trimming and placed the "UseGDIPlus.." Statement at very first line of Main Window. That works!
Does it have any other effects I should observe?
Hi again,
I just realized that you posted a sample earlier in this thread and so I took a look at it. Judging by the sample, I'm guessing that your concern is when the text seems to jump when you make the form smaller.
If that's the case, then the jump seems a lot more pronounced in the UltraLabel than in the UltraTextEditor - at least on my system. But I was able to completley eliminate it by doing two things:
First, turn off WordWrap on the UltraLabel. Wrapping when you are using TextTrimming doesn't really make sense in this case, anyway.
Second, switch to GDI text rendering (instead of GDI Plus). You can do this for all of the Infragistics controls in your application by setting a static property:
Infragistics.Win.DrawUtility.UseGDIPlusTextRendering = false;
I added this line in the form's constructor right before the InitializeComponent call.
Hi,
There's nothing we can do about how the DotNet framework draws the text, nor is there any way we can determine the offset. So the only way to "solve" this would be to set up the application in such a way that things are consistent.
But... what exactly is the problem you are trying to solve here? Why is the offset a problem? Is it inconsistency across controls? Is it inconsistency within a single control? You're not changing the TextTrimming dynamically are run-time, are you?
Can you provide some screen shots or some more detailed description of exactly why the offset is a problem? If so, then perhaps we can come up with a solution that works for your application.
For UltraTextEditor this is a solution.
But it does not work for