Custom Component problem

Post Reply
bill-lancaster
Posts: 55
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

Export

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
   Next
End

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
   ShowItems
   hBtn[Last.Tag].SetFocus
   Raise Click
End

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

Private Function ItemCount_Read() As Integer
   
End

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



Any help would be appreciated

User avatar
Quincunxian
Posts: 37
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:
X{Position},Y{Position},Width{Dimension},Height{Dimension},Visible=True,Enabled=True,Font{Font},
Background{Color}=-1,Foreground{Color}=-1,Tag,
Mouse{Mouse.Default;Blank;Arrow;Cross;Wait;Text;SizeAll;SizeH;SizeV;SizeN;SizeS;SizeW;SizeE;SizeNWSE;SizeNESW;SplitH;SplitV;Pointing}=Default,
ToolTip,Drop,Expand,Ignore
Link to the 'How to ' components page is http://www.gambaswiki.org/wiki/dev/gambas

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

bill-lancaster
Posts: 55
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