0

基本的に、私は tablelayoutpanel を持っています。現在、POS システムに使用されています。ボタン コントロールで SetColumnSpan を呼び出すと、tablelayoutpanel によって余分な行が追加され、画面レイアウトが台無しになります。

誰もこれに遭遇したことがありますか?

パネル内の各空きスペースには空白のボタンが割り当てられ、画面が編集モードの場合、ボタンを追加/編集および削除できます。以下は、ボタンの変更を適用するコードです。

クリーンアップされたコードを少し編集

void button_MouseUp(object sender, EventArgs e)
    {
        try
        {
            TableLayoutPanelCellPosition pos = tableLayoutPanel1.GetCellPosition((Control) sender);
            POSButton productButton = GetProductButton(sender);

            tableLayoutPanel1.SuspendLayout();

            if (productButton == null)
            {
                DeleteButton(sender, pos);
                return;
            }

            productButton.Dock = DockStyle.Fill;

            EditModeHookButton(productButton);
            tableLayoutPanel1.Controls.Remove((Control) sender);

            tableLayoutPanel1.Controls.Add(productButton, pos.Column, pos.Row);

            if (productButton.TableRowSpan > 0)
                tableLayoutPanel1.SetRowSpan(productButton, productButton.TableRowSpan);

            if (productButton.TableColumnSpan > 0)
                tableLayoutPanel1.SetColumnSpan(productButton, productButton.TableColumnSpan);

            buttonManager.Save(tableLayoutPanel1);
            tableLayoutPanel1.ResumeLayout();
        }
        catch(OperationCanceledException)
        {

        }
    }

ボタン レイアウトをシリアル化するボタン マネージャー関数を次に示します。

    public void Save(ScreenTabkeLayoutPanel panel)
    {
        List<ButtonSaveInfo> buttons = new List<ButtonSaveInfo>();
        foreach (Control control in panel.Controls)
        {
            TableLayoutPanelCellPosition pos = panel.GetCellPosition(control);
            ButtonSaveInfo info;

            if (control is POSButton)
                info = ((POSButton)control).ConvertToButtonInfo(pos);
            else
                info = control.ConvertToButtonInfo(pos);

            buttons.Add(info);
        }

        AppDataSerializer.SaveBinary(buttons,buttonPath);
    }

画面にボタンをロード/設定するコードは次のとおりです

 private void LoadButtonsFromFile(ScreenTabkeLayoutPanel panel)
    {
        List<ButtonSaveInfo> buttons = AppDataSerializer.LoadBinary<List<ButtonSaveInfo>>(buttonPath);
        panel.SuspendLayout();
        foreach (ButtonSaveInfo info in buttons)
        {
            switch (info.ButtonType)
            {
                case (int) ButtonType.PRODUCT:

                    POSButton productButton = info.ConvertToPosButton();
                    wireButtonEvents(productButton);
                    panel.Controls.Add(productButton, info.ColumnIndex, info.RowIndex);

                    if (productButton.TableRowSpan > 0)
                        panel.SetRowSpan(productButton, productButton.TableRowSpan);

                    if (productButton.TableColumnSpan > 0)
                        panel.SetColumnSpan(productButton, productButton.TableColumnSpan);


                    break;

                default:
                    Control control = BuildBlankButton();
                    wireButtonEvents(control);
                    panel.Controls.Add(control, info.ColumnIndex, info.RowIndex);
                    break;
            }
        }
        FillEmptySpacesWillBlankButtons(panel);
        panel.ResumeLayout();
    }

ありがとうございます。

4

2 に答える 2

1

Are you setting the RowSpan to a value greater than the number of rows in the table? This might cause an extra row to be rendered. Other than that you will need to provide more information/code for us to figure it out :)

于 2011-03-08T14:45:52.817 に答える
1

スパンされたセルにコントロールがないことを確認してください。

セル 0,0 で列スパンを 2 に設定し、コントロールを 1,0 に配置すると、レイアウト エンジンが混乱します。質問ですべてのセルに空白のボタンを追加したと指定したため、これがここで起こっている可能性があります。

スパンする予定のセルからコントロールを削除してください。

また、特に自動サイズ変更でセルをスパンする場合、テーブル レイアウトが単にあきらめる状況がいくつかあります。

于 2011-03-08T17:05:18.443 に答える