Thursday, May 17th 2012, 7:22pm UTC+2

You are not logged in.

  • Login
  • Register

Peter

Trainee

Posts: 69

Location: Cologne, Germany

Occupation: Second Vice President of Distributed Junk and Trash Development

1

Monday, September 20th 2010, 5:17pm

Toolbar in einem UserControl möglich?

Hallo,

ist es möglich, einem UserControl eine Toolbar hinzuzufügen?

Jabaco Source

1
2
3
4
5
6
7
Public Sub Usercontrol_Initialize()
   CreateToolBar
End Sub

Private Sub CreateToolBar()
   ToolBar.createToolBarItem "tabAdd", vbNullString, "Add", AddPng
End Sub

... schlägt fehl:


Quoted

java.lang.Exception: CallByName 'createToolBarItem' failed!
at VBA.Interaction.CallByName(Interaction.java:186)
at VBA.Interaction.CallByName(Interaction.java:184)
at VBA.Interaction.CallByName(Interaction.java:175)
at uctrlProducts.CreateToolBar(uctrlProducts.jsrc:10)
at uctrlProducts.Usercontrol_Initialize(uctrlProducts.jsrc:2)
at VB.Usercontrol.fireLoaded(Usercontrol.jsrc)
at VB.LoadAdapter.run(LoadAdapter.jsrc)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Danke im voraus & Grüße ... Peter

A1880

Intermediate

Posts: 500

Location: Hanover, Germany

Occupation: Software Engineer

2

Tuesday, September 21st 2010, 10:15am

Eine ToolBar kann man m.E. nur in Form, Dialog oder Applet erzeugen.
Ein Usercontrol ist ja nur eine Ansammlung von Controls (oder rekursiv Usercontrols ...), um die mühsame Definition von gleichartig sich wiederholenden Control-Konstellationen zu erleichtern. Wie man kaum einer PictureBox oder einem Frame eine ToolBar verpassen würde, so fällt mir auch keine Begründung dafür ein, es bei einem Usercontrol zu versuchen.

Wenn Du Deinem Beispiel-Code die Zeile "Option Explicit" voranstellst, bekommst Du zur Compile-Zeit auch schon eine hilfreiche Fehlermeldung.
Usercontrol hat kein Member Object "ToolBar". Das gibts eben nur in Form, Dialog und Applet.

Natürlich wäre es denkbar, die Framework-Klasse VB.Usercontrol als Mutter aller Usercontrols um eine ToolBar zu erweitern.

Gruß!

A1880

Peter

Trainee

Posts: 69

Location: Cologne, Germany

Occupation: Second Vice President of Distributed Junk and Trash Development

3

Tuesday, September 21st 2010, 2:41pm

Hallo A1880,

danke für Deine schnelle Antwort!

Quoted from "A1880"

Wie man kaum einer PictureBox oder einem Frame eine ToolBar verpassen würde, so fällt mir auch keine Begründung dafür ein, es bei einem Usercontrol zu versuchen.

ich würde gerne in jedem Tab eines TabStrip eine andere Toolbar platzieren (siehe Screenshot).
So, wie ich das verstanden habe, kann man Tabs nur mit UserControls befüllen. Daraus resultiert meine Frage.



Nun gut, dann muss ich mir ein anderes GUI-Konzept überlegen.

Danke & Grüße ... Peter

A1880

Intermediate

Posts: 500

Location: Hanover, Germany

Occupation: Software Engineer

4

Tuesday, September 21st 2010, 3:18pm

Du könntest statt ToolBars Usercontrols definieren, die jeweils aus PictureBoxes mit Eventhandlern bestehen.
Dein ToolBar-Usercontrol könnte eine Init-Methode bekommen, bei dem es dynamisch festlegt, welche Bilder wo geladen werden.
Vermutlich müsstest Du eine Resize-Methode implementieren, damit das Usercontrol seine Breite bei Bedarf anpasst.

Gruß!

A1880

OlimilO

Intermediate

Posts: 277

Location: Germany

Occupation: software engineer

5

Tuesday, September 21st 2010, 6:49pm

Hallo Peter,

die UI sieht ja eigentlich ganz nett aus.

ich würde mich nicht lange mit den Jabaco-Klassen VBToolBar und VBToolBarItem rumärgern, sondern stattdessen schauen wie die gemacht sind. VBToolBar und VBToolBarItem regeln einfach das Handling mit einer Form.



VBToolBar ist ne abgeleitete Klassen von javax#swing#JToolBar

VBToolBarItem ist ein Nachfahr von javax#swing#JButton



mach einfach selber eine oder zwei Klasse die das Handling anstatt mit einer Form mit einem UserControl regelt.



Gruß

OlimilO

OlimilO

Intermediate

Posts: 277

Location: Germany

Occupation: software engineer

6

Wednesday, September 22nd 2010, 12:44pm

Everywhere: Freedom for ToolBar

Hi @ll,

it's all that easy :)
Add a new Class and name it Toolbar.
In Propertyeditor for the SuperClass select javax/swing/JToolBar
and add the following Code to the ToolBar-Class:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Option Explicit
Implements ActionListener
Private Const PreferredBtnHeight As Integer = 26
Private Const PreferredBtnWidth  As Integer = 26
Public Event ButtonClick(ActionCmd As String)
Public Sub ToolBar
   Me.setVisible(True)   
   Me.setLocation(0, 0)   
   Me.setFloatable(False)
End Sub
Public Sub AddButton(Text As String, ToolTip As String, ActionCmd As String)
   Dim btn As New JButton
   btn.setText(Text)
   btn.addActionListener(Me)
   btn.setToolTipText(ToolTip)
   btn.setActionCommand(ActionCmd)   
   btn.setSize(PreferredBtnWidth, PreferredBtnHeight)
   Me.add(btn)
End Sub
Public Sub actionPerformed(arg2 As ActionEvent)
   RaiseEvent ButtonClick(arg2.getActionCommand)
End Sub


Now add a new UserControl to your project
switch to the Codepane of the UserControl-Class and add the following Code:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Option Explicit
Dim Withevents ToolBar As New ToolBar
Public Sub Usercontrol_Initialize()
   Me.add(ToolBar)
   ToolBar.setSize(Me.Width, 26)
   ToolBar.AddButton("ABC", "dings ABC", "ABC")
   ToolBar.AddButton("DEF", "dings DEF", "DEF")      
End Sub
Sub ToolBar_ButtonClick(ActionCmd As String)
   Select Case ActionCmd'.getActionCommand 
   Case "ABC": MsgBox("The ABC Button was pressed in " & "UserControl1")
   Case "DEF": MsgBox("The DEF Button was pressed in " & "UserControl1")
   End Select
End Sub


Of course you can use this ToolBar in a Form:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Option Explicit
Dim Withevents TB As New ToolBar
Public Sub Form_Load()    
   Me.add(TB)   
   TB.setSize(Me.Width, 26)
   TB.AddButton("ABC", "dings ABC", "ABC")
   TB.AddButton("DEF", "dings DEF", "DEF")  
End Sub
Sub TB_ButtonClick(ActionCmd As String)
   Select Case ActionCmd'.getActionCommand 
   Case "ABC": MsgBox("The ABC Button was pressed in " & "Form1")
   Case "DEF": MsgBox("The DEF Button was pressed in " & "Form1")
   End Select
End Sub


One issue of the Form-Class: you can not use the Name ToolBar because there is already a function with that name.

One issue of the ToolBar-Class: when using it floatable and clicking a button will close the Floatform and bring the ToolBar back docked to Form1.



regards

OlimilO

Rate this thread
WoltLab Burning Board