Custom Component problem

Ask about the individual Gambas components here.
Post Reply
Posts: 130
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Custom Component problem

Post by bill-lancaster » Wednesday 13th March 2019 2:04pm

This is my first attempt at a custom component.
The idea is to have a single component to step though an index of items, e.g. a collection of photos.
So far the project works but I'd like to fix the overall dimensions of the component, at the moment, when selected from the 'Form' controls the control is completely the wrong shape.
' Gambas class file


Inherits UserControl

Public Const _DefaultEvent As String = "Click"

Property ItemCount As Integer

Event Click

Private sPicture As String[] = ["icon:/22/start", "icon:/22/right", "icon:/22/left", "icon:/22/end"]
Private hBox As DrawingArea
Private hBtn[4] As Button
Private hLabel As Label
Private iBtnLeft As Integer[] = [5, 35, 145, 180]
Public iIndex As Integer
Private iItemCount As Integer

Public Sub _new()
Dim i, iBtnSize As Integer
   iBtnSize = 30
   hBox = New DrawingArea(Me)
   hBox.Border = Border.Plain
   With hLabel = New Label(HBox)
      .X = iBtnLeft[1] + iBtnSize + 5
      .Y = 5
      .H = iBtnSize
      .W = 70
      .Alignment = Align.Center
      .Text = "1 of " & Me.ItemCount
   End With
   For i = 0 To 3
      hBtn = New Button(HBox) As "btn_Event"
      With hBtn
         .X = iBtnLeft
         .Y = 5 
         .H = iBtnSize
         .W = iBtnSize
         .tag = i
         .Picture = Picture[sPicture]
      End With

Public Sub btn_Event_Click()
   Select Case Last.Tag
      Case 0
         iIndex = 0
      Case 1
         If iIndex < iItemCount - 1 Then Inc iIndex
      Case 2
         If iIndex >= 1 Then Dec iIndex
      Case 3
         iIndex = iItemCount - 1
   End Select
   Raise Click

Private Sub ShowItems()
   hLabel.Text = (iIndex + 1) & " of " & iItemCount

Private Function ItemCount_Read() As Integer

Private Function ItemCount_Write(i As Integer)
   iItemCount = i
   hLabel.Text = (iIndex + 1) & " of " & iItemCount

Any help would be appreciated

User avatar
Posts: 113
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Custom Component problem

Post by Quincunxian » Wednesday 13th March 2019 10:53pm

Hi Bill,
I got this from the gambas Wiki - Did not see any of the following code in your example so looks like the X{Position} ect is what you are missing

For example, the value of Control._Properties is:
Link to the 'How to ' components page is

One of the projects that I have on my 'to-do' list is a checked list box - something I miss from my .net days.
I have one working in a standard class but need to go down the same route as you with a fully compiled one.
Cheers - Quin.
I code therefore I am

Posts: 130
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Custom Component problem

Post by bill-lancaster » Thursday 14th March 2019 9:19am

Thanks Quin,
I added :-

Code: Select all

Public Const _DefaultSize As String = "31,6"
and now the default size is appropriate.
Still a lot to learn!

Post Reply