<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: C# AutoEllipsis property for Label not showing tooltip on Add-Ins? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/c-autoellipsis-property-for-label-not-showing/m-p/15949#M364</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is more information and a work around for anyone else that runs into this issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is not directly an ArcGIS issue, more of a .NET issue, but it does affect Add-Ins that use Windows Forms.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After more reading today, I believe ArcObjects 10.0 for .NET is using the older GDI+ (from .NET 1.0/1.1) and the Graphics class rather than the newer GDI and TextRenderer class introduced in .NET 2.0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;More info &lt;/SPAN&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setcompatibletextrenderingdefault(VS.90).aspx" rel="nofollow noopener noreferrer" target="_blank"&gt;here on MSDN&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems the autoellipsis tooltip for overflowed text in Label controls is indeed broken by setting either the control's UseCompatibleTextRendering property to true, or the global Application.SetCompatibleTextRenderingDefault(true). I have tested this in both VS C# 2008 and .NET 3.5, and VS C# 2010 with .NET 4.0, and on Windows 7 and Vista.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A quick workaround is to just add some code to the Label's Paint event, which can be shared among any number of Label controls (set AutoEllipsis=true, AutoSize=false):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
private void someLabel_Paint(object sender, PaintEventArgs e)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; // This code requires a ToolTip control on the form named toolTip.

&amp;nbsp;&amp;nbsp;&amp;nbsp; Label thisLabel = sender as Label;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set a rectangle size with same width and larger height than label's.
&amp;nbsp;&amp;nbsp;&amp;nbsp; SizeF layoutSize = new SizeF(thisLabel.Width, thisLabel.Height + 1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the actual size of rectangle needed for all of text.
&amp;nbsp;&amp;nbsp;&amp;nbsp; SizeF fullSize = e.Graphics.MeasureString(thisLabel.Text, thisLabel.Font, layoutSize);
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set a tooltip if not all text fits in label's size.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fullSize.Width &amp;gt; thisLabel.Width || fullSize.Height &amp;gt; thisLabel.Height)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; toolTip.SetToolTip(thisLabel, thisLabel.Text);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; toolTip.SetToolTip(thisLabel, null);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another workaround is to create a new label control that inherits Label, and overrides the OnPaint method with similar code, which is what I ended up doing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Jeff H&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 20:38:44 GMT</pubDate>
    <dc:creator>JeffreyHamblin</dc:creator>
    <dc:date>2021-12-10T20:38:44Z</dc:date>
    <item>
      <title>C# AutoEllipsis property for Label not showing tooltip on Add-Ins?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/c-autoellipsis-property-for-label-not-showing/m-p/15947#M362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am hoping someone can confirm (or deny) this problem I am seeing:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using VS C# 2008 Express.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On all my Add-Ins that display a custom form, I have noticed that for any labels I have set AutoEllipsis to TRUE and AutoSize to FALSE, if the text overflows then the ellipsis is appended to the end of the truncated text -- however, the expected tooltip containing the complete text DOES NOT display.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I call the same form from a test exe (not an Add-In), then it works as expected.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(I am also seeing some other subtle font painting differences, but one thing at a time...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Jeff H&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2011 19:02:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/c-autoellipsis-property-for-label-not-showing/m-p/15947#M362</guid>
      <dc:creator>JeffreyHamblin</dc:creator>
      <dc:date>2011-05-03T19:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: C# AutoEllipsis property for Label not showing tooltip on Add-Ins?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/c-autoellipsis-property-for-label-not-showing/m-p/15948#M363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Additional information:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Setting the UseCompatibleTextRendering property for a Label to TRUE (the default is FALSE), causes the Label to have the same problem whether running within the context of an Add-In or on a form in a regular exe. (and it also makes some other subtle font painting differences go away.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This makes me wonder if Add-Ins are inheriting a global setting of Application.SetCompatibleTextRenderingDefaul(true) from ArcGIS.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the .NET documentation states: "You should never call this method if your Windows Forms code is hosted in another application, such as Internet Explorer. Only call this method in stand-alone Windows Forms applications."&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;... so I don't think we can change the setting back to FALSE for an Add-In.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Jeff H&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2011 19:57:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/c-autoellipsis-property-for-label-not-showing/m-p/15948#M363</guid>
      <dc:creator>JeffreyHamblin</dc:creator>
      <dc:date>2011-05-03T19:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: C# AutoEllipsis property for Label not showing tooltip on Add-Ins?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/c-autoellipsis-property-for-label-not-showing/m-p/15949#M364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is more information and a work around for anyone else that runs into this issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is not directly an ArcGIS issue, more of a .NET issue, but it does affect Add-Ins that use Windows Forms.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After more reading today, I believe ArcObjects 10.0 for .NET is using the older GDI+ (from .NET 1.0/1.1) and the Graphics class rather than the newer GDI and TextRenderer class introduced in .NET 2.0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;More info &lt;/SPAN&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setcompatibletextrenderingdefault(VS.90).aspx" rel="nofollow noopener noreferrer" target="_blank"&gt;here on MSDN&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems the autoellipsis tooltip for overflowed text in Label controls is indeed broken by setting either the control's UseCompatibleTextRendering property to true, or the global Application.SetCompatibleTextRenderingDefault(true). I have tested this in both VS C# 2008 and .NET 3.5, and VS C# 2010 with .NET 4.0, and on Windows 7 and Vista.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A quick workaround is to just add some code to the Label's Paint event, which can be shared among any number of Label controls (set AutoEllipsis=true, AutoSize=false):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
private void someLabel_Paint(object sender, PaintEventArgs e)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; // This code requires a ToolTip control on the form named toolTip.

&amp;nbsp;&amp;nbsp;&amp;nbsp; Label thisLabel = sender as Label;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set a rectangle size with same width and larger height than label's.
&amp;nbsp;&amp;nbsp;&amp;nbsp; SizeF layoutSize = new SizeF(thisLabel.Width, thisLabel.Height + 1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the actual size of rectangle needed for all of text.
&amp;nbsp;&amp;nbsp;&amp;nbsp; SizeF fullSize = e.Graphics.MeasureString(thisLabel.Text, thisLabel.Font, layoutSize);
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set a tooltip if not all text fits in label's size.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fullSize.Width &amp;gt; thisLabel.Width || fullSize.Height &amp;gt; thisLabel.Height)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; toolTip.SetToolTip(thisLabel, thisLabel.Text);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; toolTip.SetToolTip(thisLabel, null);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another workaround is to create a new label control that inherits Label, and overrides the OnPaint method with similar code, which is what I ended up doing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Jeff H&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:38:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/c-autoellipsis-property-for-label-not-showing/m-p/15949#M364</guid>
      <dc:creator>JeffreyHamblin</dc:creator>
      <dc:date>2021-12-10T20:38:44Z</dc:date>
    </item>
  </channel>
</rss>

