コード例 #1
0
 public ExportChooseFormController(IExportChooseFormModel model, ExportChooseForm formView)
 {
     this.model    = model;
     this.formView = formView;
     model.Initialize();
     formView.DisableConfirmButton();
     formView.Show();
 }
コード例 #2
0
        public ExportChooseForm()
        {
            InitializeComponent();
            model = new ExportChooseFormModel(matrix);
            model.RegisterExportPointMatrixObserver(this);
            controller = new ExportChooseFormController(model, this);
            int rowCount    = model.GetRowCount();
            int columnCount = model.GetColumnCount();

            // 初始化 TableLayoutPanel
            controlTableLayoutPanel.Controls.Clear();
            controlTableLayoutPanel.ColumnStyles.Clear();
            controlTableLayoutPanel.RowStyles.Clear();
            // 初始化 TableLayoutPanel 的列
            controlTableLayoutPanel.ColumnCount = columnCount;
            for (int i = 0; i < columnCount; i++)
            {
                controlTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F / columnCount));
            }
            // 初始化 TableLayoutPanel 的行
            controlTableLayoutPanel.RowCount = rowCount;
            for (int i = 0; i < rowCount; i++)
            {
                controlTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F / rowCount));
            }
            // 往 TableLayoutPanel 中添加按钮
            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    Button btn = new Button
                    {
                        Name = "button_" + j + "_" + i,
                        Text = model.GetExportPointText(i, j),
                        Dock = DockStyle.Fill,
                    };
                    if (model.GetExportPointAvaliable(i, j))
                    {
                        btn.ForeColor = Color.Red;
                    }
                    // 为每一个按钮添加鼠标点击事件回调函数
                    btn.MouseClick += new MouseEventHandler(Button_MouseClick);
                    controlTableLayoutPanel.Controls.Add(btn);
                    btnDictionary.Add(GetDictionaryKey(i, j), btn);
                }
            }
        }