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

Menu Bar and command button synchronized

Status
Not open for further replies.

LindaRichard

Programmer
Feb 23, 2001
103
0
0
CA
Hi,

I have a menu bar that contains cut/copy/paste items
_med_copy etc... This menu bar was created using the wizard
and displayed using

do menuiso.mpr ( I am using VFP 8.0 sp1)

This works fine various cut/copy/paste items are enabled/disabled depending what type of control is being
edited on the form.

I also have a toolbar in a form that has 3 command buttons
which shows the standard cut/copy/paste icons.

When the form containing the buttons is refreshed I would
like the buttons to be enabled/disabled depending on whether
the cut/copy/paste is available. Does anyone know how I
can determine it an item in a menu bar is enabled/disabled
or if there is any other was of finding out if cut/copy/paste are available.

VFP controls the enabled property of the menu items in my
menu bar. VFP handles automatically turning on/off the
items depending on whether there is someting to
cut/copy/paste. How can I tap into this, is there
a way of knowing this when I refresh my buttons and
control their enabled property.

Thanks for your help
Linda
 
Linda,

Call SYS(1500) from the toolbar buttons. This will let the buttons exactly mimic the behaviour or the Cut, Copy and Paste menu commands, including the automatic greying out when there is nothing to cut/copy or paste.

For example, the Click event of your Paste button will look like this:

SYS(1500, '_MED_PASTE', '_MEDIT')

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike,

Thanks for your reply, I appreciate you taking the time,
to answer my question.

I have part of my problem resolved.

In the refresh event of class that contains my toolbar
I place the following code:

IF SKPPAD('_medit','_med_cut') then
this.cmdCut.enabled=.f.
ELSE
this.cmdCut.enabled=.t.
endif
IF SKPPAD('_medit','_med_copy') then
this.cmdCopy.enabled=.f.
ELSE
this.cmdCopy.enabled=.t.
endif
IF SKPPAD('_medit','_med_paste') then
this.cmdPaste.enabled=.f.
ELSE
this.cmdPaste.enabled=.t.
endif

This of course causes the buttons to be enabled/disable
on the toolbar simularly to what they are set on the
menubar.

Then in the click event of each button I placed the
code that you gave me.

SYS(1500, '_MED_PASTE', '_MEDIT')

My last issue is getting the toolbar to refresh
everytime the copy/cut/paste status changes.
I tried the click event of a form but the problem
is that it only triggers when I click outside a
control. Is there anyway of capturing any click
on the form (in or out of a control) to allow
the toolbar to be refreshed when required.

Thanks again
Linda
 
Linda,

Is there anyway of capturing any click
on the form (in or out of a control) to allow
the toolbar to be refreshed when required.


The short answer is Yes -- you can use the form's Keypress and Keypreview properties for that. But I don't think that will solve the problem. After all, what if the clipboard is empty (so Paste is disabled), but another application copies some text to it. Wouldn't you want the Paste button to be activated in that case?

Maybe the answer is to add a timer to the toolbar. Fire it every, say, 500 ms. In the Timer event, enable the Paste if the clipboard contains text:

MyToolbsar.PasteButton.Enabled = not empty(_cliptext)

and enable the Cut and Copy if there is text selected in the active control:

if vartype(_screen.Activeform.ActiveControl.SelText) <> "U"
MyToolbar.CutButton.enabled = not empty(_screen.activeform.activecontrol.SelText)
endif

I haven't tested the above code, so it might need refining. Also, I'm not sure if a timer is the best way to do it. But I can't think of anything else that would be completely reliable.

MIke




Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike thanks for your reply.

It sounds like it will work, but as you mention,
my only concern is the use of the timer.
I will give it a try.

Thanks again for your help.

Linda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top