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

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - 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的字符串赋给它。