Winform动态对齐

时间:2016-12-17 12:40:40

标签: c# winforms visual-c#-express-2010

我试图动态地向表单添加一系列控件,但主要问题是它们完全未对齐。我已经尝试更新控制信息并修复了一些小问题,但它们仍未对齐。

我不确定我在对齐问题上缺少什么:

public void loadSkill(string skillName)
    {
        FlowLayoutPanel panel = new FlowLayoutPanel();
        standardSkillsLayoutPanel.Controls.Add(panel);
        panel.Dock = DockStyle.Top;
        panel.Height = 28;
        panel.Width = 450;

        Label skillLabel = new Label();
        panel.Controls.Add(skillLabel);
        skillLabel.MinimumSize = new Size(120, 20);
        skillLabel.MaximumSize = new Size(120, 20);
        skillLabel.Text = skillName;
        skillLabel.Location = new System.Drawing.Point(0, 0);
        skillLabel.Dock = DockStyle.Left;

        Label skillStats = new Label();
        panel.Controls.Add(skillStats);
        skillStats.Text = "DEX + STR";
        skillStats.MinimumSize = new Size(80, 20);
        skillStats.MaximumSize = new Size(80, 20);
        skillStats.Margin = new Padding(3, 0, 3, 0);
        skillStats.Dock = DockStyle.Left;

        Label skillBasePercent = new Label();
        panel.Controls.Add(skillBasePercent);
        skillBasePercent.MinimumSize = new Size(60, 20);
        skillBasePercent.MaximumSize = new Size(60, 20);
        skillBasePercent.Text = "10";
        skillBasePercent.Dock = DockStyle.Left;
        skillBasePercent.Location = new System.Drawing.Point(210, 0);

        NumericUpDown skillCulturalUpdown = new NumericUpDown();
        panel.Controls.Add(skillCulturalUpdown);
        skillCulturalUpdown.MinimumSize = new Size(40, 20);
        skillCulturalUpdown.MaximumSize = new Size(40, 20);
        skillCulturalUpdown.Margin = new Padding(3, 0, 3, 0);
        skillCulturalUpdown.Value = 0;
        skillCulturalUpdown.Dock = DockStyle.Left;

        NumericUpDown skillProfessionalUpdown = new NumericUpDown();
        panel.Controls.Add(skillProfessionalUpdown);
        skillProfessionalUpdown.MinimumSize = new Size(40, 20);
        skillProfessionalUpdown.MaximumSize = new Size(40, 20);
        skillProfessionalUpdown.Margin = new Padding(3, 0, 3, 0);
        skillProfessionalUpdown.Value = 0;
        skillProfessionalUpdown.Dock = DockStyle.Left;

        NumericUpDown bonusUpDown = new NumericUpDown();
        panel.Controls.Add(bonusUpDown);
        bonusUpDown.Value = 0;
        bonusUpDown.MinimumSize = new Size(40, 20);
        bonusUpDown.MaximumSize = new Size(40, 20);
        bonusUpDown.Margin = new Padding(3, 0, 3, 0);
        bonusUpDown.Dock = DockStyle.Left;

        Label skillTotalPercent = new Label();
        panel.Controls.Add(skillTotalPercent);
        skillTotalPercent.Text = "10";
        skillTotalPercent.MinimumSize = new Size(50, 20);
        skillTotalPercent.Dock = DockStyle.Left;
    }

misaligned rows

0 个答案:

没有答案