示例#1
0
        private void HandlePaintBackground(PaintEventArgs e)
        {
            var      bufferImage = new ImageWithDeviceContext(Size);
            Graphics g           = Graphics.FromHdc(bufferImage.Dc);

            DrawBackground(bufferImage);

            int last = LastScrollableItemIndex;

            var mousePos        = _form.PointToClient(Cursor.Position);
            var currentHoverred = mousePos.Y / ItemHeight;

            int relativeIndex = 0;

            for (int i = FirstScrollableItemIndex; i <= last; i++)
            {
                LayeredPopupMenuItem item = Items[i];
                DrawItem(bufferImage, g, item, relativeIndex, currentHoverred == relativeIndex);

                relativeIndex++;
            }

            NativeMethods.BitBlt(e.Graphics.GetHdc(), 0, 0, Width, Height, bufferImage.Dc, 0, 0, CopyPixelOperation.SourceCopy);
            e.Graphics.ReleaseHdc();

            bufferImage.Dispose();
            g.Dispose();
        }
示例#2
0
        private void HandleMouseClick(MouseEventArgs e)
        {
            var mousePos                 = _form.PointToClient(Cursor.Position);
            var currentHoverred          = mousePos.Y / ItemHeight;
            LayeredPopupMenuItem clicked = Items[currentHoverred];

            OnItemClicked((String)clicked.Tag);
        }
示例#3
0
        private void DrawText(Graphics g, LayeredPopupMenuItem item, Rectangle textBounds)
        {
            Font font = item.Bold ? FontBold : Font;

            g.TextContrast      = 0;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            g.DrawString(item.Text, font, ForeColorBrush, textBounds, DefaultStringFormat);
        }
示例#4
0
        private void DrawImage(IDeviceContext destImage, LayeredPopupMenuItem item, Rectangle bounds, bool hovered)
        {
            ImageWithDeviceContext itemImage = ItemBackgroundImage;

            if (item.Checked || hovered)
            {
                itemImage = ItemHoveredBackgroundImage;
            }

            ImageRenderer.StretchImageWithOutMargin(destImage, bounds.X, bounds.Y, bounds.Width, bounds.Height,
                                                    itemImage, 0, itemImage.Width, itemImage.Height,
                                                    StretchMargin, 255);
        }
示例#5
0
        protected virtual void DrawItem(ImageWithDeviceContext destImage, Graphics g, LayeredPopupMenuItem item, int index, bool hovered)
        {
            var bounds = new Rectangle();

            bounds.Width  = Width - (ContentMargin.Right + ContentMargin.Left + ItemContentRight);
            bounds.Height = ItemBackgroundImage.Height;

            bounds.X = ContentMargin.Left;
            bounds.Y = ContentMargin.Top + index * bounds.Height;

            DrawImage(destImage, item, bounds, hovered);

            Rectangle textBounds = bounds;

            textBounds.X      += ItemContent.Left;
            textBounds.Y      += ItemContent.Top;
            textBounds.Width  -= ItemContent.Left + ItemContent.Right + ItemContentRight;
            textBounds.Height -= ItemContent.Top + ItemContent.Bottom;

            DrawText(g, item, textBounds);

            if (hovered && item.HoveredImage != null)
            {
                g.DrawImage(item.HoveredImage, ItemIconLocation.X + bounds.X, ItemIconLocation.Y + bounds.Y);
            }
            else if (item.Image != null)
            {
                g.DrawImage(item.Image, ItemIconLocation.X + bounds.X, ItemIconLocation.Y + bounds.Y);
            }
        }