如何强制垂直滚动条始终从WinForms中的AutoScroll中可见? [英] How to force vertical scrollbar always be visible from AutoScroll in WinForms?

查看:221
本文介绍了如何强制垂直滚动条始终从WinForms中的AutoScroll中可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#和WinForms中使用VS2010和.NET 4.0:

Using VS2010 and .NET 4.0 with C# and WinForms:

我一直希望垂直滚动条在我的面板上显示为禁用的滚动条(不需要时,在使用时启用).

I always want a Vertical Scrollbar to show for my panel as a disabled scrollbar (when it's not needed, and a enabled one when it can be used.

因此,它就像一个混合式AutoScroll.我曾尝试使用VScrollBars,但无法弄清楚将其放置在何处以进行这项工作.

So it's like a hybrid AutoScroll. I've tried using VScrollBars but I can't figure out where to place them to make this work.

基本上,我有一个用户控件,它充当控件的文档",其大小会发生变化,因此在使用自动滚动时,它可以完美地工作.当用户控件不合适时,滚动条就会出现,用户可以上下移动它.

Essentially I've got a user control that acts as a "Document" of controls, its size changes so when using auto-scroll it works perfectly. The scrollbar appears when the usercontrol doesn't fit and the user can move it updown.

从本质上来说,这就像一个网络浏览器.但是,重新绘制控件需要花费很长时间(在面板的网格中,它的网格内的组中包含许多字段和按钮等形式,

It's like a web browser essentially. However, redrawing controls takes a long time (it's forms with many fields and buttons etc within groups in a grid within a panel :P

因此,无论如何,当自动滚动启用垂直滚动条时,需要一段时间才能重新绘制窗口.我想总是显示如上所示的垂直滚动条(具有启用/禁用功能).

So anyhow, when autoscroll enables the vertical scrollbar, it takes a while to redraw the window. I'd like to ALWAYS show the vertical scrollbar as indicated above (with the enable/disable functionality).

如果有人能提供帮助,我已经阅读了许多有关自动滚动的文章,但是没有人问我要问的问题,我无法提出解决方案.

If anyone has some help, i've read many posts on the subject of autoscroll, but noone has asked what I'm asking and I can't come up with a solution.

推荐答案

主管技术答案的C#版本

C# Version of competent_Tech's answer

using System.Runtime.InteropServices; 

public class MyUserControl : UserControl
{
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);

    private enum ScrollBarDirection
    {
        SB_HORZ = 0,
        SB_VERT = 1,
        SB_CTL = 2,
        SB_BOTH = 3
    }

    public MyUserControl()
    {
        InitializeComponent();
        ShowScrollBar(this.Handle, (int) ScrollBarDirection.SB_VERT, true);
    }
}

这篇关于如何强制垂直滚动条始终从WinForms中的AutoScroll中可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆