Multiple pictures in controls

Post your Gambas programming questions here.
Post Reply
User avatar
thatbruce
Regular
Posts: 293
Joined: Sat Sep 04, 2021 11:29 pm

Multiple pictures in controls

Post by thatbruce »

Some time ago BruceS (IIRC) showed me how to combine several pictures into one,so I could use them as the, for example TabPanel1[X].Picture
Damned if I can find it and the Search doesn't help (just keeps saying "too many common terms")

Would appreciate a reminder.
tia
b
BruceSteers
Legend
Posts: 2093
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: Multiple pictures in controls

Post by BruceSteers »

So make a new Picture using New(W, H, True) ' give width/height and make transparent

Then paint both pictures to it.


Dim hPic As Picture = New Picture(64, 32, True)

Dim hLeftPic As Picture = Picture["icon:/32/gambas"]
Dim hRightPic As Picture = Picture["icon:/32/linux"]

Paint.Begin(hPic)
Paint.DrawPicture(hLeftPic, 0, 0, 32, 32)
Paint.DrawPicture(hRightPic, 32, 0, 32, 32)
Paint.End

TabPanel1[X].Picture = hPic

User avatar
thatbruce
Regular
Posts: 293
Joined: Sat Sep 04, 2021 11:29 pm

Re: Multiple pictures in controls

Post by thatbruce »

Thanks matey!

This time I want to make it 3 or 4 or 200,000,000 pics wide. :ugeek:
Will return if I can't get it going.

b
BruceSteers
Legend
Posts: 2093
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: Multiple pictures in controls

Post by BruceSteers »

No worries :)

Here's my function from my VBoxMounter program that does it dynamically adding an svg logo icon and maybe a couple of other icons if required.
The picture is then used in a the GridView


Public Sub GetImage(VM As VBoxUnit) As Picture

  Dim sFind As String = vm.Name &/ vm.Path
  Dim sp As SvgImage
  Dim p, pRet As Picture

  Select sFind
    Case Like "*deb*"
      sp = SvgImage.Load("./icons/debian.svg")
    Case Like "*mint*"
      sp = SvgImage.Load("./icons/linuxmint.svg")
    Case Like "*ubuntu*"
      sp = SvgImage.Load("./icons/ubuntu.svg")
    Case Like "*suse*"
      sp = SvgImage.Load("./icons/suse.svg")
    Case Like "*manjaro*"
      sp = SvgImage.Load("./icons/manjaro.svg")
    Case Like "*fedora*"
      p = Picture.Load("./icons/fedora.png").Stretch(16, 16)
    Case Else
      sp = SvgImage.Load("./icons/linux-tux.svg")
  End Select

  If sp Then ' convert svg to picture
    sp.Resize(16, 16)
    p = New Picture(16, 16, True)
    Paint.Begin(p)
    sp.Paint(0, 0, 16, 16)
    Paint.End
  Endif

' dynamically assign width
  Dim W As Integer = 16, X As Integer
  If vm.HasSnapshot Then w += 16 + Desktop.Scale
  If vm.StoredData.Count Then w += 16 + Desktop.Scale

  pRet = New Picture(W, 16, True)
  Paint.Begin(pRet)

  Paint.DrawPicture(p, 0, 0, 16, 16) ' add logo

  If vm.HasSnapshot Then ' add snapshot icon if exists
    X += 16 + Desktop.Scale
    Paint.DrawPicture(Picture["icon:/16/camera"], X, 0, 16, 16)
  Endif

  If vm.StoredData.Count Then ' add info icon if info exists
    X += 16 + Desktop.Scale
    Paint.DrawPicture(Picture["icon:/16/info"], X, 0, 16, 16)
  Endif
  Paint.End

  Return pRet

End


You do not have the required permissions to view the files attached to this post.
Post Reply