C# ListView 自定义ToolTip 显示
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# ListView 自定义ToolTip 显示的更多相关文章
- echarts自定义tooltip显示
使用echarts展示图形的时候,鼠标滑倒图像上,想展示除了系列名,数据名,数据值以外的数据,这时需要使用tooltip的fommater方式进行配置,另外对数据格式也有一定的要求. 如图所示:如果想 ...
- Echarts 的悬浮框tooltip显示自定义格式化
最近做的项目用到echarts雷达图,但是由于地市过多,遇到悬浮框显示问题被遮住 如图: 可以看到上面从兴安开始数据就被遮住了 为了解决这个被遮住的悬浮框,达到tooltip自定义格式 完成后的效果如 ...
- 用WPF实现在ListView中的鼠标悬停Tooltip显示
原文:用WPF实现在ListView中的鼠标悬停Tooltip显示 一.具体需求描述 在WPF下实现,当鼠标悬停在ListView中的某一元素的时候能弹出一个ToolTip以显示需要的信息. 二.代码 ...
- DevExpress.XtraGrid.GridControl 实现自定义tooltip
DevExpress.XtraGrid.GridControl 控件默认的tooltip显示的每一个单元格的文本值,但是实际工作中会出现各种需求.我这里就有一个列是折扣率显示的值是0-1之间的两位小数 ...
- WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Dat ...
- Swing图层的应用——实现tooltip显示
没有错是世纪前的swing. 在使用Swing的时候有个问题一直没有解决,就是Swing自带的tooltip不会跟随鼠标进行移动,而且移动到边界就会遮挡的问题.JCompoent有个createToo ...
- 【转】WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要内容: DataGrid自定义样式: ListView自定义样式: 二.Dat ...
- C# 解决ListView控件显示数据出现闪屏的问题
一.发现问题 如果发送数据过快的情况下,ListVies滚屏显示数据时会显示闪屏,如下所示现象: 二.解决问题 根据出现闪屏的情况,在网上查了资料要使用双缓存的办法来处理.其原理是数据在缓存区中进行处 ...
- 《连载 | 物联网框架ServerSuperIO教程》- 13.自定义视图显示接口开发,满足不同的显示需求
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
随机推荐
- js多行省略
$(function (){ // var $introduce = $(".c-introduce").html(); // $new_introduce = $introduc ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array
传送门 分析:其实没什么好分析的.统计一下负数个数.如果负数个数是偶数的话,就要尽量增加负数或者减少负数.是奇数的话就努力增大每个数的绝对值.用一个优先队列搞一下就行了. 我感觉这道题的细节极为多,非 ...
- iOS---自动布局
自动布局的发展 1.frame:通过代码计算 frame iPhone3GS \ iPhone4 \ iPhone4S 屏幕的物理尺寸是一样的(无需屏幕适配), 而且一个当时的应用要么是横屏要么是竖屏 ...
- Android获取屏幕实际高度跟显示高度,判断Android设备是否拥有虚拟功能键
//获取屏幕尺寸,不包括虚拟功能高度 getWindowManager().getDefaultDisplay().getHeight(); 获取屏幕原始尺寸高度,包括虚拟功能键高度, private ...
- json序列化时datetime的处理方法
.net自带的json序列化器,JavaScriptSerializer和DataContractJsonSerializer,都是序列化成微软的datetime json格式,e.g. " ...
- JAVA数据转换常用方法
时间格式化与运算 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar=sdf. ...
- Rhel6-csync配置文档
系统环境: rhel6 x86_64 iptables and selinux disabled 主机:192.168.122.160 server60.example.com 192.168.122 ...
- codeforces problem 140E New Year Garland
排列组合题 题意 用m种颜色的彩球装点n层的圣诞树.圣诞树的第i层恰由l[i]个彩球串成一行,且同一层内的相邻彩球颜色不同,同时相邻两层所使用彩球的颜色集合不同.求有多少种装点方案,答案对p取模. 只 ...
- linux下错误的捕获:errno和strerror的使用
经常在调用linux 系统api 的时候会出现一些错误,比方说使用open() write() creat()之类的函数有些时候会返回-1,也就是调用失败,这个时候往往需要知道失败的原因.这个时候使用 ...
- Titanium studio安装
在Win7 Titanium Studio的安装过程. 1.准备工作 Titanium存储空间的要求,Titanium Studio 需要1 GB.Android SDK需要1.5 GB.Blackb ...