我有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
。