0

我有一个程序可以显示在某个位置上运行的候选人。例如总统。我使我所有的控件动态化。我创建了一个FlowLayoutPanel,里面是一个RadioButton有一个.Text候选的。

我的代码:

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

    FlowLayoutPanel PresPanel = new FlowLayoutPanel();

    private void PanelPresident()
    {
        Label PresLabel = new Label();
        PresLabel.Text = "PRESIDENT";
        PresLabel.AutoSize = true;
        PresLabel.Location = new Point(50, 210);
        PresLabel.Font = new Font(this.Font, FontStyle.Bold);
        PresLabel.Font = new Font("Courier New", 15);
        PresLabel.ForeColor = Color.Aquamarine;
        this.Controls.Add(PresLabel);

        PresPanel.Size = new Size(160, 300);
        PresPanel.Location = new Point(30, 240);
        PresPanel.FlowDirection = FlowDirection.TopDown;
        PresPanel.BorderStyle = BorderStyle.FixedSingle;
        PresPanel.AutoScroll = true;
        PresPanel.BackColor = Color.Maroon;
        PresPanel.WrapContents = false;
        Controls.Add(PresPanel);

        PresPanel.SuspendLayout();

        try
        {
            string cmdPres = "SELECT (LastName + ', ' + FirstName + ' ' + MiddleName) as PresName, " +
                        "imgPath as PresImagePath, " + "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 PresimagePath, int PresID)
    {
        RadioButton Presradio = new RadioButton { Text = PresName, Parent = PresPanel };
        Presradio.AutoSize = false;
        Presradio.Size = new Size(130, 130);
        Presradio.Image = new Bitmap(Image.FromFile(PresimagePath), 90, 90);
        Presradio.TextImageRelation = TextImageRelation.ImageAboveText;
        Presradio.CheckAlign = ContentAlignment.BottomCenter;
        Presradio.ImageAlign = ContentAlignment.MiddleCenter;
        Presradio.TextAlign = ContentAlignment.MiddleCenter;
        Presradio.ForeColor = Color.LimeGreen;

        Presradio.Tag = PresID;
    }

我的问题是,如果单选按钮的文本很长,图片将不适合。它没有显示全貌。flowlayoutpanel即使文本很长,您能否通过将我的图片放入其中来帮助我解决此问题。谢谢 :)

4

0 回答 0