【提问】遍历窗体控件设置样式只生效一个

crystal_lz 2012-12-12 11:49:31

private void SetRadioButtonRgn() {
IntPtr hRgn = Win32.CreateRoundRectRgn(0, 1, radioButton1.Height, radioButton1.Height + 1, radioButton1.Height, radioButton1.Height);
//for (int i = 1; i <= 6; i++) {
// MessageBox.Show(this.Controls["radioButton" + i].Handle.ToString());
// Win32.SetWindowRgn(this.Controls["radioButton" + i].Handle, hRgn, true);
// //System.Threading.Thread.Sleep(500);
//}
//for (int i = 0; i < this.Controls.Count; i++) {
// if(this.Controls[i] is RadioButton)
// Win32.SetWindowRgn(this.Controls[i].Handle, hRgn, true);
//}
Win32.SetWindowRgn(this.Controls["radioButton1"].Handle, hRgn, true);
Win32.SetWindowRgn(this.Controls["radioButton2"].Handle, hRgn, true);
}

在窗体上 有六个radiobutton我想对他们进行切割只有那个选择的原点
在上面代码中 用字符串去索引的 只对第一个有用 用int索引的 只生效最后执行的一个 其他都是失败
然后 复制的两个代码值和 字符串索引的结果一样只生效最先执行的那个 其他的都失败
求解、、
...全文
123 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2012-12-13
  • 打赏
  • 举报
回复
IntPtr hRgn1 = Win32.CreateRoundRectRgn(0, 1, radioButton2.Height, radioButton2.Height + 1, radioButton2.Height, radioButton2.Height); Win32.SetWindowRgn(this.Controls["radioButton2"].Handle, hRgn1, true);
crystal_lz 2012-12-13
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
IntPtr hRgn1 = Win32.CreateRoundRectRgn(0, 1, radioButton2.Height, radioButton2.Height + 1, radioButton2.Height, radioButton2.Height); Win32.SetWindowRgn(this.Controls["radioButton2"].……
貌似不是这个的问题 因为他们要截取的区域都是一样的 所以随便用哪一个 radiobutton 来提取参数都是一样的 如果 真是这个问题的话 那么也不会出现第一个有效和最后一个有些 只会出现对radiobutton1有效 虽然 自己用自定义控件搞定了 不过对这个问题 还是比较好奇 最开始 我以为是出在 Handle 上面的问题 因为 以前在循环中提取某系列东西的Handle属性的时候出过错 如果循环里面 插入一个 thread.Sleep的话循环一次 暂停一下却又不出错 表示对于这些奇葩问题 很郁闷 不知道是不是我真哪里搞错了

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧