简体   繁体   English

如何使赢表上的区域可滚动?

[英]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: 我们应该能够对每个订单执行以下操作:

  1. Each item will occupy not more than one line. 每个项目最多占用一行。 As the area specified for it on the win form is limited, as more items comes in, I want to make the area scrollable. 由于获胜表格中为其指定的区域是有限的,因此随着更多物品的出现,我想使该区域可滚动。
  2. According to the time left the background color of the line should also change. 根据剩余时间,该行的背景色也应更改。
  3. There is a DONE button next to it. 旁边有一个“完成”按钮。 So, if the item is selected and DONE is pressed, the item is moved off the list. 因此,如果选择了该项目并按了DONE,则该项目将从列表中移出。

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 - 正如评论中所建议的,您可以使用网格,但是如果它不符合您的要求,这就像您可以做的事情-

  • Create a custom user control which will have a label control for your order detail and a Done button. 创建一个自定义用户控件,该控件将具有用于您的订单详细信息的标签控件和一个“完成”按钮。 Something like this ( sure you will design it better! ). 这样的事情( 确定您会设计得更好! )。 The label will be empty initially and you will pass then from outside, using a public property for example, while creating the control. 标签最初是空的,然后您将在创建控件时使用例如公共属性从外部传递标签。

在此处输入图片说明

  • 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM