没有ScrollableControl的滚动条 [英] Scrollbars without ScrollableControl

查看:105
本文介绍了没有ScrollableControl的滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello CP,



我目前正在编写一个自定义控件,它继承自抽象ListControl(ListBox的父级)。现在我只想显示滚动条我不知道怎么做而不继承ScrollableControl。



那么,如何在不使用的情况下添加滚动条ScrollableControl?

Hello CP,

I''m currently in the process of writing a custom control which inherits from the abstract ListControl (the parent of ListBox). Now I''d like to display scrollbars only I don''t know how to do it without inheriting from ScrollableControl.

So, how do I add scrollbars without using ScrollableControl?

推荐答案

你有太多未知的功能细节。我会尝试以最普遍的方式进行。



你可能需要有两种相同控制模式。一个是类似 ListBox ,但可能是扩展的,所以你可能想要使用 System.Windows.Forms.ListBox 功能,或创建一些其他控件。与选项一样,您可以只创建类似列表框的界面,实现它,并允许您的用户创建替代实现。第二种模式应该显示一些新的行为。



你的问题不是继承自 ScrollableControl ,而是继承一般。



以下是解决问题的方法。您需要使用两个子控件创建一个用户控件:每个子控件代表一个单独的模式。首先,您需要从定义它的通用接口开始。两个子控件中的每一个都应该实现它的接口(你已经命名了它的一个成员 - SelectedIndex )。然后,您可能需要将此接口扩展到两个特定接口。它更像是类似列表框的控件。如果您希望用户覆盖父控件类,则可以添加方法 IListBox GetListBox()。然后,用户可以通过覆盖此方法并为此模式提供备用子控件来更改列表模式的功能。您可能需要也可能不需要这部分功能;我从你的评论中无法理解。所以,你可以将这个功能用于一个或另一个模式,所有模式,或者没有,这取决于你,但现在你知道了这个想法。



一次只能看到这两个控件中的一个。模式切换(你应该定义一个枚举类型,其中两个成员代表模式,并且这种类型的读/写属性,要切换)应该通过隐藏一个子控件并显示另一个子控件来完成。



现在,我建议你从 System.Windows.Forms.Control 派生你的父控件,你的孩子控制实现模式 - 来自你想要的任何东西。如果类用户可以覆盖这些控件的实现,那么你甚至不关心。您只提供接口,使用您想要的基类编写默认实现,并且用户可以使用任何其他基类重新实现它。



-SA
You live too many unknown detail of functionality. I''ll try to go in a most general way.

You probably need to have two modes of the same control. One is something like ListBox, but probably is extended, so you may want to use the System.Windows.Forms.ListBox functionality, or create some other control. As on option, you can create just the "list-box-like" interface, implement it, and allow your user to create alternative implementation. The second mode should show some new behavior.

Your problem is not inheriting from ScrollableControl, but inheriting in general.

Here is how you can work around it. You need to create a user control with two child controls: each one representing a separate mode. First, you need to start with defining it''s common interface. Each of the two child controls should implement its interface (you already named one member of it — SelectedIndex). And then you may need to extend this interface to two specific interfaces. It''s more about the list-box-like control. If you want you parent control class to be overridden by the user, you may add a method IListBox GetListBox(). Then the user would be able to change the functionality of list mode by overriding this method and supplying an alternative child control for this mode. You may or may not need this part of functionality; I fail to understand it from your comment. So, you can have this functionality for one or another mode, all modes, or none, it''s up to you, but now you know the idea.

Only one of these two controls should be visible at a time. Mode switch (you should define a enumeration type with two members representing modes, and the read/write property of this type, to switch) should be done by hiding one child control and showing another one.

Now, I suggest you derive your parent control from System.Windows.Forms.Control, and your child controls implemented modes — from whatever you want. If the implementation of those controls can be overridden by the class user, it''s not even your concern. You only provide the interface, write your default implementation with the base class you want, and the user can re-implement it using any other base class.

—SA


覆盖怎么样

What about overriding
protected virtual CreateParams CreateParams
{
  get {...}
}



然后你可以根据需要修改样式



WS_HSCROLL有一个值0x00100000L

WS_VSCROLL的值为0x00200000L



窗口样式 [ ^ ]



祝你好运

Espen Harlinn


You can then modify the Style as needed

WS_HSCROLL has a value of 0x00100000L
WS_VSCROLL has a value of 0x00200000L

Window Styles[^]

Best regards
Espen Harlinn


这篇关于没有ScrollableControl的滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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