dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Importing a drag icon into a VB6 image object.

  1. #1
    Join Date
    Nov 2018
    Posts
    1

    Question 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?

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,318

    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.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Dec 2018
    Posts
    15

    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;
    }
    Last edited by 2kaud; January 8th, 2019 at 05:30 AM. Reason: Added code tags

  4. #4
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,973

    Re: Importing a drag icon into a VB6 image object.

    That code is C#, not VB6.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)