FlowLayoutPanel
動的ラジオボタンを運ぶこの 2 つの dynamic があります。今私の質問は、2 つFlowLayoutPanel
の を 1つにすることは可能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
の forInternal VP
は 2nd に行かないよう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
..自分がflowlayoutpanel
新しく作った所には行かなかった。