首页 技术 正文
技术 2022年11月8日
0 收藏 351 点赞 1,112 浏览 2397 个字
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace DemoTolltip
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private ToolTip lvTp = new ToolTip();
private ListViewItem currentItem = new ListViewItem();
private void Form2_Load(object sender, EventArgs e)
{
listView1.View = View.LargeIcon;
listView1.FullRowSelect = true;
// listView1.GridLines = true;
listView1.Columns.Add("Column1");
listView1.Columns.Add("Column2");
for (int i = 0; i < 10; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.SubItems[0].Text = i.ToString();
lvi.ImageIndex = i;
lvi.SubItems.Add("Item" + i.ToString());
lvi.ToolTipText = "Item" + i.ToString() +"\r\n" +strShowIms; listView1.Items.Add(lvi);
}
// listView1.ShowItemToolTips = true;
listView1.MouseMove += new MouseEventHandler(listView1_MouseMove);
lvTp.OwnerDraw = true;
lvTp.Draw += new DrawToolTipEventHandler(lvTp_Draw);
lvTp.Popup += new PopupEventHandler(lvTp_Popup);
}
string strShowIms = @"sssAAAAAAA
1 AAAAAAAAAAAAAAAAAAAAA
2 AAAAAAA
2 AAAAAAA
3 AAAAAAA
4 AAAAAAA
5 AAAAAAA
6 AAAAAAA
7 AAAAAAA
8 AAAAAAA
9 AAAAAAA
";
string strText = "";
public void lvTp_Popup(object sender, PopupEventArgs e)
{
Size s = TextRenderer.MeasureText(strText, f);
e.ToolTipSize = new Size(s.Width, s.Height + 40);
}
Font f = new Font("宋体", 10.0f);
Font fTitle = new Font("宋体", 12.0f);
void lvTp_Draw(object sender, DrawToolTipEventArgs e)
{
using (e.Graphics)
{
int x = e.Bounds.Width;
int y = e.Bounds.Height;
e.DrawBackground(); SolidBrush b = new SolidBrush(Color.FromArgb(233, 240, 245));//矩形背景色
SolidBrush border = new SolidBrush(Color.FromArgb(190, 219, 249));//边框颜色
Rectangle recg = new Rectangle(0, 0, x, 30); e.Graphics.FillRectangle(b, recg);
e.Graphics.DrawRectangle(new Pen(border), recg);
e.Graphics.DrawRectangle(new Pen(border), 0, 0, x - 1, y - 1);
int tempx = x / 4;
if (x < 180 && x > 100)
{
tempx = 10;
}
else if (x <= 100)
{
tempx = 5;
}
e.Graphics.DrawImage(global::DemoTolltip.Properties.Resources.当前床位信息, new PointF(tempx, 5));
e.Graphics.DrawString("当前信息", fTitle, Brushes.Black, new PointF(tempx + 40, 7));
// e.Graphics.DrawLine(new Pen(Brushes.Blue),new Point(1,30),new Point(400,30));
e.Graphics.DrawString(e.ToolTipText, f, Brushes.Black, new PointF(4, 40));
}
} void listView1_MouseMove(object sender, MouseEventArgs e)
{
ListViewItem lvi = listView1.GetItemAt(e.X, e.Y);
if (lvi != null && lvi != currentItem)
{
strText = lvi.ToolTipText;
currentItem = lvi;
lvTp.Show(lvi.ToolTipText, listView1, e.Location);
}
else if (lvi == null)
{
strText="";
lvTp.Hide(listView1);
}
currentItem = lvi;
} }
}

  

上一篇: C#队列
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,411
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,184
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,904