代码如下
//添加一个RadioButton 控件 .然后计算新控件显示位置
public void addNpc(Image img, int atype, int asubtype)
{
RadioButton rb = new RadioButton(); rb.Appearance = Appearance.Button;
rb.AutoSize = true;
rb.Location = new System.Drawing.Point(0, 0);
rb.Size = new System.Drawing.Size(32, 32);
rb.AutoSize = false; rb.BackgroundImage = img; rb.BackgroundImageLayout = ImageLayout.Zoom; rb.TabStop = true;
rb.UseVisualStyleBackColor = true; rb.Tag = new Point(atype, asubtype); this.panel1.Controls.Add(rb);
calculateSize(); }
private int rbNumInCol;
private int rbNumInRow; public void calculateSize()
{
panel1.Width = this.Width;
rbNumInCol = panel1.Width / 50;
rbNumInRow = rbsCnt / rbNumInCol;
if (rbsCnt % rbNumInCol != 0) rbNumInRow++;
panel1.Height = rbNumInRow * 40; int tx = 0;
int ty = 0; foreach (Control tCorl in this.panel1.Controls)
{
//问题出现在这里.
/*
我需要判断panel1上面的所有RadioButton控件.然后做位置调整.
但是tCorl.GetType() is RadioButton得到的结果永远是false.
请教.这里应该如何写(我试过 tCorl.GetType() == typeof(RadioButton) 也不对.)
在watch里面出现的问题如下:
This expression causes side effects and will not be evaluated;
我应该如何处理这种情况
*/
if (tCorl.GetType() is RadioButton)
{
RadioButton trb = (RadioButton)tCorl;
trb.Left = tx;
trb.Top = ty;
tx += 50;
if (tx + 50 > panel1.Width)
{
ty += 40;
tx = 0;
}
}
} }
//添加一个RadioButton 控件 .然后计算新控件显示位置
public void addNpc(Image img, int atype, int asubtype)
{
RadioButton rb = new RadioButton(); rb.Appearance = Appearance.Button;
rb.AutoSize = true;
rb.Location = new System.Drawing.Point(0, 0);
rb.Size = new System.Drawing.Size(32, 32);
rb.AutoSize = false; rb.BackgroundImage = img; rb.BackgroundImageLayout = ImageLayout.Zoom; rb.TabStop = true;
rb.UseVisualStyleBackColor = true; rb.Tag = new Point(atype, asubtype); this.panel1.Controls.Add(rb);
calculateSize(); }
private int rbNumInCol;
private int rbNumInRow; public void calculateSize()
{
panel1.Width = this.Width;
rbNumInCol = panel1.Width / 50;
rbNumInRow = rbsCnt / rbNumInCol;
if (rbsCnt % rbNumInCol != 0) rbNumInRow++;
panel1.Height = rbNumInRow * 40; int tx = 0;
int ty = 0; foreach (Control tCorl in this.panel1.Controls)
{
//问题出现在这里.
/*
我需要判断panel1上面的所有RadioButton控件.然后做位置调整.
但是tCorl.GetType() is RadioButton得到的结果永远是false.
请教.这里应该如何写(我试过 tCorl.GetType() == typeof(RadioButton) 也不对.)
在watch里面出现的问题如下:
This expression causes side effects and will not be evaluated;
我应该如何处理这种情况
*/
if (tCorl.GetType() is RadioButton)
{
RadioButton trb = (RadioButton)tCorl;
trb.Left = tx;
trb.Top = ty;
tx += 50;
if (tx + 50 > panel1.Width)
{
ty += 40;
tx = 0;
}
}
} }
解决方案 »
- C# 获得一个窗口的句柄后如何置为焦点
- 微软的 WPF 为何而生?只为了界面更漂亮?
- 可访问性不一致
- 求微软系列丛书
- 学习制作控件中,那位大哥有控件的源码啊? 给小弟学习学习
- webBrowser1这个控件如何只让它保存成html文件
- 把datagrird 导入 excel 我想在excel第一行显示这是什么表 比如说建三江税务表,怎么插入
- 请大家看一看,为什么request session报错!!!!
- 怎么在datagrid custom webcontrols里实现动态列的数据绑定功能?谢谢!
- C# 如何开发微信pc端 自动发送消息。
- 同样的做法在VS2003下可以运行,为什么在VS2005下不能运行,请高手指点.(在VB.NET中也有发贴子)
- 提示:未将对象引用设置到对象的实例
foreach (Control con in this.Controls)
{
if (con.GetType() == typeof(SagaViewerPanel.ClassContainer))
if (classID == ((SagaViewerPanel.ClassContainer)con).ClassID)
return true;
}
这是我做的一个project里的代码,if (con.GetType() == typeof(SagaViewerPanel.ClassContainer)) 这么写应该没有问题。
或者
foreach (Control tCorl in this.panel1.Controls)
{
RadioButton trb = tCorl as RadioButton;
if( trb != null )
{
...
}
}
代码我没试过,随便说说:)