/// <summary> /// Computes possible minimum requires sizes to fit the button text /// </summary> /// <returns>Possible sizes</returns> protected List <Size> GetPossibleTextSizes() { Graphics g = Graphics.FromHwnd(Handle); List <Size> possibleSizes = DisplaySettings.GetPossibleTextSizes(g, Text, Font, FormatFlags); g.Dispose(); return(possibleSizes); }
private void _toolTip_Popup(object sender, PopupEventArgs e) { //todo: This code can take 30 seconds or more to complete! if you make the dash small and then drag the window, //it goes navel-gazing for a long time. (JH noticed Oct 2011). //This is also implicated in involvement in WS-34187) "Better feedback for slower computers" //because we're talking about replacing all this with html, I'm just going to make //this not run when it has no business running. if (_suspendLayout) { return; } DashboardButton button = e.AssociatedControl as DashboardButton; if (button == null) { return; } string title = button.ThingToShowOnDashboard.LocalizedLongLabel; Graphics g = Graphics.FromHwnd(e.AssociatedWindow.Handle); Font localizedFont = (Font)StringCatalog.LabelFont.Clone(); Font boldFont = new Font(localizedFont, FontStyle.Bold); string textUsedOnlyForMeasurement = GetToolTipDescription(button.ThingToShowOnDashboard); #if __MonoCS__ // "\n ." is added on because Mono frequently miscalculates the height by one line. textUsedOnlyForMeasurement += (System.Environment.NewLine + " ."); #endif List <Size> possibleSizes = DisplaySettings.GetPossibleTextSizes(g, textUsedOnlyForMeasurement, localizedFont, ToolTipFormatFlags); Size bestSize = GetBestSizeBasedOnRatio(possibleSizes, GoldRatio); bestSize.Width += 15; bestSize.Height += TextRenderer.MeasureText(g, title, boldFont, new Size(bestSize.Width, int.MaxValue), ToolTipFormatFlags).Height; e.ToolTipSize = new Size(bestSize.Width + 6, bestSize.Height + 8); g.Dispose(); localizedFont.Dispose(); boldFont.Dispose(); }