private void someLabel_Paint(object sender, PaintEventArgs e) { // This code requires a ToolTip control on the form named toolTip. Label thisLabel = sender as Label; // Set a rectangle size with same width and larger height than label's. SizeF layoutSize = new SizeF(thisLabel.Width, thisLabel.Height + 1); // Get the actual size of rectangle needed for all of text. SizeF fullSize = e.Graphics.MeasureString(thisLabel.Text, thisLabel.Font, layoutSize); // Set a tooltip if not all text fits in label's size. if (fullSize.Width > thisLabel.Width || fullSize.Height > thisLabel.Height) { toolTip.SetToolTip(thisLabel, thisLabel.Text); } else { toolTip.SetToolTip(thisLabel, null); } }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.