110,534
社区成员
发帖
与我相关
我的任务
分享
[ProvideProperty("HelpTip", typeof(Control))]
public partial class HelpTip : Component, IExtenderProvider
{
private Hashtable hstData = new Hashtable(); //存放各控件的提示值字符
public HelpTip()
{
InitializeComponent();
}
public HelpTip(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public bool CanExtend(object o)
{
return o is TextBox; //只有这里返回为真时才会被扩展
}
public void SetHelpTip(Control c, string sValue)
{
int hash = c.GetHashCode();
if (!hstData.Contains(hash))
{
hstData.Add(hash, sValue);
// Means here should handle mouse hover event.
c.MouseHover += new EventHandler(c_MouseHover);
c.Disposed += new EventHandler(c_Disposed);
}
else
hstData[hash] = sValue;
}
void c_Disposed(object sender, EventArgs e)
{
Control c = sender as Control;
if (c != null)
{
c.MouseHover -= new EventHandler(c_MouseHover);
c.Disposed -= new EventHandler(c_Disposed);
}
}
void c_MouseHover(object sender, EventArgs e)
{
TextBox c = sender as TextBox;
if (c != null)
{
Form f = c.FindForm();
if (f != null)
showTip(c, f);
}
}
[DefaultValue("")]
[Description("件鼠标悬停时控件的提示")]
public string GetHelpTip(Control c)
{
int hash = c.GetHashCode();
if (hstData.Contains(hash))
return hstData[hash].ToString();
else
return "";
}
//前景色
private Color fc = Color.Black;
public Color foreColor
{
get { return fc; }
set { fc = value; }
}
//窗体背景色
private Color bbc = Color.White;
public Color baseBackColor
{
get { return bbc; }
set { bbc = value; }
}
//label背景色
private Color lblBc = Color.Yellow;
public Color lblBackColor
{
get { return lblBc; }
set { lblBc = value; }
}
//窗体背景图
private Image BackImageT = null;
public Image BackImage
{
get { return BackImageT; }
set { BackImageT = value; }
}
//窗体透明度
private byte op = 100;
public byte Opatity
{
get { return op; }
set
{
byte oT = op;
try
{
op = byte.Parse(value.ToString());
}
catch
{
MessageBox.Show("无效的值!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
op = oT;
}
}
}
//lable显示的字体
private Font ft = new Font("宋体", 9);
public Font sFont
{
get { return ft; }
set { ft = value; }
}
//多长时间没有动静时显示
private int delay = 500;
public int AutoMaticDelay
{
get { return delay; }
set { delay = value; }
}
//每次自动显示多长时间(有键盘及鼠标操作时会停止显示)
private int popdelay = 3000;
public int AutoPopDelay
{
get { return popdelay; }
set { popdelay = value; }
}
//主要显示用的窗体
private class TipForm : System.Windows.Forms.Form
{
public TipForm(Color bckColor, Color lblBckColor)
{
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = bckColor;
this.TopMost = true;
this.MinimumSize = new Size(1, 1);
this.ShowInTaskbar = false;
this.BackColor = bckColor;
}
}
public void showTip(TextBox c, Form f)
{
showTip(c.Location, f.Location, f.Size, c);
}
public void showTip(Point ControlLocation, Point FormLocation, Size FormSize, Control c)
{
TipForm tf = new TipForm(baseBackColor, lblBackColor);
tf.Location = new Point(10, 10);
tf.Width = 200;
tf.Height = 200;
tf.Show();
//获得大小
//添加提示内容(一图片及label)
Label lb = new Label();
if (hstData.Contains(c.Name)) //这里获得不到值
{
lb.ForeColor = foreColor;
lb.BackColor = lblBackColor;
lb.Font = sFont;
lb.AutoSize = true;
lb.Text = hstData[c.Name].ToString();
tf.Controls.Add(lb);
}
}
}
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace help
{
[ProvideProperty("HelpTip", typeof(Control))]
public partial class helptip : Component, IExtenderProvider
{
private Hashtable hstData = new Hashtable(); //存放各控件的提示值字符
public helptip()
{
InitializeComponent();
}
public helptip(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public bool CanExtend(object o)
{
return o is TextBox; //只有这里返回为真时才会被扩展
}
public void SetHelpTip(Control c, string sValue)
{
if (!hstData.Contains(c.Name))
hstData.Add(c.Name, sValue); //这里的c.name永远是空字符串""
else
hstData[c.Name] = sValue;
}
[DefaultValue("")]
[Description("件鼠标悬停时控件的提示")]
public string GetHelpTip(Control c)
{
if (hstData.Contains(c.Name ))
return hstData[c.Name].ToString();
else
return "";
}
//前景色
private Color fc = Color.Black;
public Color foreColor
{
get { return fc; }
set { fc = value; }
}
//窗体背景色
private Color bbc = Color.White;
public Color baseBackColor
{
get { return bbc;}
set { bbc = value; }
}
//label背景色
private Color lblBc = Color.Yellow;
public Color lblBackColor
{
get { return lblBc; }
set { lblBc = value; }
}
//窗体背景图
private Image BackImageT = null;
public Image BackImage
{
get { return BackImageT; }
set { BackImageT = value; }
}
//窗体透明度
private byte op = 100;
public byte Opatity
{
get { return op; }
set
{
byte oT = op;
try
{
op = byte.Parse(value.ToString());
}
catch
{
MessageBox.Show("无效的值!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
op = oT;
}
}
}
//lable显示的字体
private Font ft=new Font("宋体",9);
public Font sFont
{
get { return ft; }
set { ft = value; }
}
//多长时间没有动静时显示
private int delay = 500;
public int AutoMaticDelay
{
get { return delay; }
set { delay = value; }
}
//每次自动显示多长时间(有键盘及鼠标操作时会停止显示)
private int popdelay = 3000;
public int AutoPopDelay
{
get { return popdelay; }
set { popdelay = value; }
}
//主要显示用的窗体
private class TipForm : System.Windows.Forms.Form
{
public TipForm(Color bckColor,Color lblBckColor)
{
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = bckColor;
this.TopMost = true;
this.MinimumSize = new Size(1, 1);
this.ShowInTaskbar = false;
this.BackColor = bckColor;
}
}
public void showTip(TextBox c, Form f)
{
showTip(c.Location, f.Location, f.Size,c);
}
public void showTip(Point ControlLocation, Point FormLocation, Size FormSize,Control c)
{
TipForm tf = new TipForm(baseBackColor, lblBackColor);
tf.Location = new Point(10, 10);
tf.Width = 200;
tf.Height = 200;
tf.Show();
//获得大小
//添加提示内容(一图片及label)
Label lb = new Label();
if (hstData.Contains(c.Name)) //这里获得不到值
{
lb.ForeColor = foreColor;
lb.BackColor = lblBackColor;
lb.Font = sFont;
lb.AutoSize = true;
lb.Text = hstData[c.Name].ToString();
tf.Controls.Add(lb);
}
}
}
}