我可以将ScrollBar设置为浮动Step吗?

发布于 2024-08-18 04:37:13 字数 1918 浏览 5 评论 0原文

我有一个面板,代表一个时间线 - 24 小时(24 x 60 分钟 = 1 440 分钟)。

我需要将滚动条的步长设置为一分钟。显然,此类面板的最小尺寸应为 1440 像素。

假设客户端屏幕上的屏幕分辨率(宽度)为 1280,因此面板容器的最大尺寸为 1280。 现在,如果我希望我的步骤是一分钟,我需要将滚动条容器的步骤设置为 1280 / 1440 = 0.(8) - 但这是不可能的,因为 Step (myContainer.Horizo​​ntalScroll. SmallChange) 是一个 int 值...

我可以对此做些什么吗?

编辑

也许每分钟 0.2 像素可以被认为是不可观察的错误,但如果我的步长为 5 分钟,则实际上为 4.(4)px,但在滚动条 = 5 中,步长为 10分钟 = 8.(8)px : 10px。在 800x600 屏幕上,10 分钟步长将为 = 5.(5)px : 10px,因此每 2 次点击(20 分钟)我有 4 个像素误差。这个“三角洲”变得可见。

最后,这是一个示例,不起作用 - 即使我到达使滚动条可见 - 奇怪的滚动条可见性是不可预测的...... - 我无法滚动 6 中的所有 VOLVO 徽标( 60Maxim/10smallChange) 步骤...:

替代文本 http:// /lh6.ggpht.com/_1TPOP7DzY1E/S1eOPUlVvQI/AAAAAAAAC8M/ZFWDI_aaJxI/s800/panels.png

设计者:

this.panel2.BackgroundImage =  ....Resources.volvo_logo;
this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;

代码:

public partial class Form1 : Form
{
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Panel panel2;

    public Form1()
    {
        InitializeComponent();

        panel1.AutoScroll = false;

        panel1.HorizontalScroll.Maximum = 60;
        panel1.HorizontalScroll.SmallChange = 10;

        panel1.HorizontalScroll.LargeChange = 10;
        panel1.HorizontalScroll.Visible = true;

        panel1.Scroll += new ScrollEventHandler(panel1_Scroll);
    }

    void panel1_Scroll(object sender, ScrollEventArgs e)
    {
        Console.WriteLine(
            "Scroll: OldVal {0}, NewVal {1},  Orientation {2}, Type {3}", 
            e.OldValue, e.NewValue, e.ScrollOrientation, e.Type);
    }
}

I have a panel in witch I represent a timeline - 24 hours(24 x 60 min = 1 440 min).

I need to set my scroll bar's step to a minute. It's evident that minimum size of such a panel should be 1440 pixels.

Let's say the screen resolution on the client screen (width) is 1280, so say panel container max size is 1280.
Now, if I want my step be a minute I need to set the step to the scrollbar's container to 1280 / 1440 = 0.(8) - but it's impossible, cause the Step (myContainer.HorizontalScroll.SmallChange) is an int value...

Can I do something to this?

EDIT

Maybe 0.2 pixel per minute can be considered a inobservable error, but if my step will be 5 minutes, it will in reality be 4.(4)px but in scrollbar = 5, a step of 10 minutes will be = 8.(8)px : 10px. On a 800x600 screen the 10min step will be = 5.(5)px : 10px, so in each 2 clicks(20 min) I have 4 pixel error. This "delta" became visible.

Finally, this is a sample, that DOES NOT work - even if I arrive to make the scrollbar visible - strange scrollbar visibility is unpredictable... - I can't scroll all the VOLVO logo in 6 (60Maxim/10smallChange) steps...:

alt text http://lh6.ggpht.com/_1TPOP7DzY1E/S1eOPUlVvQI/AAAAAAAAC8M/ZFWDI_aaJxI/s800/panels.png

Designer:

this.panel2.BackgroundImage =  ....Resources.volvo_logo;
this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;

Code:

public partial class Form1 : Form
{
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Panel panel2;

    public Form1()
    {
        InitializeComponent();

        panel1.AutoScroll = false;

        panel1.HorizontalScroll.Maximum = 60;
        panel1.HorizontalScroll.SmallChange = 10;

        panel1.HorizontalScroll.LargeChange = 10;
        panel1.HorizontalScroll.Visible = true;

        panel1.Scroll += new ScrollEventHandler(panel1_Scroll);
    }

    void panel1_Scroll(object sender, ScrollEventArgs e)
    {
        Console.WriteLine(
            "Scroll: OldVal {0}, NewVal {1},  Orientation {2}, Type {3}", 
            e.OldValue, e.NewValue, e.ScrollOrientation, e.Type);
    }
}

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

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

发布评论

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

评论(1

白衬杉格子梦 2024-08-25 04:37:13

将 ClientSize 设置为像素 (1440) 并保留小更改 = 1。它也将以像素为单位,并与您的分钟数相匹配。

Set the ClientSize in pixels (1440) and leave the small change = 1. It will also be in pixels and will match your minutes.

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