DrawToolTipEventArgs.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / WinForms / Managed / System / WinForms / DrawToolTipEventArgs.cs / 1 / DrawToolTipEventArgs.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Windows.Forms 
{ 

    using System.Diagnostics; 
    using System;
    using System.Runtime.InteropServices;
    using System.ComponentModel;
    using System.Windows.Forms.VisualStyles; 
    using System.Drawing;
    using System.Windows.Forms.Internal; 
    using Microsoft.Win32; 

    ///  
    /// 
    ///     This class contains the information a user needs to paint the ToolTip.
    /// 
    public class DrawToolTipEventArgs : EventArgs 
    {
 
        private readonly Graphics graphics; 
        private readonly IWin32Window associatedWindow;
        private readonly Control associatedControl; 
        private readonly Rectangle bounds;
        private readonly string toolTipText;
        private readonly Color backColor;
        private readonly Color foreColor; 
        private readonly Font font;
 
        ///  
        /// 
        ///     Creates a new DrawToolTipEventArgs with the given parameters. 
        /// 
        public DrawToolTipEventArgs(Graphics graphics, IWin32Window associatedWindow, Control associatedControl, Rectangle bounds, string toolTipText,
 				    Color backColor, Color foreColor, Font font)
        { 
            this.graphics = graphics;
            this.associatedWindow = associatedWindow; 
            this.associatedControl = associatedControl; 
            this.bounds = bounds;
            this.toolTipText = toolTipText; 
            this.backColor = backColor;
            this.foreColor = foreColor;
            this.font = font;
        } 

        ///  
        ///  
        ///     Graphics object with which painting should be done.
        ///  
        public Graphics Graphics
        {
            get
            { 
                return graphics;
            } 
        } 

        ///  
        /// 
        ///     The window for which the tooltip is being painted.
        /// 
        public IWin32Window AssociatedWindow { 
            get {
                return associatedWindow; 
            } 
        }
	 
        /// 
        /// 
        ///     The control for which the tooltip is being painted.
        ///  
        public Control AssociatedControl
        { 
            get 
            {
                return associatedControl; 
            }
        }

        ///  
        /// 
        ///     The rectangle outlining the area in which the painting should be done. 
        ///  
        public Rectangle Bounds
        { 
            get
            {
                return bounds;
            } 
        }
 
 
        /// 
        ///  
        ///     The text that should be drawn.
        /// 
        public string ToolTipText
        { 
            get
            { 
                return toolTipText; 
            }
        } 

        /// 
        /// 
        ///     The font used to draw tooltip text. 
        /// 
        public Font Font 
        { 
            get
            { 
                return font;
            }
        }
 
        /// 
        ///  
        ///     Draws the background of the ToolTip. 
        /// 
        public void DrawBackground() 
        {
            Brush backBrush = new SolidBrush(backColor);
            Graphics.FillRectangle(backBrush, bounds);
            backBrush.Dispose(); 
        }
 
        ///  
        /// 
        ///     Draws the text (overloaded) 
        /// 
        public void DrawText()
        {
            //Pass in a set of flags to mimic default behavior 
            DrawText(TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.HidePrefix);
        } 
	 
        /// 
        ///  
        ///     Draws the text (overloaded) - takes a TextFormatFlags argument.
        /// 
        public void DrawText(TextFormatFlags flags)
        { 
            TextRenderer.DrawText(graphics, toolTipText, font, bounds, foreColor, flags);
        } 
 
        /// 
        ///  
        ///     Draws a border for the ToolTip similar to the default border.
        /// 
        public void DrawBorder()
        { 
            ControlPaint.DrawBorder(graphics, bounds, SystemColors.WindowFrame, ButtonBorderStyle.Solid);
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Windows.Forms 
{ 

    using System.Diagnostics; 
    using System;
    using System.Runtime.InteropServices;
    using System.ComponentModel;
    using System.Windows.Forms.VisualStyles; 
    using System.Drawing;
    using System.Windows.Forms.Internal; 
    using Microsoft.Win32; 

    ///  
    /// 
    ///     This class contains the information a user needs to paint the ToolTip.
    /// 
    public class DrawToolTipEventArgs : EventArgs 
    {
 
        private readonly Graphics graphics; 
        private readonly IWin32Window associatedWindow;
        private readonly Control associatedControl; 
        private readonly Rectangle bounds;
        private readonly string toolTipText;
        private readonly Color backColor;
        private readonly Color foreColor; 
        private readonly Font font;
 
        ///  
        /// 
        ///     Creates a new DrawToolTipEventArgs with the given parameters. 
        /// 
        public DrawToolTipEventArgs(Graphics graphics, IWin32Window associatedWindow, Control associatedControl, Rectangle bounds, string toolTipText,
 				    Color backColor, Color foreColor, Font font)
        { 
            this.graphics = graphics;
            this.associatedWindow = associatedWindow; 
            this.associatedControl = associatedControl; 
            this.bounds = bounds;
            this.toolTipText = toolTipText; 
            this.backColor = backColor;
            this.foreColor = foreColor;
            this.font = font;
        } 

        ///  
        ///  
        ///     Graphics object with which painting should be done.
        ///  
        public Graphics Graphics
        {
            get
            { 
                return graphics;
            } 
        } 

        ///  
        /// 
        ///     The window for which the tooltip is being painted.
        /// 
        public IWin32Window AssociatedWindow { 
            get {
                return associatedWindow; 
            } 
        }
	 
        /// 
        /// 
        ///     The control for which the tooltip is being painted.
        ///  
        public Control AssociatedControl
        { 
            get 
            {
                return associatedControl; 
            }
        }

        ///  
        /// 
        ///     The rectangle outlining the area in which the painting should be done. 
        ///  
        public Rectangle Bounds
        { 
            get
            {
                return bounds;
            } 
        }
 
 
        /// 
        ///  
        ///     The text that should be drawn.
        /// 
        public string ToolTipText
        { 
            get
            { 
                return toolTipText; 
            }
        } 

        /// 
        /// 
        ///     The font used to draw tooltip text. 
        /// 
        public Font Font 
        { 
            get
            { 
                return font;
            }
        }
 
        /// 
        ///  
        ///     Draws the background of the ToolTip. 
        /// 
        public void DrawBackground() 
        {
            Brush backBrush = new SolidBrush(backColor);
            Graphics.FillRectangle(backBrush, bounds);
            backBrush.Dispose(); 
        }
 
        ///  
        /// 
        ///     Draws the text (overloaded) 
        /// 
        public void DrawText()
        {
            //Pass in a set of flags to mimic default behavior 
            DrawText(TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.HidePrefix);
        } 
	 
        /// 
        ///  
        ///     Draws the text (overloaded) - takes a TextFormatFlags argument.
        /// 
        public void DrawText(TextFormatFlags flags)
        { 
            TextRenderer.DrawText(graphics, toolTipText, font, bounds, foreColor, flags);
        } 
 
        /// 
        ///  
        ///     Draws a border for the ToolTip similar to the default border.
        /// 
        public void DrawBorder()
        { 
            ControlPaint.DrawBorder(graphics, bounds, SystemColors.WindowFrame, ButtonBorderStyle.Solid);
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK