两个动态FlowLayoutPanel内部带有动态radiobuttons

时间:2013-10-21 15:16:45

标签: c# winforms sql-server-2008

我有2个动态FlowLayoutPanel s,它带有动态无线电按钮。现在我的问题是,是否可以在一个FlowLayoutPanel中制作两个Form_Load个?因为,我这样做了:

    private void FVotingArea_Load(object sender, EventArgs e)
    {
        PanelPresident();

        PresPanel.SuspendLayout();

        BtnVote.CenterHorizontally();

        try
        {
            string cmdPres = "SELECT (FirstName + ' ' + MiddleName + ' ' + LastName) as PresName, " +
                        "imgPath as ImagePath, " + "id as PresID FROM TableVote WHERE Position='President'";
            using (SqlCommand Prescom = new SqlCommand(cmdPres, sc))
            {
                if (sc.State != ConnectionState.Open) sc.Open();
                SqlDataReader Presreader = Prescom.ExecuteReader();
                while (Presreader.Read())
                {
                    PresRadioButton(Presreader.GetString(0), Presreader.GetString(1), Presreader.GetInt32(2));
                }
                Presreader.Close();
                sc.Close();
                PresPanel.ResumeLayout(true);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        PanelIVPresident();
        IVPresPanel.SuspendLayout();
        try
        {
            string cmdIVPres = "SELECT (FirstName + ' ' + MiddleName + ' ' + LastName) as IVPresName, " +
                            "imgPath as ImagePath, " + "id as IVPresID FROM TableVote WHERE Position='Internal VP'";
            using (SqlCommand IVPrescom = new SqlCommand(cmdIVPres, sc))
            {
                if (sc.State != ConnectionState.Open) sc.Open();
                SqlDataReader IVPresreader = IVPrescom.ExecuteReader();
                while (IVPresreader.Read())
                {
                    IVPresRadioButton(IVPresreader.GetString(0), IVPresreader.GetString(1), IVPresreader.GetInt32(2));
                }
                IVPresreader.Close();
                sc.Close();
                IVPresPanel.ResumeLayout(true);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

radiobutton的{​​{1}}似乎没有进入第二个Internal VP。它只是前往总统所在的第一个FlowLayoutPanel

原作是这样的:

FlowLayoutPanel

但我如何制作另一个 public FVotingArea() { InitializeComponent(); Load += FVotingArea_Load; } FlowLayoutPanel PresPanel = new FlowLayoutPanel(); private void PanelPresident() { Label PresLabel = new Label(); PresLabel.Text = "PRESIDENT :"; PresLabel.AutoSize = true; PresLabel.Location = new Point(30, 20); PresLabel.Font = new Font(this.Font, FontStyle.Bold); PresLabel.Font = new Font("Courier New", 18); PresLabel.ForeColor = Color.Orange; this.Controls.Add(PresLabel); PresPanel.Size = new Size(630, 160); PresPanel.Location = new Point(50, 50); PresPanel.FlowDirection = FlowDirection.LeftToRight; PresPanel.BorderStyle = BorderStyle.FixedSingle; PresPanel.AutoScroll = true; PresPanel.WrapContents = false; Controls.Add(PresPanel); } private void FVotingArea_Load(object sender, EventArgs e) { PanelPresident(); PresPanel.SuspendLayout(); BtnVote.CenterHorizontally(); try { string cmdPres = "SELECT (FirstName + ' ' + MiddleName + ' ' + LastName) as PresName, " + "imgPath as ImagePath, " + "id as PresID FROM TableVote WHERE Position='President'"; using (SqlCommand Prescom = new SqlCommand(cmdPres, sc)) { if (sc.State != ConnectionState.Open) sc.Open(); SqlDataReader Presreader = Prescom.ExecuteReader(); while (Presreader.Read()) { PresRadioButton(Presreader.GetString(0), Presreader.GetString(1), Presreader.GetInt32(2)); } Presreader.Close(); sc.Close(); PresPanel.ResumeLayout(true); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void PresRadioButton(string PresName, string imagePath, int PresID) { RadioButton Presradio = new RadioButton { Text = PresName, Parent = PresPanel }; Presradio.AutoSize = false; Presradio.Size = new Size(150, 130); Presradio.Image = new Bitmap(Image.FromFile(imagePath), 90, 90); Presradio.TextImageRelation = TextImageRelation.ImageAboveText; Presradio.CheckAlign = ContentAlignment.BottomCenter; Presradio.CheckAlign = ContentAlignment.BottomCenter; Presradio.ImageAlign = ContentAlignment.MiddleCenter; Presradio.TextAlign = ContentAlignment.MiddleCenter; Presradio.ForeColor = Color.LimeGreen; Presradio.Tag = PresID; Presradio.CheckedChanged += Presradio_CheckedChanged; } public void Presradio_CheckedChanged(object sender, EventArgs e) { try { RadioButton Presradio = sender as RadioButton; int PresID = (int)(Presradio.Tag ?? -1); TxtPresID.Text = PresID.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } ?我会再次进入flowlayoutpanel吗?因为我试过这样做,但是form_load的所有位置只是去了总统的Internal VP ..它没有进入我新制作的新flowlayoutpanel

0 个答案:

没有答案