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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change caption on Command Buttons

Status
Not open for further replies.

tilltek

Programmer
Mar 8, 2001
298
PH
I have a dozen or so Command Buttons on a form which allow the user to input information easily.
Button "Command1" may have the caption "FROGS" and when clicked return "XF001" which is a code in a product datafile for frogs.
My question.. How can I allow these captions and what they return be set by the user?
Can "Command Button Captions" and "Click Events" come from a data file?
 
Yes, this is easy.

It's up to you to decide where to store the caption text. There's no problem in putting them in a table. At run time, all you need to do is to retrieve the text from the table and store it in the button's Caption property.

You also have to decide how the user is to choose which caption to display. Choose whatever mechanism you like for that.

Once you know which caption you want to display for a given button, set the button's Caption property to the appropriate text.

As for you other question -- which text the button should "return" -- that depends on what you mean by "return". In general, button's don't return anything; they perform an action. Perhaps you could clarify your requirements.

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks Mike, I figured there would be something like that available and I have managed to do it programaticaly but I can figure out how to do it, or where to do it when adding a command button to a form. Or looking at that buttons properties.

About "return", bad choice of words on my behalf
What I need is up to 20 or so command buttons that will, when clicked, enter something that would normally come from the key board.
Kenny in Camiguin
 
Kenny,

What I need is up to 20 or so command buttons that will, when clicked, enter something that would normally come from the key board.

Thanks for the clarification. So you want a sort of auto-text facility (like in Word), where the user can assign a word or phrase to a button, and have that text entered into an editing control when the button is clicked.

One way to do that would be with the KEYBOARD command. You can use that command to programmatically type the text. But there are some complications.

You'd have to have some way of knowing which control is to receive the text. You can't rely on the ActiveControl property, because that would simply point to the command button. You'd also need to know where the insertion point is. You could determine that from the SelStart property, but you'd have to store that before the editing control loses focus. The command button's Click event would have to set focus back to the editing control, put the insertion point in the correct place, and then issue the KEYBOARD command.

It's probably do-able, but difficult.

May I suggest an alternative? Instead of using command buttons, consider using a shortcut menu. The menu would appear when the user right-clicks within the editing control. It could include all the auto-text entries, possibly arranged in cascading sub-menus to make navigation easier. The user would click on a sub-menu entry (or use an associated shortcut key) to enter the text at the insertion point.

The advantage of a sub-menu over command buttons is that it works within the context of the control you are editing. The control always retains focus and keeps track of its own insertion point. The code called from the menu would simply do the KEYBOARD command. It would also be easier to make it generic (all your text boxes and edit boxes could have such a menu), plus it would reduce clutter on the form.

Just a thought.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Well,

Mike has explained some of the pitfalls such buttons would have. There is a way of making this work with making use of more events at hand.

First of all, I'd make a generic button, not 20 special buttons. The task is always the same, have a shortcut for entereing some text snippet. That could be one button class being data driven, including it's caption.

Mike correctly points out that Activecontrol will point to the command button in the click event, but not in the When() event. So you can determine which control has the focus when the button is clicked, because at first the When event is called, then Gotfocus() and then click(). In When you could deny the focus to move, by returning .T., but you can also simply determine which control has focus. The rest should be easy, in the When() you store Thisform.Activecontrol to a user defined button property, in the click() you use a KEYBOARD command and set focus to the control you stored in the When() event and the Text will arrive at that control in whatever position the cursor has there.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top