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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
V
V2EX
G
Google Developers Blog
F
Full Disclosure
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
H
Hacker News: Front Page
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
About on SuperTechFans
The Cloudflare Blog
C
Cisco Blogs
D
DataBreaches.Net
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
P
Privacy International News Feed
Microsoft Security Blog
Microsoft Security Blog
Help Net Security
Help Net Security
Recorded Future
Recorded Future
PCI Perspectives
PCI Perspectives
S
Schneier on Security
AI
AI
N
News | PayPal Newsroom
雷峰网
雷峰网
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
L
LINUX DO - 最新话题
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
Schneier on Security
Schneier on Security
S
Securelist
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
AWS News Blog
AWS News Blog
TaoSecurity Blog
TaoSecurity Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 三生石上(FineUI控件)
C
CXSECURITY Database RSS Feed - CXSecurity.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cloudbric
Cloudbric
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
C
Check Point Blog
S
Security Affairs

博客园 - 老羽

推荐AspNetPager分页控件 SqlServer2005中分页代码测试 WM中实现Splash动画效果 自定义合并多文件协议设计 JScript中Date.getTime转.Net中的DateTime .net中处理C/C++中的位域 POOM(Pocket Outlook Object Model)开发介绍及应用(转) 多线程执行多任务的DEMO GPRS管理与创建APN拨号连接 WM中电话相关的技巧 - 老羽 - 博客园 一道面试题题解 【转】Windows Mobile控制面板程序 [转]Windows Mobile上的服务程序 Smartphone2003开发总结一:Form总结 C++常用技巧一(整理收集) [转]CString,string,char*的综合比较 [转] C++ Windows字符和字符指针类型 [转]C++ int,char,string,CString类型转换(整理总结) C++字符串函数详解[转]
Smartphone2003中实现焦点在ListView控件与其它控件中切换
老羽 · 2009-06-06 · via 博客园 - 老羽

2009-06-06 17:35  老羽  阅读(301)  评论()    收藏  举报

在Smartphone2003中,如果界面中有ListView控件,则无法与其它控件切换了。如下图:

部件更新smartphone2003

在上图中,如果焦点切换到了ListView中后,就无法切换回TextBox等控件上了,非常不方便操作。

因此在这里,我扩展了ListView控件,参考代码如下:

public class ListViewEx : ListView
    {
        public ListViewEx()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 处理上下控件的焦点切换
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            int index = -1;
            bool up = false;
            bool next = false;

            if (this.Items.Count == 0)
            {
                up = true;
            }
            if (this.SelectedIndices.Count > 0 && this.SelectedIndices[0] == 0)
            {
                up = true;
            }
            if (this.SelectedIndices.Count > 0 && this.SelectedIndices[0] == this.Items.Count - 1)
            {
                next = true;
            }

            switch (e.KeyCode)
            {
                case Keys.Down:
                    if (next)
                    {
                        index = this.Parent.Controls.GetChildIndex(this);
                        do
                        {
                            if ((index + 1) == this.Parent.Controls.Count)
                                index = -1; //roll over
                            index++;
                        } while (!IsFocusable(this.Parent.Controls[index]));
                    }
                    break;

                case Keys.Up:
                    if (up)
                    {
                        index = this.Parent.Controls.GetChildIndex(this);
                        do
                        {
                            if (index == 0)
                                index = this.Parent.Controls.Count; //roll over
                            index--;
                        } while (!IsFocusable(this.Parent.Controls[index]));
                    }
                    break;
            }
            if (index > -1 && index < this.Parent.Controls.Count)
            {
                this.Parent.Controls[index].Focus();
                return;
            }
            base.OnKeyDown(e);
        }

        private bool IsFocusable(Control control)
        {
            if (control is Label)
                return false;
            else
                return true;
        }
    }