Board index » cppbuilder » Add menu item from button

Add menu item from button

Hi, how would i add a menu item to a menu from a button with the new menu
items caption coming from a TEdit ?

NETDEVEL

 

Re:Add menu item from button


Simply instantiate a new instance and assign its Caption afterwards:

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        TMenuItem *Item = new TMenuItem(YourMenu);
        Item->Caption = Edit1->Text;
        YourMenu->Add(Item);
    }

Gambit

Quote
"NETDEVEL" <NETDEV...@xtra.co.nz> wrote in message

news:3dbe687e@newsgroups.borland.com...
Quote
> Hi, how would i add a menu item to a menu from a button
> with the new menu items caption coming from a TEdit ?

Re:Add menu item from button


If you mean an OnClick handler:

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        TMenuItem *Item = new TMenuItem(YourMenu);
        Item->Caption = Edit1->Text;
        Item->OnClick = MenuClick;
        YourMenu->Add(Item);
    }

    void __fastcall TForm1::MenuClick(TObject *Sender)
    {
        // do something
    }

Gambit

Quote
"NETDEVEL" <NETDEV...@xtra.co.nz> wrote in message

news:3dbf2469$1@newsgroups.borland.com...
Quote
> ty remy but i forgot to ask how to add a function to each new item.

Other Threads