protected override void OnPaint(PaintEventArgs pevent)
        {
            Graphics g = pevent.Graphics;

            base.Paint(g);

            if (MainForm.IsHidden)
            {
                return;
            }

            if (_decorator == null)
            {
                var  taskbarLocation = this.MainForm.TaskbarLocation;
                bool leftToRight     = taskbarLocation == Native.ABEdge.Top ||
                                       taskbarLocation == Native.ABEdge.Bottom;
                _decorator = new PushPanelDecorator(leftToRight, Width, Height, Padding, this);
            }
            _decorator.Paint(g, _isClicked, _hover);

            if (this.Image != null)
            {
                int iconPosX = (this.Width - this.Image.Width) / 2;
                int iconPosY = (this.Height - this.Image.Height) / 2;

                g.DrawImage(this.Image, iconPosX + (_isClicked ? ClickedOffset : 0), iconPosY + (_isClicked ? ClickedOffset : 0));
            }
        }
        public void Init()
        {
            SetDefaultHeight();

            var taskbarLocation = this.MainForm.TaskbarLocation;

            bool leftToRight = taskbarLocation == Native.ABEdge.Top ||
                               taskbarLocation == Native.ABEdge.Bottom;

            Width = leftToRight ? (IsBig ? BigWidth : SmallWidth) : (this.Parent.Width);

            bool isVisualTheme = Native.IsThemeActive() != 0;

            if (!isVisualTheme && !leftToRight)
            {
                Width       -= 5;
                this.Padding = new Padding(0, 0, 0, 0);
            }
            else
            {
                this.Padding = new Padding(1, 0, 2, 0);
            }
            if (_decorator != null)
            {
                _decorator.Dispose();
            }
            _decorator = null;

            int iconSize = this.IsBig ? ButtonConstants.BigIconSize : ButtonConstants.SmallIconSize;

            this.Image = _app.Icon.ResizeBitmap(iconSize, iconSize);
        }
        protected void CustomPaint()
        {
            using (Graphics g = this.CreateGraphics())
            {
                base.Paint(g);

                if (!MainForm.IsHidden)
                {
                    if (Native.IsThemeActive() != 0)
                    {
                        if (_decorator == null)
                        {
                            var taskbarLocation = this.MainForm.TaskbarLocation;

                            bool leftToRight = taskbarLocation == Native.ABEdge.Top || taskbarLocation == Native.ABEdge.Bottom;
                            _decorator = new PushPanelDecorator(true, Width, Height, Padding, this);
                        }
                        _decorator.Paint(g, _isClicked, _hover);
                    }
                    NotificationAreaProxy.PaintIcon(_data.BitmapIndex,
                        (this.Width - ButtonConstants.SmallIconSize) / 2,
                        (this.Height - ButtonConstants.SmallIconSize) / 2, this.Handle);
                }
            }

            // Tell Windows that the button is now rendered. This will prevent it from calling paint again until actually needed.
            Native.RECT rect = new Native.RECT()
            {
                left = this.ClientRectangle.Left,
                right = this.ClientRectangle.Right,
                top = this.ClientRectangle.Top,
                bottom = this.ClientRectangle.Bottom
            };
            Native.ValidateRect(this.Handle, ref rect);
        }
Пример #4
0
 protected override void OnSizeChanged(EventArgs e)
 {
     base.OnSizeChanged(e);
     if (_decorator != null)
     {
         _decorator.Dispose();
     }
     _decorator = null;
 }
        public void Init()
        {
            var taskbarLocation = this.MainForm.TaskbarLocation;
            bool isLeftToRight = taskbarLocation == Native.ABEdge.Top || taskbarLocation == Native.ABEdge.Bottom;

            if (isLeftToRight)
            {
                SetDefaultHeight();
                Height = Height - 9;
                Width = ButtonConstants.NotifIconWidth;
            }
            else
            {
                Width = ButtonConstants.NotifIconWidth;
                Height = ButtonConstants.NotifIconHeight;
            }

            this.Padding = System.Windows.Forms.Padding.Empty;

            if (_decorator != null) _decorator.Dispose();
            _decorator = null;
        }
Пример #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // due to a bug, sometimes Paint method is called when Height = 2
            // this causes PushPanelDecorator : LinearGradientBrush to throw OutOfMemory exception because the two points are equal (framework bug !?)
            if (Width <= 5 || Height <= 5)
            {
                return;
            }

            bool isVisualTheme = Native.IsThemeActive() != 0;

            if (isVisualTheme)
            {
                base.OnPaint(e);
            }

            if (MainForm.IsHidden)
            {
                return;
            }

            if (isVisualTheme)
            {
                if (_decorator == null)
                {
                    var taskbarLocation = this.MainForm.TaskbarLocation;

                    bool leftToRight = taskbarLocation == Native.ABEdge.Top ||
                                       taskbarLocation == Native.ABEdge.Bottom;

                    _decorator = new PushPanelDecorator(leftToRight, Width, Height, Padding.Empty, this);
                }
                _decorator.Paint(e.Graphics, _isClicked, _hover);
            }

            IntPtr hdc = e.Graphics.GetHdc();

            Native.SetTextCharacterExtra(hdc, 0);
            e.Graphics.ReleaseHdc(hdc);


            if (isVisualTheme)
            {
                string str;

                str = DateTime.Now.ToShortTimeString();
                if (this.Parent.Parent.Height > Constants.BigTaskbarSize)
                {
                    str += Environment.NewLine + DateTime.Now.ToString("dddd") + Environment.NewLine + DateTime.Now.ToShortDateString();
                }
                else if (this.Parent.Parent.Height == Constants.BigTaskbarSize)
                {
                    str += Environment.NewLine + DateTime.Now.ToShortDateString();
                }

                if (AeroDecorator.Instance.IsDwmCompositionEnabled)
                {
                    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                }
                else
                {
                    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                }
                e.Graphics.DrawString(str, Font, _fontColor, this.Width / 2, this.Height / 2 + 2, _format);
            }
            else
            {
                string str;

                str = DateTime.Now.ToShortTimeString();
                if (!TaskbarPropertiesManager.Instance.Properties.SmallIcons)
                {
                    var taskbarLocation = this.MainForm.TaskbarLocation;

                    if (TaskbarPropertiesManager.Instance.Properties.HeightMultiplier > 1 ||
                        taskbarLocation == Native.ABEdge.Left ||
                        taskbarLocation == Native.ABEdge.Right)
                    {
                        str += Environment.NewLine + DateTime.Now.ToString("dddd") + Environment.NewLine + DateTime.Now.ToShortDateString();
                    }
                    else
                    {
                        str += Environment.NewLine + DateTime.Now.ToShortDateString();
                    }
                }
                else
                {
                    var taskbarLocation = this.MainForm.TaskbarLocation;

                    if (TaskbarPropertiesManager.Instance.Properties.HeightMultiplier >= 3 ||
                        taskbarLocation == Native.ABEdge.Left ||
                        taskbarLocation == Native.ABEdge.Right)
                    {
                        str += Environment.NewLine + DateTime.Now.ToString("dddd") + Environment.NewLine + DateTime.Now.ToShortDateString();
                    }
                    else if (TaskbarPropertiesManager.Instance.Properties.HeightMultiplier == 2)
                    {
                        str += Environment.NewLine + DateTime.Now.ToShortDateString();
                    }
                }

                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                Font font = new System.Drawing.Font(Font.FontFamily, Font.Size - 0.5f);
                e.Graphics.DrawString(str, font, _fontColor, this.Width / 2, this.Height / 2, _format);
            }
        }