简体   繁体   English

如何确定哪个UserControl在FlowLayoutPanel的顶部?

[英]How to determine which UserControl is at the top of a FlowLayoutPanel?

I'm creating an accounting-like software and doing the General Ledger. 我正在创建类似会计的软件并进行总帐管理。 Now my plan is to have a UserControl called Entry, which shows and have Properties called: Date, Details, Amount. 现在,我的计划是拥有一个名为Entry的UserControl,该控件显示并具有名为:Date,Details,Amount的Properties。 I have two FlowLayoutControls, one for Debit, one for Credit. 我有两个FlowLayoutControls,一个用于借记,一个用于贷记。

What I want to achieve: 我要实现的目标:

As I slide the Debit side down, I want the credit to automatically slide down to an entry with a same or nearby date. 当我向下滑动借方时,我希望贷方自动向下滑动到具有相同或附近日期的条目。 Or to the same month, when the Ledger is balanced. 或到当月帐本平衡的同月。

My idea: 我的点子:

Determine the highest visible UserControl, get its Date value. 确定最高可见的 UserControl,获取其Date值。 Then on the other side, go through every UserControl and its Date value and scroll it to the one that fits the above description best. 然后在另一侧,遍历每个UserControl及其Date值,并将其滚动到最适合上述描述的那个。

Can anybody please help me with the coding and the properties of the FlowLayoutPanels in order to achieve this? 有人可以帮助我实现FlowLayoutPanels的编码和属性吗?

Thank you. 谢谢。

Implement the FLP's Scroll event. 实现FLP的Scroll事件。 Iterate its controls and find out which one is located at the top: 迭代其控件,并找出位于顶部的控件:

    private void flowLayoutPanel1_Scroll(object sender, ScrollEventArgs e) {
        var top = new Point(1, 1);    // tweak if necessary
        foreach (Control ctl in flowLayoutPanel1.Controls) {
            if (ctl.Bounds.Contains(top)) {
                // Found the control, do your stuff
                //...
                break;
            }
        }
    }

Cast the ctl to your user control type and retrieve the property you want. ctl强制转换为用户控件类型,然后检索所需的属性。 Then iterate the other FLP to find the matching control, set the FLP's AutoScrollPosition to scroll it into view. 然后迭代另一个FLP以找到匹配的控件,设置FLP的AutoScrollPosition使其滚动到视图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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