If you use Windows Vista or up, you have probably seen this kind of tooltip, with the coloured text and icon:
I've searched using various keywords e.g. Explorer, Aero, Windows, tooltips, and haven't come across any useful information on how to achieve this.
Preferably, I'd like the solution to be for WinForms. Has anyone had any luck?
This blog post on wyDay has the solution.
It links to a 3 part series called "Shell Style Drag and Drop in .NET":
The archive linked in part 3 is no longer available, but there appears to be copy of its contents here. Note that in order to compile, you may need to set the DragDropLib and WpfDragDropLib projects to allow unsafe code.
There's samples inside, but for convenience, here's an extract:
#region Drop target accepting FileDrop
private void textBox2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = e.AllowedEffect & DragDropEffects.Copy;
DropTargetHelper.DragEnter(textBox2, e.Data, new Point(e.X, e.Y), e.Effect, "Copy to %1", "Here");
}
else
{
e.Effect = DragDropEffects.None;
DropTargetHelper.DragEnter(textBox2, e.Data, new Point(e.X, e.Y), e.Effect);
}
}
private void textBox2_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = e.AllowedEffect & DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
DropTargetHelper.DragOver(new Point(e.X, e.Y), e.Effect);
}
private void textBox2_DragLeave(object sender, EventArgs e)
{
DropTargetHelper.DragLeave(textBox2);
}
private void textBox2_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = e.AllowedEffect & DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
if (e.Effect == DragDropEffects.Copy)
AcceptFileDrop(textBox2, e.Data);
}
#endregion // Drop target accepting FileDrop
From my experimentation it seems that I can just write e.Effect = DragDropEffects.Copy;
instead of e.Effect = e.AllowedEffect & DragDropEffects.Copy;
; though I currently don't understand what the &
is there for, so someone might be able to help me with that. As well as that, it seems that the text drop type won't show the description tooltip.
Otherwise, I'm definitely very happy with this.
Hope this helps anyone with this issue as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With