Beispiel #1
0
        private void DrawHintWithPicture(HintPaintEventArgs e, string text, string subText)
        {
            if (e.Renderer != null)
            {
                e.Renderer.DrawBackground(e.Graphics, new Rectangle(Point.Empty, e.Size));
            }
            else // fallback for old windows versions
            {
                using (Brush brush = new SolidBrush(SystemColors.Info))
                    e.Graphics.FillRectangle(brush, new Rectangle(Point.Empty, e.Size));
            }

            e.Graphics.DrawIcon(Icon, new Rectangle(customHint.InnerPadding.Left, customHint.InnerPadding.Top, 32, 32));

            if (e.Renderer != null)
            {
                int height = e.Renderer.GetTextExtent(e.Graphics, subText, TextFormatFlags.TextBoxControl).Height;

                e.Renderer.DrawText(
                    e.Graphics,
                    new Rectangle(
                        customHint.InnerPadding.Left * 2 + 32,
                        customHint.InnerPadding.Top,
                        e.Size.Width - customHint.InnerPadding.Right,
                        e.Size.Height - customHint.InnerPadding.Bottom
                        ),
                    text,
                    false,
                    TextFormatFlags.TextBoxControl
                    );
                e.Renderer.DrawText(
                    e.Graphics,
                    new Rectangle(
                        customHint.InnerPadding.Left * 2 + 32,
                        customHint.InnerPadding.Top + height,
                        e.Size.Width - customHint.InnerPadding.Right,
                        e.Size.Height - customHint.InnerPadding.Bottom - height
                        ),
                    subText,
                    true,
                    TextFormatFlags.TextBoxControl
                    );
            }
            else // fallback for old windows versions
            {
                int height = (int)e.Graphics.MeasureString(subText, SystemFonts.DefaultFont).Height;
                using (Brush brush = new SolidBrush(Color.DarkBlue))
                    e.Graphics.DrawString(
                        text,
                        SystemFonts.DefaultFont,
                        brush,
                        new RectangleF(
                            customHint.InnerPadding.Left * 2 + 32,
                            customHint.InnerPadding.Top,
                            e.Size.Width - customHint.InnerPadding.Right,
                            e.Size.Height - customHint.InnerPadding.Bottom
                            ),
                        StringFormat.GenericDefault
                        );

                using (Brush brush = new SolidBrush(Color.Gray))
                    e.Graphics.DrawString(
                        subText,
                        SystemFonts.DefaultFont,
                        brush,
                        new RectangleF(
                            customHint.InnerPadding.Left * 2 + 32,
                            customHint.InnerPadding.Top + height,
                            e.Size.Width - customHint.InnerPadding.Right,
                            e.Size.Height - customHint.InnerPadding.Bottom - height
                            ),
                        StringFormat.GenericDefault
                        );
            }
        }
Beispiel #2
0
 private void myTrayIcon_TooltipPaint(object sender, HintPaintEventArgs e)
 {
     DrawHintWithPicture(e, myTrayIcon.LongHintText, myTrayIcon.HintText);
 }
Beispiel #3
0
 private void customHint_OnPaint(object sender, HintPaintEventArgs e)
 {
     DrawHintWithPicture(e, customHint.Text, "Rendered from form");
 }