Skip to content

Commit

Permalink
新增主窗口分组折叠,TODO:折叠后窗口大小调整问题
Browse files Browse the repository at this point in the history
  • Loading branch information
何秀奇 committed Jul 9, 2024
1 parent 56fa905 commit e9a6748
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CommunTools/Enums/FuncItemCom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class FuncItemCom
/// 基础通信
/// </summary>
[Flags]
[FuncGroup("Base", "基础通信")]
[FuncGroup("Base", "基础通信协议")]
public enum Com_BaseFuncItem
{
/// <summary>
Expand Down
51 changes: 51 additions & 0 deletions CommunTools/FrmMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ private void FrmMenu_Load(object sender, EventArgs e)

gpb.Location = new Point(20, 33 + totolHeight + 4 * gpbIndex);
gpb.Text = groupInf[1];

Label titleLabel = new Label();
titleLabel.Text = groupInf[1];
titleLabel.Size = new Size(80, 16);
titleLabel.Location = new Point(0, 0);
titleLabel.Click += (s, ev) => ToggleGroupBox(gpb, gpbHeight);
gpb.Controls.Add(titleLabel);

this.Controls.Add(gpb);

totolHeight += gpbHeight;
Expand Down Expand Up @@ -132,6 +140,49 @@ private void box_Click(object sender, EventArgs e)
SkipToFunction(funcUrl);
}

/// <summary>
/// 折叠分组菜单
/// </summary>
/// <param name="gpb"></param>
/// <param name="originalHeight"></param>
private void ToggleGroupBox(GroupBox gpb, int originalHeight)
{
if (gpb.Height == originalHeight)
{
foreach (Control control in gpb.Controls)
{
if (!(control is Label))
{
control.Visible = false;
}
}
gpb.Height = 20; // 折叠后的高度

// 重新计算窗体高度
this.Size = new System.Drawing.Size(Size.Width, Size.Height - originalHeight + 20);

// 这里有问题,TODO

}
else
{
foreach (Control control in gpb.Controls)
{
control.Visible = true;
}
gpb.Height = originalHeight;

// 重新计算窗体高度
this.Size = new System.Drawing.Size(Size.Width, Size.Height + originalHeight - 20);

// 这里有问题,TODO
}

// 重新设置最小和最大尺寸
this.MinimumSize = this.Size;
this.MaximumSize = this.Size;
}

/// <summary>
/// 点击按钮跳转到功能
/// </summary>
Expand Down

0 comments on commit e9a6748

Please sign in to comment.