简体   繁体   English

TableLayoutPanel Winforms未显示所有信息

[英]TableLayoutPanel Winforms not showing all information

I have a really strange set of circumstances that I just can't seem to get to work. 我遇到了一种非常奇怪的情况,我似乎无法上班。 I will let you know what I have and see If you can put me right. 我会让你知道我有什么,看看你能不能说对我。 (The below represents the closest I have been able to get to what I want). (以下代表我所能获得的最接近我想要的东西)。

The idea is that when a day is selected I show a usercontrol that has a lorry's deliveries for that day. 这个想法是,当选择了一天时,我会显示一个用户控件,该控件具有当天该货车的交货。 The thing is that the date may be a range. 问题是日期可能是一个范围。 Therefore I have the following setup thus far: 因此,到目前为止,我有以下设置:

I have a 我有一个

 TableLayoutPanel (Dock = Fill; 1 column (100percent); 1 Row (Autosize). 

Then each selected has a user control (ucSchedulerDay) this is added as a row to the TableLayoutPanel. 然后,每个选定的控件都有一个用户控件(ucSchedulerDay),将其作为一行添加到TableLayoutPanel中。 So take a single day for example, you would have this: 因此,以一天为例,您将拥有:

TableLayoutPanel (Dock = Fill; 1 Column (100%); 1 Row (Autosize).
   - (Row1 Column1) ucSchedulerDay

So the ucSchedulerDay is just a user control that houses a GroupBox (Dock=Fill) and a FlowLayoutPanel (also dock=fill inside the groupbox) 因此,ucSchedulerDay只是一个用户控件,其中包含一个GroupBox(Dock = Fill)和一个FlowLayoutPanel(也是dock = fill在groupbox内)

For each lorry I have another usercontrol added to the FlowLayoutPanel (these have a fixed width) so essentially what I have is the following for one single day 对于每辆卡车,我在FlowLayoutPanel中添加了另一个用户控件(这些控件具有固定的宽度),因此,基本上我每天只有以下内容

TableLayoutPanel (as above (also forgot to mention that AutoScrollBars=True)
  - (Row 1 Column 1) ucSchedulerDay (Dock=Fill(done in code when added))
    - GroupBox (Dock=Fill)
      - FlowLayoutPanel (Dock=Fill)
        - ucLorryDay1
        - ucLorryDay2

工作画面 This works fine as long as all the lorries fit on the screen (see above), so for one day with 2 lorries(or even up to 5 on my monitor) then it's ok. 只要所有的卡车都适合屏幕,此方法就可以正常工作(请参见上文),因此对于一天有2辆卡车(或显示器上最多5辆)的情况就可以了。 However, if I select two days or make the screen smaller, instead of showing the scroll bars but generally having the same layout, it cuts some of the ucLorryDays up and just doesn't display others. 但是,如果我选择两天或缩小屏幕,而不是显示滚动条,但通常具有相同的布局,它会缩短一些ucLorryDays,而不会显示其他内容。

较小的显示或更多的项目出现问题

Note on the above pic how the grey lorry is cut off, even the scroll bar doesn't extend that far. 请注意上面的图片,灰色卡车是如何切断的,即使滚动条也没有延伸那么远。

I don't understand why this isn't working. 我不明白为什么这行不通。 I would really appreciate any help on this, please let me know if you need more information. 非常感谢您的帮助,如果您需要更多信息,请告诉我。

Ok, So I think that the nested GroupBox/UserControl-GroupBox idea was where it all went wrong. 好的,所以我认为嵌套的GroupBox / UserControl-GroupBox想法就是哪里出错了。 I have fixed this by updating the original form to do the following: 我已经通过更新原始表格来解决此问题,以执行以下操作:

  pnlLorries.Controls.Clear();
  DateTime dt_start = monthView1.SelectionStart;
  DateTime dt_end = monthView1.SelectionEnd;
  int rowCounter = 0;
  for (DateTime dt = dt_start; dt.Date <= dt_end; dt = dt.AddDays(1))
  {
    Label lbl = new Label();
    Font ft = new System.Drawing.Font("Calibri", 12);
    lbl.Text = dt.ToShortDateString();
    lbl.Font = ft;
    pnlLorries.Controls.Add(lbl, 0, rowCounter);
    rowCounter++;
    FlowLayoutPanel pnl = new FlowLayoutPanel();
    pnl.Dock = DockStyle.Fill;
    pnl.AutoSize = true;
    DataTable tbl = cDALSettings.DB.GetCannedTable("select * from lorry");
    // Now we simply add these controls to the panel...
    foreach (DataRow row in tbl.Rows)
    {
      ucLorryDay ld = new ucLorryDay(dt, cTypes.ToInt(row["id"]), this);
      pnl.Controls.Add(ld);
    }
    pnlLorries.Controls.Add(pnl, 0, rowCounter);
    rowCounter++;
  }

So I create it all and add in the label. 因此,我将其全部创建并添加标签。 The downside is of course that it is not in a neat little box but even when I did it this way with a groupbox it came back with the same results I was experiencing before. 缺点当然是它不是在一个整洁的小盒子里,但是即使当我用groupbox这样操作时,它也会以与我之前所经历的相同的结果返回。 I suppose the problem was the panel inside a panel (inception style). 我想问题出在面板内部的面板(初始样式)。

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

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