Page 1 of 1

PNG as button image

Posted: 02 Oct 2014, 08:37
by Mex
Hi Timo!

Is there a way to use PNG files as button images? GDI+?


Regards
Meelis

Re: PNG as button image

Posted: 03 Oct 2014, 08:27
by TiKu
Hi,

Yes, this can be done, if you find a way to load the PNG into an image list. Loading a PNG into an image list should be possible. I'll try to create a sample project.

Regards
TiKu

Re: PNG as button image

Posted: 04 Oct 2014, 17:18
by TiKu
See the attached file. The sample uses GDI+ to load a PNG file into an image list and use the icons for the tool bar buttons.

Regards
TiKu

Re: PNG as button image

Posted: 06 Oct 2014, 09:00
by Mex
Hi

Thank you, PNG-s are working fine now.

Question about aligning ReBar. When I set ReBar's alignment to left/right, then no buttons are visible.
What is causing this?


Regards
Meelis

Re: PNG as button image

Posted: 06 Oct 2014, 09:33
by Mex
Mex wrote:Hi

Thank you, PNG-s are working fine now.

Question about aligning ReBar. When I set ReBar's alignment to left/right, then no buttons are visible.
What is causing this?


Regards
Meelis
OK this was the "Orientation" problem...
But how to change rebar/toolbar alignment at runtime? Setting Align at runtime is not working as expected. Align is only working when I use toolbar without rebar.

And couple "bugs" or something.. :D
1) When I set ButtonStyle to flat and toolbar is aligned Top, everything looks ok. Now when I set align to Right, button visual look is changed to 3D, but property is still "flat".
2) Change rebar align to top at design time and try to change "Apperance". ReBar starts to flicker and VB6 IDE hangs.

Re: PNG as button image

Posted: 06 Oct 2014, 23:23
by TiKu
Hi,

Changing the rebar's orientation at runtime will recreate the control window. Recreation includes destroying the window. Destroying a window also destroys its child windows - the tool bar.
So it might work to detach the tool bar from the rebar while changing the rebar's orientation. This can be done by setting the band's hContainedWindow property to 0 (and afterwards to the tool bar's window handle to re-attach).

Regarding the 2 bugs: I've fixed no. 2. No. 1 seems to be caused by the internal behavior of the native tool bar control and I have not yet found a work-around.

Regards
TiKu

Re: PNG as button image

Posted: 07 Oct 2014, 06:33
by Mex
OK, got it working now.
I found, that correct order is very important, how to change alignment. For example, if you change ReBar's properties first and then ToolBar properties, Buttons.Add method will fail.
And if you change ReBar's "Orientation" first and then "Align", ReBar starts flicker and applications hangs.

Method that's working now as excpected.

Code: Select all

Private Sub CreateToolbar(Optional ByVal Alignment As Integer = vbAlignTop)
Dim il As Long, dom As New DOMDocument

If MyGDIHelper Is Nothing Then
   Set MyGDIHelper = New clsGDIHelper
End If

theToolBar.Buttons.RemoveAll
theRebar.Bands.RemoveAll

Select Case Alignment
   Case vbAlignTop
   With theToolBar
      .Orientation = oHorizontal
   End With
   With theRebar
      .Align = Alignment
      .Orientation = oHorizontal
   End With
   Case vbAlignRight
   With theToolBar
      .Orientation = oVertical
   End With
   With theRebar
      .Align = Alignment
      .Orientation = oVertical
   End With
End Select

theRebar.Bands.Add(, theToolBar.hwnd, , SizingGripVisibility:=sgvAlways, MinimumWidth:=38, MinimumHeight:=38).UseChevron = True

Dim node As IXMLDOMNode, n As Integer
dom.Load app.path & "\Templates\toolbars.xml"
If MyGDIHelper.CreateImageListForToolbar("mainmdi") Then
   theToolBar.hImageList(ilNormalButtons) = MyGDIHelper.ImageList
   For Each node In dom.selectSingleNode("//toolbar[@id='mainmdi']").childNodes
      With theToolBar
         .Buttons.Add n + 1, , n
      End With
      n = n + 1
   Next
End If

End Sub