Custom Component problem

Post

Posted
Rating:
#1 (In Topic #240)
Regular
bill-lancaster is in the usergroup ‘Regular’
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.

Code (gambas)

  1. ' Gambas class file
  2.  
  3.  
  4. Inherits UserControl
  5.  
  6. Public Const _DefaultEvent As String = "Click"
  7.  
  8. Property ItemCount As Integer
  9.  
  10. Event Click
  11.  
  12. Private sPicture As String[] = ["icon:/22/start", "icon:/22/right", "icon:/22/left", "icon:/22/end"]
  13. Private hBtn[4] As Button
  14. Private iBtnLeft As Integer[] = [5, 35, 145, 180]
  15. Private iItemCount As Integer
  16.  
  17. Public Sub _new()
  18. Dim i, iBtnSize As Integer
  19.    iBtnSize = 30
  20.    hBox.Border = Border.Plain
  21.    With hLabel = New Label(HBox)
  22.       .X = iBtnLeft[1] + iBtnSize + 5
  23.       .Y = 5
  24.       .H = iBtnSize
  25.       .W = 70
  26.       .Alignment = Align.Center
  27.       .Text = "1 of " & Me.ItemCount
  28.    End With
  29.    For i = 0 To 3
  30.       hBtn[i] = New Button(HBox) As "btn_Event"
  31.       With hBtn[i]
  32.          .X = iBtnLeft[i]
  33.          .Y = 5
  34.          .H = iBtnSize
  35.          .W = iBtnSize
  36.          .tag = i
  37.          .Picture = Picture[sPicture[i]]
  38.       End With
  39.    Next
  40.  
  41. Public Sub btn_Event_Click()
  42.    Select Case Last.Tag
  43.       Case 0
  44.          iIndex = 0
  45.       Case 1
  46.          If iIndex < iItemCount - 1 Then Inc iIndex
  47.       Case 2
  48.          If iIndex >= 1 Then Dec iIndex
  49.       Case 3
  50.          iIndex = iItemCount - 1
  51.    End Select
  52.    ShowItems
  53.    hBtn[Last.Tag].SetFocus
  54.    Raise Click
  55.  
  56. Private Sub ShowItems()
  57.    hLabel.Text = (iIndex + 1) & " of " & iItemCount
  58.  
  59. Private Function ItemCount_Read() As Integer
  60.    
  61.  
  62. Private Function ItemCount_Write(i As Integer)
  63.    iItemCount = i
  64.    hLabel.Text = (iIndex + 1) & " of " & iItemCount
  65.  
  66.  

Any help would be appreciated
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
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:

Code (gambas)

  1. X\{Position},Y\{Position},Width\{Dimension},Height\{Dimension},Visible=True,Enabled=True,Font\{Font},
  2. Background\{Color}=-1,Foreground\{Color}=-1,Tag,
  3. Mouse\{Mouse.Default;Blank;Arrow;Cross;Wait;Text;SizeAll;SizeH;SizeV;SizeN;SizeS;SizeW;SizeE;SizeNWSE;SizeNESW;SplitH;SplitV;Pointing}=Default,
  4. ToolTip,Drop,Expand,Ignore
  5.  

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
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
Thanks Quin,
I added :-

Code

Public Const _DefaultSize As String = "31,6"
and now the default size is appropriate.
Still a lot to learn!
Online now: No Back to the top
1 guest and 0 members have just viewed this.