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.

Dr_Acula

Beginner

  • "Dr_Acula" is male
  • "Dr_Acula" started this thread

Posts: 8

Date of registration: Feb 22nd 2011

Location: Adelaide, Australia

Occupation: Medical practitioner

  • Send private message

1

Thursday, February 24th 2011, 5:00am

What is a good program structure?

In this folder C:\Program Files\Jabaco\Samples\ControlDemo is a very good demonstration program. It shows how to get a menu working, a toolbar, and how all the controls work.

I would like to take this further and have two richtextboxes. Each richtextbox will almost fill the screen, and I want to be able to switch between these.

1) In my version of VB5/6 I don't seem to be able to find a Tabstrip. Maybe it was an add on?. So back 10 years ago, I was putting two richtextboxes on Form1 and then hiding them and showing them alternately. This works, but maybe it is not the best method?

2) In vb.net, you can interact with the Tabstrip on the GUI, and place richtextbox1 on Tab1, and richtextbox2 on Tab2. Then you can code simple things like

Source code

1
richtextbox2.text=richtextbox1.text


3) In jabaco things a bit different. The Tabstrip is set up in code rather than on the GUI, and this code is demonstrated in that very nice example above. As far as I can tell, each Tabstrip page is set up as a new "usercontrol" and then you place richtextbox1 on usercontrol1, and richtextbox2 on usercontrol2.

Then on the menu bar, use this sort of code (copied from the example)

Source code

1
2
3
4
5
6
7
Public Sub Form_MenuClick(MenuItem As IMenuItem)
   Select Case MenuItem.ControlID
  	Case "mnuShowChart": TabStrip1.SelectedIndex = 1
  	Case "mnuShowUsers": TabStrip1.SelectedIndex = 2
  	Case "mnuShowProducts": TabStrip1.SelectedIndex = 3
   End Select
End Sub


This works very well, but each richtextbox cannot interact with any other richtextbox. The usercontrol appears to be self contained, so it does not know about controls on other usercontrols, or on form1. Even global variables do not seem to work (Dim in either Form1 or in the main Module).

What would be the best way to write this sort of code?

Is there a way of transferring data between usercontrols, eg richtextbox1.text=richtextbox2.text

Or is it better not to use the Tabstrip, and to put every single control on the one page, and then hide and show them as needed?

Or is there an even better solution?

Thankyou in advance.

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

Thursday, February 24th 2011, 8:37am

You could write an init() method per UserControl to tell this usercontrol about the other controls it is supposed to interact with.
Using init() you could pass objects to the usercontrol. These objects are then stored as local private variables of the usercontrol.

Another approach is to use global variables. If you declare a variable as public in a Module, this variable becomes visible everywhere.

You might want to have a look at the SplitPane control. Use the forum search facility to find details.

Happy experimenting!

A1880

Dr_Acula

Beginner

  • "Dr_Acula" is male
  • "Dr_Acula" started this thread

Posts: 8

Date of registration: Feb 22nd 2011

Location: Adelaide, Australia

Occupation: Medical practitioner

  • Send private message

3

Friday, February 25th 2011, 8:36am

init() sounds interesting - I'll check that out.

Tested global variables - that works well too. Declare a global variable in the main module.

With a separate usercontrol for each part of the tab code, it gets very complicated to code. For instance, if you put a button on one usercontrol and want to change the tab to a different tab, how do you do that?

The tabstrip1 exists on Form1, not on Usercontrol1. So Usercontrol1 can't see Tabstrip1, so it can't do something simple like Tabstrip1.SelectedIndex = 2

You could put a timer on Form1, check GlobalVariable every 100ms and pass control that way. It is a bit messy though.

Or - another thing I just found. You can put everything on Form1, and then move things around in code. You can move richtextbox1 so it sits on top of Tabstrip1. Then if you click the second tab, you could hide richtextbox1, show richtextbox2, and put this on top of the Tabstrip1. This gives the appearance that one is tabbing between richtextboxes, and also means that everything is in Form1, so they can all talk to each other.

I found a small bug too. If you have Form1 and Usercontro1, and you want to delete Usercontrol1, you right click it (over on the right part of the screen) and select "Delete". But it seem to delete the item under that item. Or sometimes the one above. So you right click Usercontrol1 and delete it and it actually deletes Form1

I shall do some more experiments.

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

4

Friday, February 25th 2011, 10:24am

The object-oriented way to launch an activity in object A from within object B is to implement a public method in A and call it from B.
To do that, you have to pass B a reference to A. If the objects are forms and controls, the situation is rather static and the object
references can be passed during initialization.

During my experiments with Jabaco I've come across one pecularity of Java swing:
event handlers of controls have to make sure that they don't spawn follow-up events.
I used flag variables to detect and avoid nested events.

I would not store global variable in Main but rather introduce a separate Module "Global" for that.
Obviously, global variables have their problems and should only be used in rare circumstances.
One problem is debugging and code maintenance. Another problem is that global variables
are difficult to handle in multi-threaded applications where several threads have access to the
same variable.

Happy experimenting

A1880

Dr_Acula

Beginner

  • "Dr_Acula" is male
  • "Dr_Acula" started this thread

Posts: 8

Date of registration: Feb 22nd 2011

Location: Adelaide, Australia

Occupation: Medical practitioner

  • Send private message

5

Saturday, February 26th 2011, 11:55am

event handlers of controls have to make sure that they don't spawn follow-up events.

Yes, I agree! I've had all sorts of bugs in code where you set a richtextbox to autoupdate things, that then spawn other autoupdates. eg I have some code that does syntax highlighting in color. I found it was simpler in the end to just add a button "update color".

I agree about trying not to have global variables.

Ok, so I am doing some experiments with tabstrip1. I have a tabstrip and I want to detect when the user clicks the tabstrip, and in particular which tab they clicked.

I found a little example of some vb6 code here http://www.vb-helper.com/howto_tabstrip_with_frames.html
which has
TabStrip1.SelectedItem.Index
However, this does not seem to be an option in jabaco.

So I went back one step to this bit of code

Source code

1
2
3
Public Sub TabStrip1_Click()
MsgBox("tab strip clicked")
End Sub


but even that does not print a message when you click the tab strip.

Any suggestions how we could get this working?

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

6

Saturday, February 26th 2011, 12:23pm

The idea of the TabStrip is to add one usercontrol per Tab as explained here.
Then you can use the event handlers of the user controls to find out what Tab has been clicked.

Please correct me if I'm wrong.
I haven't tried this myself yet.

Greetings

A1880

Dr_Acula

Beginner

  • "Dr_Acula" is male
  • "Dr_Acula" started this thread

Posts: 8

Date of registration: Feb 22nd 2011

Location: Adelaide, Australia

Occupation: Medical practitioner

  • Send private message

7

Sunday, February 27th 2011, 11:40am

Ok, I have something working here.

* Put a timer on Form1. Tick every 100ms. Enabled = True.
* Put a tabstrip on form1. Create two new usercontrols.
*Create a global variable for passing messages in Module1
Public GlobalMessage As String
* In usercontrol1, add a button with this code

Source code

1
2
3
Public Sub Command1_Click()
   GlobalMessage = "Test"
End Sub

* On Form1 in the timer

Source code

1
2
3
4
5
6
Public Sub Timer1_Timer()
  If GlobalMessage="Test" Then
	TabStrip1.SelectedIndex = 2
	GlobalMessage = "" 'clear the message
  End If   
End Sub


Now if you click the button on tab1, it changes to tab2. You can also add timers on usercontrol1, and usercontrol2, and then pass messages this way.

If the best way to create tabstrips is to have a new usercontrol for each tab, maybe this is a way for each usercontrol to communicate with other ones, and with Form1?

Maybe there is a better way, instead of a single string, create an array with Source, Destination, Message and any form/usercontrol can add to that list, and when a message is read it is deleted?

This post has been edited 1 times, last edit by "Dr_Acula" (Feb 27th 2011, 12:39pm)


Rate this thread
WoltLab Burning Board