[英]How make an area on win form scrollable?
Items like below have to be accommodated on a specific area on WinForm. 如下所示的项目必须放在WinForm的特定区域中。
"Order 1 ------------ Time Left: 00:20:00" “订单1 ------------剩余时间:00:20:00”
"Order 2 ------------ Time Left: 01:30:20" “订单2 ------------剩余时间:01:30:20”
We should be able to perform the following action on the each order: 我们应该能够对每个订单执行以下操作:
My question is what C# Form control can be used for it. 我的问题是可以使用什么C#窗体控件。 I was thinking of labels, but how to make the area scrollable if there are many of them.
我当时在考虑标签,但是如果标签很多,如何使区域可滚动。 If not labels, what else is suggested?
如果没有标签,还建议什么?
As suggested in comments, you can use grid, but in case it does not suits your requirements, this is like something what you can do - 正如评论中所建议的,您可以使用网格,但是如果它不符合您的要求,这就像您可以做的事情-
Define an Event
on this control, and raise this event when the Done button is clicked. 在此控件上定义一个
Event
,并在单击“完成”按钮时引发此事件。 This is required for your main form to know that when to remove this user control. 这是您的主窗体需要知道何时删除此用户控件的必要条件。
Add a FlowLayoutPanel
to your main form. 将
FlowLayoutPanel
添加到您的主窗体。 This will be the container for your user controls. 这将是用户控件的容器。 Make sure to set the following so that the controls are created as desired
确保设置以下内容,以便根据需要创建控件
this.flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
this.flowLayoutPanel1.WrapContents = false;
this.flowLayoutPanel1.AutoScroll = true;
Now you can start adding your custom control to this FlowLayoutPanel
, either by loop or the way you like. 现在,您可以通过循环或您喜欢的方式开始将自定义控件添加到此
FlowLayoutPanel
。 The control will added in linear way, one in each line, and you will also get scroll it it exceeds the given space. 控件将以线性方式添加,每行添加一个,并且滚动超过给定空间时也会滚动。
Make sure to define event handler for the control, so that you know when to remove the control. 确保为控件定义事件处理程序,以便您知道何时删除控件。 And of course you can set other properties like back groung color etc. That's not going to be any problem.
当然,您可以设置其他属性,例如,背景色等。这不会有任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.