Ejemplo n.º 1
0
        public CustomTabControl() : base()
        {
            if (this._DisplayManager.Equals(TabControlDisplayManager.Custom))
            {
                this.SetStyle(ControlStyles.UserPaint, true);
                this.ItemSize = new Size(0, 15);
                this.Padding  = new Point(9, 0);
            }

            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.ResizeRedraw   = true;
            _priorSelectedIndex = -1;
            _priorAlignment     = TabAlignment.Left;

            ImageOffset = new System.Drawing.Point(16, 2);

            // We are simulating a close button with the close images. The
            // image is a stylized X from the VS2008 image library.  There are
            // three versions - a regular CloseImage, the greyed version for
            // tabs that are not currently selected, and the hover image,
            // which is a highlighted (red) form that gets displayed when the
            // mouse hovers over the X. The effect is to make the image itself
            // highlight like a normal button might.
            //
            // OnMouseHover doesn't really work for the purposes of the close
            // "button".  The close image isn't really a Control, so it gets no
            // Hover events.  The TabControl is a Control, and it gets hover
            // events, but only one, on entry to the control.  Moving the
            // mouse around on different tabs doesn't send a new hover event.
            // Therefore, we need to track the mouse events, and simulate the
            // effect.  We use a timer for that purpose.  It gets reset
            // whenever the mouse moves and is present on the close image. If
            // the mouse stops moving for a period of _hoverInterval ms, then
            // the timer fires and the close image is painted with the hover
            // image (a red X).  If the mouse moves away from the closeimage
            // on the selected tab, the timer gets disabled.
            _hoverInterval = 110;
            _hoverTimer    = new System.Timers.Timer
            {
                Interval  = _hoverInterval,
                AutoReset = false
            };

            // Hook up the Elapsed event for the timer.
            _hoverTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
            mhs = new MouseHoverState();


            // get the images
            System.Reflection.Assembly assembly = this.GetType().Assembly;
            System.IO.Stream           s1       =
                assembly.GetManifestResourceStream("CustomControls.Resources.Close.png");
            var b = new Bitmap(s1);

            s1.Dispose();
            //b.MakeTransparent();
            CloseImage = b;

            s1 = assembly.GetManifestResourceStream("CustomControls.Resources.Close-grayed.png");
            b  = new Bitmap(s1);
            s1.Dispose();
            //b.MakeTransparent();
            CloseImageGray = b;

            s1 = assembly.GetManifestResourceStream("CustomControls.Resources.Close-hover.png");
            b  = new Bitmap(s1);
            s1.Dispose();
            //b.MakeTransparent();
            CloseImageHover = b;

            //System.Console.WriteLine("Images: Close({0}) Gray({1}) Hover({2})", CloseImage, CloseImageGray, CloseImageHover);
        }
Ejemplo n.º 2
0
        public CustomTabControl()
            : base()
        {
            if (this._DisplayManager.Equals(TabControlDisplayManager.Custom))
            {
                this.SetStyle(ControlStyles.UserPaint, true);
                this.ItemSize = new Size(0, 15);
                this.Padding = new Point(9,0);
            }

            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.ResizeRedraw = true;
            _priorSelectedIndex = -1;
            _priorAlignment = TabAlignment.Left;

            ImageOffset = new System.Drawing.Point(16, 2);

            // We are simulating a close button with the close images. The
            // image is a stylized X from the VS2008 image library.  There are
            // three versions - a regular CloseImage, the greyed version for
            // tabs that are not currently selected, and the hover image,
            // which is a highlighted (red) form that gets displayed when the
            // mouse hovers over the X. The effect is to make the image itself
            // highlight like a normal button might.
            //
            // OnMouseHover doesn't really work for the purposes of the close
            // "button".  The close image isn't really a Control, so it gets no
            // Hover events.  The TabControl is a Control, and it gets hover
            // events, but only one, on entry to the control.  Moving the
            // mouse around on different tabs doesn't send a new hover event.
            // Therefore, we need to track the mouse events, and simulate the
            // effect.  We use a timer for that purpose.  It gets reset
            // whenever the mouse moves and is present on the close image. If
            // the mouse stops moving for a period of _hoverInterval ms, then
            // the timer fires and the close image is painted with the hover
            // image (a red X).  If the mouse moves away from the closeimage
            // on the selected tab, the timer gets disabled.
            _hoverInterval = 110;
            _hoverTimer = new System.Timers.Timer
                {
                    Interval = _hoverInterval,
                    AutoReset = false
                        };

            // Hook up the Elapsed event for the timer.
            _hoverTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
            mhs = new MouseHoverState();

            // get the images
            System.Reflection.Assembly assembly = this.GetType().Assembly;
            System.IO.Stream s1 =
                assembly.GetManifestResourceStream("CustomControls.Resources.Close.png");
            var b = new Bitmap(s1);
            s1.Dispose();
            //b.MakeTransparent();
            CloseImage = b;

            s1 = assembly.GetManifestResourceStream("CustomControls.Resources.Close-grayed.png");
            b = new Bitmap(s1);
            s1.Dispose();
            //b.MakeTransparent();
            CloseImageGray= b;

            s1 = assembly.GetManifestResourceStream("CustomControls.Resources.Close-hover.png");
            b = new Bitmap(s1);
            s1.Dispose();
            //b.MakeTransparent();
            CloseImageHover= b;

            //System.Console.WriteLine("Images: Close({0}) Gray({1}) Hover({2})", CloseImage, CloseImageGray, CloseImageHover);
        }