如何从“Grip”中回收空间?

发布于 2024-08-29 04:50:07 字数 278 浏览 5 评论 0原文

我有一个带有单个 ToolStripStatusLabel、Spring=true 和通知背景色的 StatusStrip。

问题是状态栏右侧有一个丑陋的灰色方块。摆弄了一段时间后,我意识到这是调整手柄大小(我设置为 SizingGrip=false,GripStyle=Hidden)。然而,即使它被隐藏起来,它仍然占据着空间。我无法将状态条上的任何内容一直延伸到右侧。

您将如何解决这个问题?注意我不能只设置 StatusStrip 的背景色,因为 Status Label 会改变颜色并具有一些褪色效果。

I've got a StatusStrip with a single ToolStripStatusLabel, Spring=true and a background color for notifications.

The problem is that there's an ugly gray square on the right side of the status strip. After fiddling for a while, I realized this is the sizing grip (I had is set to SizingGrip=false, GripStyle=Hidden). Yet even with it hidden, it still hogs the space. I can't get any content on the status strip to extend all the way to the right.

How would you work around this? Note I can't just set the backcolor of the StatusStrip because the Status Label changes colors and has some fading effects.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无风消散 2024-09-05 04:50:07

StatusStrip.Padding 属性已失效,如果禁用大小调整夹点,它会返回错误的 Padding.Right 值。您可以在表单构造函数中修复它,如下所示:

public Form1() {
  InitializeComponent();
  statusStrip1.Padding = new Padding(statusStrip1.Padding.Left,
    statusStrip1.Padding.Top, statusStrip1.Padding.Left, statusStrip1.Padding.Bottom);
}

使用 Left 属性指定 Right 即可修复。不要费心将此错误提交给 Connect,他们不会修复它。

The StatusStrip.Padding property is borked, it returns the wrong value for Padding.Right if the sizing grip is disabled. You can fix it in your form constructor, like this:

public Form1() {
  InitializeComponent();
  statusStrip1.Padding = new Padding(statusStrip1.Padding.Left,
    statusStrip1.Padding.Top, statusStrip1.Padding.Left, statusStrip1.Padding.Bottom);
}

Using the Left property to specify Right is the fix. Don't bother submitting this bug to Connect, they won't fix it.

‖放下 2024-09-05 04:50:07

查看此博客MSDN 上的条目。问题是关于手动更改大小调整手柄的大小,我认为按照建议使用 ToolStrip 渲染器也可以为您工作。

到目前为止,我遇到的问题是它删除了 StatusStrip 中状态标签上的背景颜色,因此这还不是解决方案,但它是一个开始。

    public MyForm()
    {
        InitializeComponent();
        statusStrip1.Renderer = new MyRenderer();
    }

    private class MyRenderer : ToolStripProfessionalRenderer
    {
        protected override void OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs e)
        {
            // don't draw at all
        }
    }

Have a look at this blog entry on MSDN. The question was about changing the size of the sizing grip manually, and I think using the ToolStrip Renderer as suggested could work for you also.

The problem I have so far, is that it removes the background color on a status label in the StatusStrip, so it's not a solution yet, but it's a start.

    public MyForm()
    {
        InitializeComponent();
        statusStrip1.Renderer = new MyRenderer();
    }

    private class MyRenderer : ToolStripProfessionalRenderer
    {
        protected override void OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs e)
        {
            // don't draw at all
        }
    }
最冷一天 2024-09-05 04:50:07

我遇到了以下问题:当我设置 tsslSeparator.Spring = true 时,我的右侧标签在 tsslSeparator 失去焦点后立即消失。启用调整握点大小时会出现此问题。当它被禁用时,一切都工作得很好。
解决方案是将右标签的右边距设置为不同于 0 的值。

tsslLogging.Margin = new Padding(0, 3, 2, 2); // this is necessary for right alignment of status bar label

希望这对某人有帮助。

I had following problem: when I set tsslSeparator.Spring = true, my right label disappeared immediately after tsslSeparator lost focus. The issue appeared when sizing grip was enabled. When it was disabled, everything worked just fine.
The solution was to set right margin for right label to something different than 0.

tsslLogging.Margin = new Padding(0, 3, 2, 2); // this is necessary for right alignment of status bar label

Hope this helps somebody.

梦途 2024-09-05 04:50:07

如果微软对修复它不感兴趣,似乎正确的修复应该处理所有方向,并且理想情况下修复所有状态条(请参阅我对 获取所有子项,了解 GetAllChildren 的定义)

    public static StatusStrip FixPadding(this StatusStrip ss) {
        if (!ss.SizingGrip) {
            var fixpad = ss.Padding;

            if (ss.Orientation == Orientation.Horizontal) {
                if (ss.RightToLeft == RightToLeft.No)
                    fixpad.Right = fixpad.Left;
                else
                    fixpad.Left = fixpad.Right;
            }
            else
                fixpad.Bottom = fixpad.Top;

            ss.Padding = fixpad;
        }

        return ss;
    }

    public static void FixStatusStripPadding(this Form f) {
        foreach (var ss in f.GetAllChildren().OfType<StatusStrip>())
            ss.FixPadding();
    }

If Microsoft isn't interesting in fixing it, it seems like a proper fix should handle all orientations, and ideally fix all Status Strips (see my answer to Get All Children for definition of GetAllChildren)

    public static StatusStrip FixPadding(this StatusStrip ss) {
        if (!ss.SizingGrip) {
            var fixpad = ss.Padding;

            if (ss.Orientation == Orientation.Horizontal) {
                if (ss.RightToLeft == RightToLeft.No)
                    fixpad.Right = fixpad.Left;
                else
                    fixpad.Left = fixpad.Right;
            }
            else
                fixpad.Bottom = fixpad.Top;

            ss.Padding = fixpad;
        }

        return ss;
    }

    public static void FixStatusStripPadding(this Form f) {
        foreach (var ss in f.GetAllChildren().OfType<StatusStrip>())
            ss.FixPadding();
    }
铃予 2024-09-05 04:50:07

我尝试过这个:

ssStatus.Padding = Padding.Empty

它对我有用。

I tried this:

ssStatus.Padding = Padding.Empty

It works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文