Exemple #1
0
        private void _toolTip_Draw(object sender, DrawToolTipEventArgs e)
        {
            DashboardButton button = e.AssociatedControl as DashboardButton;

            // Default behavior for non-button tooltips
            if (button == null)
            {
                e.DrawBackground();
                e.DrawBorder();
                e.DrawText();
                return;
            }
            DisplaySettings.Default.PaintBackground(e.Graphics, e.Bounds, this);
            e.DrawBorder();
            string title         = button.ThingToShowOnDashboard.LocalizedLongLabel;
            Font   localizedFont = (Font)StringCatalog.LabelFont.Clone();
            Font   boldFont      = new Font(localizedFont, FontStyle.Bold);
            int    titleHeight   =
                TextRenderer.MeasureText(e.Graphics,
                                         title,
                                         boldFont,
                                         new Size(e.Bounds.Width - 6, int.MaxValue),
                                         ToolTipFormatFlags).Height;
            Rectangle titleBounds = new Rectangle(e.Bounds.Left + 3,
                                                  e.Bounds.Top + 3,
                                                  e.Bounds.Width - 6,
                                                  e.Bounds.Top + 2 + titleHeight);
            Rectangle descriptionBounds = new Rectangle(e.Bounds.Left + 18,
                                                        e.Bounds.Top + 3 + titleHeight,
                                                        e.Bounds.Width - 21,
                                                        e.Bounds.Height - 8 - titleHeight);

            TextRenderer.DrawText(e.Graphics,
                                  title,
                                  boldFont,
                                  titleBounds,
                                  Color.Black,
                                  ToolTipFormatFlags);
            TextRenderer.DrawText(e.Graphics,
                                  GetToolTipDescription(button.ThingToShowOnDashboard),
                                  localizedFont,
                                  descriptionBounds,
                                  Color.Black,
                                  ToolTipFormatFlags);
            localizedFont.Dispose();
            boldFont.Dispose();
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        private DashboardButton MakeButton(IThingOnDashboard item, ButtonGroup group)
        {
            DashboardButton button = MakeButton(item);

            button.BackColor   = Color.Transparent;
            button.Font        = (Font)StringCatalog.LabelFont.Clone();
            button.AutoSize    = false;
            button.BorderColor = group.BorderColor;
            button.DoneColor   = group.DoneColor;

            button.Size         = _bestButtonSize;
            button.SizeChanged += ButtonSizeChanged;
            button.Text         = item.LocalizedLabel;
            button.Click       += OnButtonClick;
            // if fonts or text are localized, we will need to re-measure stuff
            button.TextChanged += delegate { _smallestPossibleButtonSizes = null; };
            button.FontChanged += delegate { _smallestPossibleButtonSizes = null; };
            _toolTip.SetToolTip(button, item.LocalizedLabel + GetToolTipDescription(item));
            return(button);
        }