Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding objects to toolbar

Status
Not open for further replies.

academica

Technical User
Feb 21, 2010
28
CN
I am creating my 1st toolbar. I have the following questions and problems:
1. Is there a sample toolbar like the Standard one in VFP with the common buttons (Open, Save, Cut, Copy, Paste, etc.)? I plan to copy and change it according to my needs. (I could not find one in the Solution samples.)

2. I am trying to interactively add to my toolbar 2 combos and a Separator, using the form control toolbar. I gave up! Can I use both interactive and programmatic methods to design my toolbar (and other objects, too)? Where can I add the extra code - e.g. tbrStandard.AddObject('sepSpace','Separator')
tbrStandard.AddObject('cboCombo2','Combobox')

VFP 9.0 SP2 on XP SP3
 
Is there a sample toolbar like the Standard one in VFP with the common buttons

No, but it should be quite easy to create your own. The controls are ordinary command buttons, and all the icons are available in the VFP directory.

Can I use both interactive and programmatic methods to design my toolbar

Yes. A toolbar is just like a form. You can add objects at design time or programmatically. If adding programmatically, a good place to put the code would be the toolbar's Init.

Can I give you another tip. If you want to have fine control over the positioning of the control in the toolbar, place a container in the toolbar, and place all the controls in the container. At run time, resize the container to the width of the screen (or to the height if the toolbar is vertical). You will then be able to position any control anywhere you like in the container (but this won't work properly if you allow the toolbar to float).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks, Mike, for the prompt and informative reply. I'll be trying to put it into action.

VFP 9.0 SP2 on XP SP3
 
At design time, you can treat a toolbar like a form. But, at runtime it behaves a bit differently. A toolbar cannot get focus. So you need to supply someway for keyboard users to get to the same functionality.

Craig Berntson
MCSD, Visual FoxPro MVP,
 
I'm guessing that the problem you're running into is getting Separators to land where you want them. I've never found a good solution to this and often have to try several times to get the result I want.

Tamar
 
Thank you, guys, for your help. This forum is sooooo helpful and effective.

Yes, Tamar, EXACTLY! All I want is to insert a combo, a separator and another combo in my toolbar and I stopped at the second object.

I am now trying to implement Mike's advice and to insert the three objects programmatically in the Init event. Tamar, is this how you solve this problem?

Would anyone give me a hint about the Init event code please. I'll add the other objects according to this example.

VFP 9.0 SP2 on XP SP3
 
If you try my idea of adding a container to the toolbar, and then adding the individual controls to the container, you won't need any separators (provided the toolbar stays permanently docked). You will be able to define the absolute position of each control.

Academica, you say: I am now trying to implement Mike's advice and to insert the three objects programmatically in the Init event.

I don't necessarily advise addings the objects programmatically - although it's perfectly possible to do so. What I said was that you are free to mix the two methods (adding them programmatically and in the designer) if you have a need to do that. Also, if you do decide to add them programmatically, the toolbar's Init is a good place to do so.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I generally handle this by adding and removing separators until they land where I want.

Tamar
 
Thank you, Mike and Tamar, for your responses.

Mike, I did try the container method (it IS described in VFP Help, too) but at runtime (i.e. by 'DO FORM...' command) I cannot reposition the superimposed controls.

A workaround I've found is:
1.(in the Command Window) CREATE CLASS test OF Test_lib AS 2.toolbar -> the Class Designer opens;
3.Add your controls from the Toolbox, in my case a ComboBox, a Separator and a ComboBox;
4.Save the new library 'Test_lib.vcx'
5.Add Test_lib.vcx to the Form Control Toolbar
6.Add the Test toolbar from the library to your form
7.Run the form: the toolbar is movable and dockable.

I welcome your comments.

The method by adding objects in the Init even procedure would work perfectly for me and I could use it for other purposes, though it's not advisable.

Would you give me an example code - which commands can I use to programmatically add controls in the Init even procedure.

VFP 9.0 SP2 on XP SP3
 
Academica,

You say you can't position the controls in the container, but you don't say why you can't.

If you are working in the class designer, you should be able to select a control and move it around in the normal way. If the control is inside the container, it won't position itself automatically, as it would if it was placed directly in the toolbar.

If you want to position the controls programmatically, just set the Top and Left properties. Again, that should work OK if the controls are in the container. Remember, the position is relative to the container, not to the toolbar.

You asked for help with creating the controls programmatically. Perhaps you could clarify why you want to do that. You know how to create the toolbar interactively, and you say it works OK. What problem do you have with that?

Also, you asked for examples for how to create the controls programmatically. But you've already got that code - you quoted it in your original question.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thank you, Mike, for your reply.
I've already solved this problem.
If you want to position the controls programmatically, just set the Top and Left properties.
Yes, I am new to the IDE and I'm still learning. Now it's clear.
You asked for help with creating the controls programmatically. Perhaps you could clarify why you want to do that. You know how to create the toolbar interactively, and you say it works OK. What problem do you have with that?
I prefer working programmatically because 1. I am new to the IDE; 2. debugging is easier; 3. tracing the code visually is easier for me (a habit from old procedural programming); 4. I can use code from the Help.

The best solution for me is to use both methods, which, alas, is not possible.

But you've already got that code - you quoted it in your original question.
Yes, I tried these commands tbrStandard.AddObject('sepSpace','Separator')
tbrStandard.AddObject('cboCombo2','Combobox')
but could not Add the Objects (why should I post this question if I could)

Meanwhile I am learning and many things are easier now.
And thanks for your consideration.

VFP 9.0 SP2 on XP SP3
 
Academica,

I'm still not clear why you feel you can't add the controls both interactively and programmatically. But never mind. You seem to be heading along the right path now.

Be sure to come back when you have more questions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top