【发布时间】:2018-01-22 23:30:59
【问题描述】:
背景:我正在使用 c# 中的 winforms。我不希望图像显示在 datagridview 单元格中,我只在数据库中存储了路径,并在数据库中的 datagridview 中显示它们。
问题:当用户输入一个单元格时,会弹出一个工具提示。我需要的是,当当前单元格的列索引为 2 时,工具提示应显示当前单元格中给定路径的图像。
我发现This Article 非常好。但无法获得成功。我有以下代码
void CustomizedToolTip_Popup(object sender, PopupEventArgs e)
{
DataGridView parent = e.AssociatedControl as DataGridView;
if (parent.CurrentCell != null)
{
if (parent.CurrentCell.ColumnIndex == 2)
{
Bitmap bmpIn = new Bitmap(parent.CurrentCell.Value + "");
using (Graphics g = Graphics.FromImage(bmpIn))
{
Rectangle mr = new Rectangle(5, 5, 50, 50);
mr.Location = new Point(5, 5);
g.PageUnit = GraphicsUnit.Pixel;
g.DrawImage(bmpIn, mr);
}
}
}
}
我以为这段代码应该画图,但不是画图,而且画的多我不确定位置,即使我可以画,如何在tootip中定位。我无法从我提到的文章中理解它。下面是我的datagridview的图像。
【问题讨论】:
标签: c# winforms datagridview tooltip