惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - 随风而去

easyui表格格线错位 从sp_executesql中返回table型数据及动态SQL语句的参数化查询 vb6转vb.net wss 备份与还原相关的站点 怎么用javascript进行拖拽 gridview无数据行时显示表头的方法 WSS3 顺序工作流之发布链接 域FRS复制策略失败后用ansiedit.msc用的着的几个值.恢复FRS对象或属性缺少 工作流一些链接 xp下自定义纸张 有用的几个系统过程 不错的CRM软件 wss3 Beta2 TR下载 终于完成第一个Wss3上WebPart(treeview 目录树形控件) CODEDOM动态编译相关资料 asp.net 变量保存方法 利用IsPostBack检查网页是不是第一次进入(asp.net) 微软的设计思想:总感觉有点返祖现象,以前VB中很方便的功能,在C#中却要很复杂才能实现 treeview 用友u8之远程信道错误解决方法
运行时选择界面上控件的方法
随风而去 · 2006-07-31 · via 博客园 - 随风而去

看到很多入门人员(C#我也是入门者)找如何在运行时选择界面上控件,因此写了这段代码,希望有所帮助.
用左键确定选择,选择后置控件的背景颜色(如能像微软一样显示一个句柄就更好,觉得不难)
        static Control oldCtr;
        static Color oldColor;
        private void timer1_Tick(object sender, EventArgs e)
        {
            //左键确认选择
            if (Control.MouseButtons == MouseButtons.Left)
            {
                Control ctr = FindControl(this);
                if (ctr != null)
                {
                    //复原先前控件属性
                    if (oldCtr != null)
                    {
                        oldCtr.BackColor = oldColor;
                    }
                    //保存选择并置选择状态
                    oldCtr = ctr;
                    oldColor = ctr.BackColor;
                    ctr.BackColor = Color.Red;
                }
            }
 
        }

        private Control FindControl(Control pControl)
        {
            Control ctr ;
            ctr = pControl.GetChildAtPoint(pControl.PointToClient(Control.MousePosition));
            //直接在容器中
            if (ctr != null)
            {
                //无子控件
                if (ctr.Controls.Count == 0)
                {
                    return (ctr);
                }
                else
                {
                    Control  ctr2 = FindControl(ctr);                       
                    if (ctr2 != null)
                    {
                        //子控件处于选择状态则返回子控件
                        return (ctr2);
                    }
                    else
                    {
                        //子控件不处于选择状态则返回容器控件
                        return (ctr);
                    }
                }
            }
            return (null);
        }