Importing a drag icon into a VB6 image object.
I am running VB6 on Windows XP. I have made 16x16 and 32x32 bitmap icons in Paint in Windows 7 and Windows XP, but none of them will work as drag icons in VB6. I have saved these files as 256 Color bitmap files, 24-bit bitmap files and 16 Color bitmap files (all with "ico" extensions when saving them), but none work. These files work as desktop icons, but I get the message "Invalid property value" when I try to import them as drag icons. How can I make an icon that can be used as a drag icon in VB6?
Re: Importing a drag icon into a VB6 image object.
.ico files are not bitmaps simply changing the extension of a .bmp to .ico does not do anything for you. You need to use a software that can save actual icon files either as .ico or .dll Been a while since I used XP but I do not think there was any native software included with XP that could do this. I had a 3rd party icon creator tool that I used for this under XP.
Re: Importing a drag icon into a VB6 image object.
You may try this code:
Code:
private void OnDragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
Debug.WriteLine("OnDragEnter");
string filename;
validData=GetFilename(out filename, e);
protected bool GetFilename(out string filename, DragEventArgs e)
{
bool ret=false;
filename=String.Empty;
if ( (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
{
Array data=((IDataObject)e.Data).GetData("FileName") as Array;
if (data != null)
{
if ( (data.Length ==1) && (data.GetValue(0) is String) )
{
filename=((string[])data)[0];
string ext=Path.GetExtension(filename).ToLower();
if ( (ext==".jpg") || (ext==".png") || (ext==".bmp") )
{
ret=true;
}
}
}
}
return ret;
}
private void OnDragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
Debug.WriteLine("OnDragEnter");
string filename;
validData=GetFilename(out filename, e);
if (validData)
{
if (lastFilename != filename)
{
thumbnail.Image=null;
thumbnail.Visible=false;
lastFilename=filename;
getImageThread=new Thread(new ThreadStart(LoadImage));
getImageThread.Start();
}
else
{
thumbnail.Visible=true;
}
e.Effect=DragDropEffects.Copy;
}
else
{
e.Effect=DragDropEffects.None;
}
}
public delegate void AssignImageDlgt();
protected void LoadImage()
{
nextImage=new Bitmap(lastFilename);
this.Invoke(new AssignImageDlgt(AssignImage));
}
protected void AssignImage()
{
thumbnail.Width=100;
// 100 iWidth
// ---- = ------
// tHeight iHeight
thumbnail.Height=nextImage.Height * 100 / nextImage.Width;
SetThumbnailLocation(this.PointToClient(new Point(lastX, lastY)));
thumbnail.Image=nextImage;
}
Re: Importing a drag icon into a VB6 image object.
That code is C#, not VB6.