C#中datagridview使用tooltip控件显示单元格内容与datagridview自带的tooltip显示单元格内容的方法
2016-11-05 02:25
916 查看
1、datagridview自带的tooltip显示单元格内容的方法
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.dataGridView1.ShowCellToolTips = true; this.toolTip1.AutomaticDelay = 0;//提示延迟 this.toolTip1.ShowAlways = true;//是否显示文本 this.toolTip1.ToolTipTitle = "";//窗口标题 this.toolTip1.UseAnimation = true;//动画效果 this.toolTip1.UseFading = true;//淡入淡出效果 } private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); SqlConnection con = new SqlConnection("server = XQ-20160210KQLE\\SA;uid = sa;pwd = 123456;database = JYXinXi"); try { con.Open(); string strselect = "select 仓库名称,负责人,联系电话,仓库地址,备注 from CanKuBiao"; SqlDataAdapter da = new SqlDataAdapter(strselect, con); da.Fill(dt); } catch (Exception ee) { MessageBox.Show(ee.Message.ToString()); } finally { con.Close(); this.dataGridView1.DataSource = dt; } } private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } else { this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = "qqq"; } } private void toolTip1_Draw(object sender, DrawToolTipEventArgs e) {//绘制提示文本 e.Graphics.FillRectangle(Brushes.AliceBlue, e.Bounds); e.Graphics.DrawRectangle(Pens.Chocolate, new Rectangle(0, 0, e.Bounds.Width - 1, e.Bounds.Height - 1)); e.Graphics.DrawString(this.toolTip1.ToolTipTitle + e.ToolTipText, e.Font, Brushes.Red, e.Bounds); } private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) {////鼠标移出单元格后隐藏提示工具 this.toolTip1.Hide(this.dataGridView1); } } }
2、datagridview使用tooltip控件显示单元格内容
public partial class Form1 : Form { public Form1() { InitializeComponent(); this.dataGridView1.ShowCellToolTips = false; this.toolTip1.AutomaticDelay = 0;//提示延迟 this.toolTip1.OwnerDraw = true;//自己绘制或者系统绘制 this.toolTip1.ShowAlways = true;//是否显示文本 this.toolTip1.ToolTipTitle = "";//窗口标题 this.toolTip1.UseAnimation = true;//动画效果 this.toolTip1.UseFading = true;//淡入淡出效果 } private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); SqlConnection con = new SqlConnection("server = XQ-20160210KQLE\\SA;uid = sa;pwd = 123456;database = JYXinXi"); try { con.Open(); string strselect = "select 仓库名称,负责人,联系电话,仓库地址,备注 from CanKuBiao"; SqlDataAdapter da = new SqlDataAdapter(strselect, con); da.Fill(dt); } catch (Exception ee) { MessageBox.Show(ee.Message.ToString()); } finally { con.Close(); this.dataGridView1.DataSource = dt; } } private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } else { this.toolTip1.Hide(this.dataGridView1); this.toolTip1.Show("qqqq", this.dataGridView1, Cursor.Position); } } private void toolTip1_Draw(object sender, DrawToolTipEventArgs e) {//绘制提示文本 e.Graphics.FillRectangle(Brushes.AliceBlue, e.Bounds); e.Graphics.DrawRectangle(Pens.Chocolate, new Rectangle(0, 0, e.Bounds.Width - 1, e.Bounds.Height - 1)); e.Graphics.DrawString(this.toolTip1.ToolTipTitle + e.ToolTipText, e.Font, Brushes.Red, e.Bounds); } private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) {////鼠标移出单元格后隐藏提示工具 this.toolTip1.Hide(this.dataGridView1); } }
问题1:
b882
使用tooltip控件显示程序中提示文本显示的位置不在datagridview表中。
提示文本自定义绘制可显示,只是显示的位置不在表中。
相关文章推荐
- C#中datagridview使用tooltip控件显示单元格内容的方法
- datagridview使用tooltip控件显示单元格内容
- datagridview使用tooltip控件显示单元格内容
- C#中使用DataGridView控件显示数组中的内容
- C#Winform基础 显示选中行的第一列单元格的内容,datagridview控件
- C#Winform基础 显示选中行的第一列单元格的内容,datagridview控件
- 【MARK】C# DataGridView控件单元格 未提交 内容改变事件
- C#中,当鼠标移动到控件上,动态显示提示内容 ToolTip
- C#中使用DataGridView显示二维数组中的内容
- C#中使用DataGridView控件显示DataTable中的数据
- C#读取Excel表格中内容并显示在DataGridView控件中
- C#中,当鼠标移动到控件上,动态显示提示内容 -> 用代码操作ToolTip
- C#中,当鼠标移动到控件上,动态显示提示内容 ToolTip
- C# datagridview toolTip悬浮框显示详细内容
- C#设置DataGridView某一具体单元格的内容居中显示
- C#如何使用dataGridView控件显示类对象数据
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- C#中使用DataGridView显示二维数组中的内容
- 在VS2008中使用C#代码打印 RichTextBox 控件的内容[方法采自微软支持][Part 1]
- 在VS2008中使用C#代码打印 RichTextBox 控件的内容[方法采自微软支持][Part 2]