Results 1 to 8 of 8

Thread: How to insert a picture into a listbox , visual basic 6.0

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2018
    Posts
    17

    Question How to insert a picture into a listbox , visual basic 6.0

    I want to make a program like this 'see one of this two links'..https://ufile.io/y1qm9 or this https://ibb.co/jGobgm
    The program for children ,combines two numbers with a combined output show in the form of a number of apples.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to insert a picture into a listbox , visual basic 6.0

    Welcome to the forums

    Fairly difficult with VB's standard listbox. Suggestion: Use the ListView (Windows Common Controls in your toolbox). That control has a buddy control called an ImageList. You add needed images in the ImageList and the ListView control can add those images (as many entries/copies as needed).
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,389

    Re: How to insert a picture into a listbox , visual basic 6.0

    Quote Originally Posted by LaVolpe View Post
    Fairly difficult with VB's standard listbox.
    True, because you need a owner-drawn listbox. And with the intrinsic VB Listbox you can't change the style bits after window creation. So you need a windows hook to catch WM_CREATE.

    In my ListBoxW control (replacement control) is a convenient DrawMode property to enable owner drawing.

    Of course then you need to draw the focus rectangles, text and image yourself in WM_DRAWITEM. (Encapsulated in ListBoxW in an ItemDraw event)

    Or as LaVolpe suggested using the ListView.

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: How to insert a picture into a listbox , visual basic 6.0

    Hmm, since it seems to be only about:
    - rendering a few Images in a Stripe
    - only a few Rows
    - and apparently no Scrolling needed

    Why not implement this in your own (Project Private) simple UserControl, which represents such a Stripe.

    Multiple instances of that Stripe could then be defined on the Form in a Control-Array.

    Example-implementation of such an ucImgStripe-Usercontrol:
    Code:
    Option Explicit
    
    Private Img As StdPicture, i As Long
    
    Private Sub UserControl_Initialize()
      BackColor = vbWhite: AutoRedraw = True
      AsyncRead "https://upload.wikimedia.org/wikipedia/commons/thumb/0/07/Honeycrisp-Apple.jpg/120px-Honeycrisp-Apple.jpg", vbAsyncTypePicture
    End Sub
    Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
      If AsyncProp.BytesRead Then Set Img = AsyncProp.Value
    End Sub
    
    Public Sub SetImageCount(ImgCount)
      Cls
      For i = 0 To ImgCount - 1
        PaintPicture Img, ScaleHeight / 5 + i * ScaleHeight, 0, ScaleHeight, ScaleHeight
      Next
    End Sub
    Form-Test code (having the above Control on it as a Ctl-Array Stripe(0), Stripe(1) and Stripe(2):
    Code:
    Option Explicit
     
    Private Sub cmdRun_Click()
      Stripe(0).SetImageCount 2
      Stripe(1).SetImageCount 3
      Stripe(2).SetImageCount 5
    End Sub
    The above code-snippets will then produce this:


    HTH

    Olaf

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to insert a picture into a listbox , visual basic 6.0

    Are "stripes" even needed?

    I'm not sure how this program is meant to work, but here is a wild stab at it.

    Name:  sshot.png
Views: 1336
Size:  13.7 KB

    It just draws the apples on a PictureBox, using a different pattern for each sum of apples. The user picks two numbers that add up to the sum.
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: How to insert a picture into a listbox , visual basic 6.0

    Quote Originally Posted by dilettante View Post
    Are "stripes" even needed?
    Only slightly related to the topic at hand - but out of interest in bettering my english -
    how would a "native speaker" name such a kind of UserControl (which could act as
    an element in e.g. a scrollable DataRepeater)?

    A "row", or perhaps better - a "band", or ... ?

    Olaf

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to insert a picture into a listbox , visual basic 6.0

    I see no problem with your choice of word for such a UserControl.

    My use of quotation marks was merely to call out the word as a specific usage rather than as the general usage of the noun. Sort of somewhere between a regular noun and a proper noun. It could have been italicized or just used inline normally, but as I said I wanted to refer to your usage specifically.

    So stripe works fine. Even the more generic item works for an item contained within a multi-item control I suppose, but you have several stand-alone controls and not sub-controls above.

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: How to insert a picture into a listbox , visual basic 6.0

    Quote Originally Posted by dilettante View Post
    I see no problem with your choice of word for such a UserControl.
    My use of quotation marks was merely to call out the word as a specific usage...
    I understood it as such..
    Was asking only because I repeatedly stumble over exactly this kind of english-translation (consulting my translation-website),
    when I'm about to "name a thing, which assembles some other things inside, but in itself is part of something "scrollable" or "repeatable").

    Quote Originally Posted by dilettante View Post
    Even the more generic item works for an item contained within a multi-item control I suppose, ...
    Thanks, "item" indeed sounds a bit nicer I guess ...
    (better than e.g. "bar", which kind of suggests "non-repeatability").

    Yep, thinking about it - the term is indeed a bit more flexible (when attributed with a prefix) - and in usage in other programming-scenarios and -languages,
    where I found "rowItemTemplate" and "colItemTemplate" (made up out of "sub- HTML-defs" in those cases, but bound to a "repeating JSON-DataSource-enumeration").

    Olaf

Posting Permissions

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



Click Here to Expand Forum to Full Width