怎样用最快的方法找到winform中的tab键值最小的前三个控件?

BillTuan 2009-04-08 11:32:04
怎样用最快的方法找到winform中的tab键值最小的前三个控件?

...全文
134 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
BillTuan 2009-04-09
  • 打赏
  • 举报
回复
漏给了12楼的友情分,
Sorry!
BillTuan 2009-04-09
  • 打赏
  • 举报
回复
谢谢九楼的兄弟及各位!

结帖迟了,
抱歉!
麻子Mozart 2009-04-08
  • 打赏
  • 举报
回复
帮顶
wartim 2009-04-08
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Control C = this.GetNextControl(null, true); // 返回 tabindex=0 的控件
MessageBox.Show(C.Name);
C = this.GetNextControl(C, true); // 返回 tabindex=1 的控件
MessageBox.Show(C.Name);
C = this.GetNextControl(C, true); // 返回 tabindex=2 的控件
MessageBox.Show(C.Name);
}
}
}
BillTuan 2009-04-08
  • 打赏
  • 举报
回复
6楼的思路是可行的哈。

有什么简捷的方法不~?
BillTuan 2009-04-08
  • 打赏
  • 举报
回复
6楼:
考虑到FORM上有容器控件的情况了吗?

这个问题有点另类的哈,
先大家讨论一下,
晚上结帖~
游北亮 2009-04-08
  • 打赏
  • 举报
回复
2楼我想的太复杂了,直接定义3个变量,一个循环就得出了

int a=-1,b=-1,c=-1;
foreach(Control item in this.Controls){
int d = item.TabIndex;
if(d<a)a=d;
else if(d<b)b=d;
else if(d<c)c=d;
}



得出:a最小,b第二小,c第三小
mykelly6 2009-04-08
  • 打赏
  • 举报
回复
没看懂。。
windsea123 2009-04-08
  • 打赏
  • 举报
回复
控件遍历,放入集合,按tab排序。
zzxap 2009-04-08
  • 打赏
  • 举报
回复
TabIndex=0
TabIndex=1
TabIndex=2
游北亮 2009-04-08
  • 打赏
  • 举报
回复
先按控件的TabIndex进行快速排序
然后取前3条记录
ztmdsbt 2009-04-08
  • 打赏
  • 举报
回复
帮顶,我也想知道.
guzhonghua 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wartim 的回复:]
C# codeusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, Eve…
[/Quote]
九楼的方法不错,但是要注意一下,微软的这个方法有问题。
我刚才测试了一下,如果窗体中有GridView的时候,他还会找到GridView中使用的水平滚动条和垂直滚动条。
所以到要判断找到的空间的Parent属性是不是当前的窗体。
i3men 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wartim 的回复:]
C# codeusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, Eve…
[/Quote]
应该就这样的
wuyq11 2009-04-08
  • 打赏
  • 举报
回复
通过GetNextControl查询控件
参考

111,126

社区成员

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

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

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