如何在用户滚动时保持状态栏可见

发布于 2024-12-27 18:18:58 字数 337 浏览 2 评论 0原文

我有一个带有状态条的表格。表单具有自动滚动功能。需要时,会出现滚动条,用户可以滚动。

然而,当内容大于表单大小并且用户必须向下滚动才能看到内容的其他部分时,他/她也必须一直向下滚动才能看到状态条。

我想将状态条保留在表单底部,无论大小和滚动位置如何。我该怎么做?

为什么我不能将所有内容放在面板上并设置 panel.AutoScroll = true

因为我在这个面板上绘制所有内容(使用 GDI+),然后调整其大小,然后显示表单滚动条。现在,如果我在面板中设置自动滚动,则不会显示滚动条,因为面板上没有控件,只有 GDI+ 绘图。

I have a form with status strip. Form has auto-scroll on. When required, scrollbars appear and user can scroll.

However when the content is bigger than form size and user has to scroll down to see other parts of the content, he/she has to scroll all the way down also to see the status strip.

I want to keep the status strip on the bottom of the form whatever the size and scroll position is. How do I do that?

Why can I not put everything on a panel and set panel.AutoScroll = true?

Because I draw everything on this panel (with GDI+), then resize it, then form displays scrollbars. Now if I set autoscroll on in the panel no scroll bars are shown because there are no controls on panel, only GDI+ drawings.

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

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

发布评论

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

评论(2

月牙弯弯 2025-01-03 18:18:58

将需要滚动的所有内容放入面板中,并在面板上设置自动滚动。您的状态条应该位于面板之外。

如果您正在使用 GDI+ 进行大量绘图,我可以想到两个不错的选择来替换您的设计。

  • 如果用户必须与您的图形交互,请考虑创建自定义控件来封装功能和图形。

  • 如果只是显示一些数据,您可以将图形绘制到 Bitmap 并在 PictureBox 中查看。

我不知道你想要完成什么,所以我不能说什么是正确的解决方案。

Put everything that needs scrolling inside a panel and set auto-scroll on the panel. Your status strip should go outside the panel.

If you are doing extensive drawing with GDI+, there are two good options that I can think of to replace your design.

  • If the user must interact with your graphics, consider creating a custom control to encapsulate the functionality and graphics.

  • If it is nothing but a display of some data, you can draw your graphics to a Bitmap and view it in a PictureBox.

I don't know what you are trying to accomplish, so I can't say what is the correct solution.

一向肩并 2025-01-03 18:18:58

听起来你好像在倒退做事。 “表单”不应该显示滚动条,面板应该显示。

如果面板的“内容”比面板大,并且您在面板内完成所有这些绘制,那么您需要将面板的 AutoScrollMinSize 设置为内容的大小,而不是保留扩大面板尺寸。

设置面板内容的大小(示例):

panel1.AutoScrollMinSize = new Size(500, 500);

然后在面板的绘制事件中应用转换:

private void panel1_Paint(object sender, PaintEventArgs e) {
  e.Graphics.TranslateTransform(panel1.AutoScrollPosition.X, panel1.AutoScrollPosition.Y);
  // do your normal painting here
}

使用双缓冲面板以避免闪烁。

您的 StatusStrip 应该停靠在表单的底部,而不是干扰面板。

It sounds like you are doing things backwards. The "Form" shouldn't be showing the scrollbars, the panel should be.

If the "content" of your panel is larger than your panel, and you are doing all of this drawing inside the panel, then you need to set the panel's AutoScrollMinSize to the size of your content, not keep enlarging the size of the panel.

Set the size of your panel's content (example):

panel1.AutoScrollMinSize = new Size(500, 500);

Then in your panel's paint event, apply the transformation:

private void panel1_Paint(object sender, PaintEventArgs e) {
  e.Graphics.TranslateTransform(panel1.AutoScrollPosition.X, panel1.AutoScrollPosition.Y);
  // do your normal painting here
}

Use a Double-Buffered panel to avoid flicker.

Your StatusStrip should just be docked to the bottom of the form, not interfering with the panel.

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