PDA

View Full Version : [BCB6] i Menu


Argosoft
23-11-2003, 11:14
come faccio da codice ad abilitare/disabilitare una singola voce di un MainMenu? o di un PopupMenu?


thanks!

verloc
24-11-2003, 09:24
It is often useful to disable menu commands without removing them from the menu. For example, in a text editor, if there is no text currently selected, the Cut, Copy, and Delete commands are inapplicable. An appropriate time to enable or disable menu items is when the user selects the menu. To disable a menu item, set its Enabled property to false.
In the following example, an event handler is attached to the OnClick event for the Edit item on a child form’s menu bar. It sets Enabled
for the Cut, Copy, and Delete menu items on the Edit menu based on whether RichEdit1 has selected text. The Paste command is enabled or disabled based on whether any text exists on the Clipboard.

void __fastcallTMainForm::EditEditClick(TObject *Sender)

{
// enable or disable the Paste menu item
Paste1->Enabled = Clipboard()->HasFormat(CF_TEXT);
bool HasSelection = (RichEdit1->SelLength > 0); // true if text is selected
Cut1->Enabled = HasSelection; // enable menu items if HasSelection is true
Copy1->Enabled = HasSelection;
Delete1->Enabled = HasSelection;
}

The HasFormat method of the Clipboard returns a Boolean value based on whether the Clipboard contains objects, text, or images of a particular format. By calling HasFormat with the parameter CF_TEXT, you can determine whether the Clipboard contains any text, and enable or disable the Paste item as appropriate.

Argosoft
26-11-2003, 21:14
uh, GRAZIE un po' in ritardo scusa per la domanda che è veramente molto scema ma... sono incappato in una delle stranezze del BCB!! in pratica io volevo abilitare/disabilitare sti cosi da una funzione fatta da me (non da un evento) ...e non funzionava! ho provato di tutto.... alla fine la cosa giusta da fare era........


Form1 -> MenuSalva -> Enabled = ....


che mmerdaaaaaaaaaaaaaaaaaaaaaaa dovevo specificare Form1


grazie lo stesso, eh! :cincin:

verloc
27-11-2003, 08:39
Se stai facendo questo per non concedere funzionalità agli utenti
non registrati (o cose simili)...

indubbiamente è un ottimo metodo per suicidarsi...(programmatoriamente parlando) :D



Non lo fare!

Argosoft
27-11-2003, 15:44
sta cosa mi serve per rendere un programma ancora più "professionale" :D (per esempio: se non c'è nessun documento aperto è inutile che il tasto "Salva" sia abilitato!)



indubbiamente è un ottimo metodo per suicidarsi...(programmatoriamente parlando) :D


Non lo fare!


ehmmm... :wtf: