【问题标题】:Replicating the Win7 network flyout refresh button复制 Win7 网络弹出刷新按钮
【发布时间】:2012-02-13 03:31:33
【问题描述】:

我目前正在尝试创建一个类似这样的屏幕:

使用this tool浏览视觉样式部分和状态,我发现底部区域是一个FLYOUT_LINKPANEL。

但是刷新按钮呢?我找不到任何具有相同行为的按钮;悬停前没有背景。 此外,我尝试通过 shell32 中的 dll 查看复制刷新图标的图标 - 没有骰子。刷新图标是 ExplorerFrame.dll 中的位图。

我也尝试过让 WinSpy++ 在窗口周围晃动,但这不起作用,因为它会在停用时立即消失。

建议?

【问题讨论】:

  • 那个面板不是用 WPF 完成的吗?

标签: c# winforms windows-7


【解决方案1】:

这看起来像一个带有一个刷新按钮的标准工具条。

您可以使用C# ToolStrip is transparent but border is still visible? 中列出的方法使其透明。

我确实检查了 %SystemRoot%\system32\shell32.dll 并且有一个与此非常相似的图标,您可以使用。

【讨论】:

  • ToolStrip 按钮的悬停状态是透明的玻璃效果不是吗?在网络弹出窗口中,它似乎是一个没有悬停时没有背景的标准按钮(还有一个虚线轮廓,我也不想尝试模仿)
  • 虽然我已经回答了我自己的问题,但我会奖励你,因为你的回答对我的最终解决方案有所帮助。
【解决方案2】:

这是一个示例实现。至于图片,可以从ExplorerFrame中提取出来。

这个类的第一次尝试只是在悬停时翻转按钮的 FlatStyle,但是每当按钮悬停时图像会移动位置。

此外,该类忠实地复制浮出控件中的那个按钮;它具有按下状态而不是移动图像,并且在它处于活动状态时也不会绘制虚线轮廓。然而,这与按钮在 Windows 中的典型功能背道而驰,因此这并没有复制这种行为。

    public class FlyoutImageButton : Button
    {
        bool _isHovering = false;
        public FlyoutImageButton() : base()
        {
            MouseEnter += (sender, e) => _isHovering = true;
            MouseLeave += (sender, e) => _isHovering = false;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            if (_isHovering)
                base.OnPaint(e);
            else
            {
                if (this.Image != null)
                {
                    e.Graphics.Clear(BackColor);
                    if (this.Enabled)
                        e.Graphics.DrawImageUnscaled(
                            this.Image,
                            (this.Width - this.Image.Width) / 2,
                            (this.Height - this.Image.Height) / 2);
                    else
                        ControlPaint.DrawImageDisabled(
                            e.Graphics,
                            this.Image,
                            (this.Width - this.Image.Width) / 2,
                            (this.Height - this.Image.Height) / 2,
                            BackColor);
                }
                if (this.DesignMode)
                    ControlPaint.DrawBorder(
                        e.Graphics, ClientRectangle, SystemColors.ControlDarkDark, ButtonBorderStyle.Dashed);
            }
        }
    }

【讨论】:

    猜你喜欢
    • 2018-06-13
    • 2017-01-17
    • 2022-10-02
    • 2017-04-08
    • 2023-01-30
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    相关资源
    最近更新 更多