ScreenTip Module Extension Like Office 2007

2 posts, 0 answers
  1. NorthGates
    NorthGates avatar
    13 posts
    Member since:
    Oct 2012

    Posted 06 Feb 2013 Link to this post


    RadControls version v2012.3.1211.40
    .NET version v4.0
    Visual Studio version vs 2012
    programming language C#
    browser support N/A

    Incapsulate ScreenTips in one location and closely follows Office 2007 Screen Tip popup convention/style.

    In your project, create a new class called ExtensionMethods and paste the following:
    If you already have a class ExtensionMethods, just paste the #region SCREENTIP but make sure the 2 using Telerik... are in the class.

    using System;
    using System.Drawing;
    using System.Linq;
    using System.Windows.Forms;
    using Telerik.WinControls;
    using Telerik.WinControls.UI;
    namespace ExtensionMethods
        public static class MyExtensions
            #region ////////// SCREENTIP ... ///////////////
            /* TO USE, in your form or user control add a reference to this namespace (using ExtensionMethods;)
                void btn_ScreenTipNeeded(object sender, Telerik.WinControls.ScreenTipNeededEventArgs e)
                    e.Item.PopupTip(e, "Format Painter (Ctrl+Shift+C)", null, "<html>Copy <b>formatting</b> from one place and apply it to another.");
            private static RadOffice2007ScreenTipElement screenTip = new RadOffice2007ScreenTipElement();
            /// <summary>
            /// Set to true to display or hide all PopupTips.
            /// </summary>
            public static bool ShowPopupTips = true;
            /// <summary>
            /// Incapsulate ScreenTips in one location and closely follows Office 2007 Screen Tip popup convention/style.
            /// </summary>
            /// <param name="control"></param>
            /// <param name="e">ScreenTipNeededEventArgs to allow a global (one location) config of Delay and Offset.</param>
            /// <param name="titleText">Caption. Leave blank to hide the caption area.</param>
            /// <param name="mainImage">Image shown middle-left of main text area or null if no image to display.</param>
            /// <param name="mainText">Main text area. If the mainImage is null and mainText is empty, the main area is hidden.</param>
            /// <param name="showFooter">Show/hide footer. Default is show it.</param>
            public static void PopupTip(this RadItem control, ScreenTipNeededEventArgs e, string titleText, Image mainImage = null, string mainText = "", bool showFooter = true)
                if (!ShowPopupTips)
                e.Delay = 1;
                e.Offset = new System.Drawing.Size(-32, 0);
                screenTip = null;
                screenTip = new RadOffice2007ScreenTipElement();
                screenTip.CaptionLabel.Padding = new Padding(8, 8, 8, 2);
                screenTip.CaptionLabel.Font = new Font("Tahoma", 8.5f, FontStyle.Bold);
                screenTip.CaptionLabel.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                screenTip.CaptionLabel.Opacity = .8;
                //screenTip.CaptionLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
                screenTip.CaptionLabel.TextAlignment = ContentAlignment.MiddleLeft;
                //screenTip.CaptionLabel.ImageAlignment = ContentAlignment.MiddleLeft;
                //screenTip.CaptionLabel.Image = myNamespace.Properties.Resources.help16;
                if (string.IsNullOrEmpty(titleText))
                    screenTip.CaptionLabel.Visibility = ElementVisibility.Hidden;
                    screenTip.CaptionLabel.Text = titleText;
                screenTip.MainTextLabel.Padding = new Padding(8, 0, 8, 0);
                screenTip.MainTextLabel.Font = new Font("Tahoma", 8.5f);
                screenTip.MainTextLabel.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                screenTip.MainTextLabel.Opacity = .9;
                screenTip.MainTextLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
                screenTip.MainTextLabel.TextAlignment = ContentAlignment.MiddleLeft;
                screenTip.MainTextLabel.ImageAlignment = ContentAlignment.MiddleLeft;
                if (string.IsNullOrEmpty(mainText) && mainImage == null)
                    screenTip.MainTextLabel.Visibility = ElementVisibility.Hidden;
                screenTip.MainTextLabel.Image = mainImage;
                if (!string.IsNullOrEmpty(mainText))
                    screenTip.MainTextLabel.Text = mainText;
                screenTip.FooterVisible = showFooter;
                screenTip.FooterLine.Visibility = showFooter ? ElementVisibility.Visible : ElementVisibility.Hidden;
                screenTip.FooterTextLabel.Padding = new Padding(8);
                screenTip.FooterTextLabel.Font = new Font("Tahoma", 8.5f, FontStyle.Bold);
                screenTip.FooterTextLabel.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                screenTip.FooterTextLabel.Opacity = .8;
                screenTip.FooterTextLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
                screenTip.FooterTextLabel.TextAlignment = ContentAlignment.MiddleLeft;
                screenTip.FooterTextLabel.ImageAlignment = ContentAlignment.MiddleLeft;
                screenTip.FooterTextLabel.Image = SystemIcons.Question.ToBitmap().GetThumbnailImage(22, 22, null, IntPtr.Zero); //myNamespace.Properties.Resources.help16;
                screenTip.FooterTextLabel.Text = "  Press F1 for more help.";
                //The following line indicates that Office 2007 UI complient screen tip sizing should not be used.
                screenTip.EnableCustomSize = false;
                screenTip.AutoSizeMode = RadAutoSizeMode.Auto;
                control.ScreenTip = screenTip;
            #endregion //////// END SCREENTIP ////////////////

    In your forms and user controls, add the reference to your Extension Methods Namespace:
    using ExtensionMethods;

    Add the event handler of your RadControl to your form:
    protected override void OnLoad(EventArgs e)
        btn.ScreenTipNeeded += btn_ScreenTipNeeded;

    Call the screen tip from the event:
    void btn_ScreenTipNeeded(object sender, Telerik.WinControls.ScreenTipNeededEventArgs e)
        e.Item.PopupTip(e, "Format Painter (Ctrl+Shift+C)", null
    , "<html>Copy <b>formatting</b> from one place and apply it to another.");

    Sample with image | Sample without image

  2. Plamen
    Plamen avatar
    132 posts

    Posted 11 Feb 2013 Link to this post

    Hi Luc,

    Thank you for posting this code library article.

    Your Telerik points have been updated for the community effort.

    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top