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

推荐订阅源

G
Google Developers Blog
Cisco Talos Blog
Cisco Talos Blog
Y
Y Combinator Blog
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
J
Java Code Geeks
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 聂微东
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Privacy & Cybersecurity Law Blog
L
LangChain Blog
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
F
Full Disclosure
S
Schneier on Security
T
Tenable Blog
量子位
NISL@THU
NISL@THU
Latest news
Latest news
V
Visual Studio Blog
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
博客园_首页
K
Kaspersky official blog
L
Lohrmann on Cybersecurity
美团技术团队
P
Proofpoint News Feed
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
S
Securelist
The Register - Security
The Register - Security
G
GRAHAM CLULEY
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta
C
Cisco Blogs

博客园 - BearOcean

LOG.ZS.0001.基于Freetype的游戏字体渲染优化思路 const 和指针 C++ 下啥时候用struct, 啥时候用class C++ 和 Java 中的变参 解决站点关键数据,状态数据,无须持久化数据的一些思路 BS程序代码与安全与基本攻击/防御模式 Struts 实现的I18N Ant 阅读笔记 进度,效率,与个人事务管理 Personal Task 1.0 MySql与Java的时间类型 数据挖掘概述 解决Thread 的关闭问题和参数传递时想到的办法. Command 模式 内网聊天工具FreeChat 2.0 FreeChat 2.0 ...大改 模型和架构 局域网聊天工具FreeChat 1.0 开发日志 内网聊天工具FreeChat Beta 为Socket写的附加方法 .Net 事件
.Net标准控件与自定义控件(2) ToolTipButton
BearOcean · 2006-04-27 · via 博客园 - BearOcean

继昨天的NoCopyTextBox(http://bearocean.cnblogs.com/archive/2006/04/26/385413.html
以后,客户又提出了新的要求:

            客户需要一套机票定位系统,用一个小方框来代表一个机位,点击以后弹出对话框,将由系统的操作人员填写预定信息。
            所以我们考虑用Button来实现这个功能。
            
            但是客户有一个附加要求,就是当鼠标移动到机位的方框上是,尽管不点击也能够显示定位信息:           
            但是具我所知默认的Button并没有这个功能。(如果有就白忙了)
            所以要自己做一个新的Button控件。

            最好是这样,MyButton myButton =new Button();
                                      myButton.Title ="This is a test";

            这样就能自动的显示Title的内容。
            之所以把这个属性取名为Title是因为这个跟Html的Title如此相象。

            其后想到了.Net 提供的ToolTip
            于是利用这个控件,做了一个ToolTipButton.
            原代码如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;


namespace Uestc_15_UI
{
    
/// <summary>
    
/// HelperButton 的摘要说明。
    
/// </summary>

    public class HelpTipButton :System.Windows.Forms.Button
    
{
        
private System.Windows.Forms.ToolTip HelpTip;
        
private System.ComponentModel.IContainer components;

        
public delegate void OnTitleChanged();
        
public event OnTitleChanged TitleChaneged;

        
private string strTitle ="";
        
public string Title
        
{
            
get
            
{
                
return this.strTitle;
            }

            
set
            
{
                
this.strTitle =value;
                
if(this.TitleChaneged !=null)
                
{
                    
this.TitleChaneged();
                }

            }

        }

    
        
public HelpTipButton()
        
{
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
            this.components = new System.ComponentModel.Container();
            
this.HelpTip = new System.Windows.Forms.ToolTip(this.components);
            
this.TitleChaneged +=new OnTitleChanged(HelpTipButton_TitleChaneged);
        }


        
private void InitializeComponent()
        
{
            
// 
            
// HelpTipButton
            
// 

        }


        
private void HelpTipButton_TitleChaneged()
        
{
            
if(this.strTitle !="")
            
{
                
this.HelpTip.SetToolTip(this,this.strTitle);
            }

        }

    }

}

其实实现很简单,只是继承自Button,然后添加了一个私有成员ToolTip,和一个属性string Title
并定义一个事件去检测Title.一旦Title变化,就重新利用HelpTip.SetToolTip(this,this.strTitle)将字符串信息
设置到ToolTip上。
同时SetToopTip将ToolTip与Button绑定。

最后,只要重新作一个Surface就差不多了。
其实真正的实现可能还要复杂一点,如果要实现上述定机位功能,最好把string Title换成一个实际的类。
初始化ToolTipButton时是将一个ClientInfo实例附给他。而不是将一串名为Title的字符串赋给它。