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

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Cyberwarzone
Cyberwarzone
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX
博客园_首页
博客园 - 聂微东
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
T
Tenable Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
A
About on SuperTechFans
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
D
Docker
P
Proofpoint News Feed

博客园 - 随风而去

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);
        }