如何在面板中添加单选按钮(左侧和右侧) [英] how to add radio button in a panel (left and right side)

查看:144
本文介绍了如何在面板中添加单选按钮(左侧和右侧)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生您好,

我正在做一个Windows应用程序.我有一个面板,形式如下.
我要在面板的左侧和右侧动态添加单选按钮.
我在左侧添加了4个单选按钮,以及如何添加右侧.


Hello sir,

I am doing one windows application .I have a panel in the form.
i have want to add dynamically radio buttons in the panel left and right.
i added 4 radio buttons left and how to add right.


hr         dfsdfwewr
finance    dfdsfdfsd
accounts   abcddddsd


我要在面板中添加这样的单选按钮.
我还剩下4个按钮,但接下来的4个按钮想来边用怎么办?


我的编码


In a panel i want to add radio button like this.
i added 4 buttons left but next 4 button want to come righ tside how to do?


my coding

void addRadiobutton()
        {
            try
            {
                DataTable dt = new DataTable();
                dt = RoleSecurity.getRoleId();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    RadioButton rdo = new RadioButton();
                    rdo.AutoSize = false;
                    rdo.Height = 20;
                    rdo.Width = 215;
                    rdo.Padding = new Padding(-10);

                    if (i == 4)
                    {
                        rdo.Location = new Point(235, 28);
                    }
                    else if (i > 4)
                    {
                        rdo.Location = new Point(235, rdo.Location.Y + 25 * i);
                    }
                    else
                    {
                        rdo.Location = new Point(6, rdo.Location.Y + 25 * i);
                    }

                    rdo.Font = new System.Drawing.Font(new FontFamily("Mangal"), 9, FontStyle.Bold);
                    rdo.Text = dt.Rows[i]["Rolename"].ToString();
                    pnlRole.Controls.Add(rdo);
                    rdo.CheckedChanged += new EventHandler(radiobuttonchecked);
                }
            }



那是在弄错.该如何解决?

[edit]已添加代码块-OriginalGriff [/edit]



in that am getting wrongly.how to correct that?

[edit]Code block added - OriginalGriff[/edit]

推荐答案

该代码有点不寻常.
我会这样:
That code is a bit unusual.
I would do it this way:
int yLoc = 28;
int xLoc = 6;
for (int i = 0; i < dt.Rows.Count; i++)
    {
    RadioButton rdo = new RadioButton();
    rdo.AutoSize = false;
    rdo.Height = 20;
    rdo.Width = 215;
    rdo.Padding = new Padding(-10);

    if (i == 4)
        {
        yLoc = 28;
        xLoc = 235;
        }

    rdo.Location = new Point(xLoc, yLoc);
    yLoc += 25;

    rdo.Font = new System.Drawing.Font(new FontFamily("Mangal"), 9, FontStyle.Bold);
    rdo.Text = dt.Rows[i]["Rolename"].ToString();
    pnlRole.Controls.Add(rdo);
    rdo.CheckedChanged += new EventHandler(radiobuttonchecked);
    }



[edit] Dunno的方式,但<"更改为<<",已修复-OriginalGriff [/edit]



[edit]Dunno how, but "<" changed to "<<", Fixed - OriginalGriff[/edit]


这篇关于如何在面板中添加单选按钮(左侧和右侧)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆