You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

riaanp

Beginner

  • "riaanp" is male
  • "riaanp" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

1

Sunday, January 3rd 2010, 7:17pm

Jabaco User Control

Hi Community ,

Does anyone know how to give a "properties" option to a user control, to clarify if you add command button it has properties you can set like widht, height etc.

And also mabe assigning a icon to it? (not needed but would be great)
I am ROOT if you see me laughing you better have a backup! :cursing:

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Sunday, January 3rd 2010, 8:16pm

The properties of a Usercontrols are defined when you design it.
Just "add" a Usercontrol to your project. This will put you in a control editing mode, similar to the usual form or dialog editing.
You then design the control including its icons, buttons etc.
Once you have saved the Usercontrol, you call or put copies of it on your form(s).
Doing so, you define the left/top coordinates of the Usercontrol instances.

At runtime, you can assign properties to your control by defining and calling Usercontrol properties in the Usercontrol source code.

I found it practical to define a common "Interface" for various Usercontrols.

Sample of an interface for Usercontrols:

Jabaco Source

1
2
3
4
5
6
7
8
Public Function description() As String
End Function

Public Sub reset()
End Sub

Public Function query() As String
End Function


Using the "implements" keyword you can tell Jabaco, that a given Usercontrol implements a certain interface.
You can then use the interface as object type to administer and pass references to your Usercontrols as function parameters.
I wanted to loop through all Usercontrols and call their respective init() or resize() routines.

Sample code for a Usercontrol:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Implements IUCreset

Private initCalls As Integer 
Private dbField As String

Public Sub Init(left As Integer, top As Integer, width As Integer, caption As String, field As String)

   initCalls = initCalls + 1
   
   If initCalls = 1 Then
      dbField = field
      Me.Height = 27
      Me.BackColor = myForm1.BackColor 

      Label1.Caption = " " & caption
      Text1.Text = ""
      
      If field <> "" Then
         Text1.ToolTip = "Textfeld " & caption & " (Datenbankfeld '" & field & "')"
      Else
         Text1.ToolTip = "Textfeld " & caption
      End If

      myForm1.registerUsercontrol Me   '  this adds the Usercontrol to an array for looping purposes
   End If 

   Me.Left = left
   Me.Top = top
   Me.Width = width
   resize
End Sub

Public Function query() As String
   Dim s As String = ""
   Dim t As String = Trim(Text1.Text)
   Dim op As String = "="
   
   If t <> "" Then
      t = Replace(t, "*", "%")
      t = Replace(t, "?", "_")
      
      If (InStr(t, "%") > 0) Or (InStr(t, "_") > 0) Then
         op = "LIKE"
      End If
      
      s = "( " & dbField & " " & op & " '" & t & "' )" & vbCrLf
   End If
   
   query = s
End Function

Public Function description() As String
   Dim s As String = ""
   Dim t As String = Trim(Text1.Text)
   
   If t <> "" Then      
      s = Trim(Label1.Caption) & " = '#MA" & t & "#MB'"
   End If
   
   description = s
End Function

Private Sub resize()
   Const xGap = 5
   Const yGap = 5
   Const h = 17

   Label1.Width = (Me.Width - 2 * xGap) / 2
   Label1.Left = 0
   Text1.Left = Label1.Left + Label1.Width + xGap
   Text1.Width = Label1.Width - Picture1.Width - 2 * xGap
   Picture1.Left = Me.Width - Picture1.Width - xGap
   
   Label1.Height = h
   Text1.Height = h
   
   Label1.Top = yGap
   Text1.Top = Label1.Top
   Picture1.Top = Label1.Top + (h - Picture1.Height)/2
End Sub

Public Sub Picture1_Click()
   reset
End Sub

Public Sub reset
   Text1.Text = ""
End Sub


Logic in the main form for maintaining Usercontrols:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'  keep all user controls in a list
'  to allow for reset and SQL query calculation
Private ucList As java#util#ArrayList

Public Sub cmdReset_Click()
   Dim i As Integer 
   
   For i = 0 To ucList.size - 1
      Cast(ucList.get(i), IUCreset).reset 
   Next i
End Sub

Public Sub Form_Load()
   NL = vbCrLf                       '  abbreviation
   myForm1 = Me                      '  cf. mdlGlobal variable
   ucList = New java#util#ArrayList  '  list of user controls   
End Sub

Public Sub Form_Resize()
   Const xGap = 20
   Const yGap = 16
   
   Dim columnWidth As Integer
   Dim rowHeight As Integer = 27 + yGap
   Dim minHeight As Integer = yGap + cmdSearch.Height + yGap + 9 * rowHeight + yGap + 5
   Dim minWidth As Integer = xGap + cmdSearch.Width + xGap + cmdReset.Width + xGap + cmdEnd.Width + xGap
   Dim x As Integer 
   Dim y As Integer 
      
   If Me.Width < minWidth Then
      Me.Width = minWidth
   End If
   
   If Me.Height < minHeight Then
      Me.Height = minHeight
   End If
   
   columnWidth = (Me.Width - 4 * xGap) / 3

  '  automatic positioning of Usercontrols
   x = xGap
   y = yGap
   ucTrackId.Init x, y, columnWidth, "Track-ID", "cFree10"
   y = y + rowHeight
   ucDirection.Init x, y, columnWidth, "Richtung", "cDirection"
   y = y + rowHeight
   ucCategory.Init x, y, columnWidth, "Kategorie", "cFree18"
   y = y + rowHeight
   ucBusinessUnit.Init x, y, columnWidth, "Business Unit", "cPartner"
   y = y + rowHeight
   ucStart.Init x, y, columnWidth, "Startzeit", "cProcessingTimeStart"
   
   x = ucUNB.Left + ucUNB.Width + xGap
   y = yGap
   ucStatus.Init x, y, columnWidth, "Status", "cStatus"
   ucStatus.selectText "SUCCESS"
   y = y + rowHeight
   ucSource.Init x, y, columnWidth, "Quelle", "cFree2"
   y = y + rowHeight
   ucDestination.Init x, y, columnWidth, "Ziel", "cFree3"
   y = y + rowHeight
   ucEnd.Init x, y, columnWidth, "Endzeit", "cProcessingTimeEnd"

   x = ucDestination.Left + ucDestination.Width + xGap
   y = yGap
   ucAggregation.Init x, y, columnWidth, "Aggregationsperiode", "",fmMultiSelectSingle 

   cmdSearch.Left = xGap
   cmdReset.Left = cmdSearch.Left + cmdSearch.Width + xGap
   cmdEnd.Left = Me.Width - cmdEnd.Width - xGap
   
   y = Me.Height - cmdSearch.Height - 1.7 * cmdSearch.Height 
   cmdSearch.Top = y
   cmdReset.Top = y
   cmdEnd.Top = y

   If columnWidth > picLogo.Width Then
      picLogo.Left = x + columnWidth - picLogo.Width
      picLogo.Top = y - picLogo.Height - yGap
      picLogo.Visible = True
   Else
      picLogo.Visible = False
   End If
   
   Me.Refresh 
   DoEvents
End Sub

Public Sub registerUsercontrol(uc As IUCreset)
   ucList.add uc
End Sub


I haven't tried yet to put Usercontrols inside other Usercontrols.
This should be feasible but I don't have any practical use case for that.

Happy experimenting with Usercontrols!

A1880

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

3

Sunday, January 3rd 2010, 10:47pm

Damn dude... that is a intense sample and description! Thank you very much i will experiment and if i make something usable will post it here for other to use :)
I am ROOT if you see me laughing you better have a backup! :cursing:

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

4

Sunday, January 3rd 2010, 11:11pm

But.. I need something like this? is it possible?

Public Enum UCBorderStyles
UCBorderNone = 0
UCBorderFlat = 1
UCBorderThin = 2
UCBorderFrame = 3
UCBorderThick = 4
End Enum
I am ROOT if you see me laughing you better have a backup! :cursing:

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

5

Monday, January 4th 2010, 12:05am

Hi,

I figured out what I wanted to do. In this example I am using a LABEL as a "user control". The custom property name is
RiaanLabelCaption and the text for it is TESTING!

Sample Attached. I hope this can help someone!

JabcoSam.zip
I am ROOT if you see me laughing you better have a backup! :cursing:

Rate this thread
WoltLab Burning Board