Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C++ Builder > Событие при нажатии на динамическу кнопку


Автор: Sergio 30.4.2007, 15:23
Здраствуйте. Как обработать событие при нажатии на динамическу кнопку? Вот кнопка:
Код

        Forma = new TForm(Application, 1);
        Forma->Width = 320;
        Forma->Height = 365;
        Forma->Left = Form1->Left + Form1->Width/2 - (Forma->Width/2);
        Forma->Top = Form1->Top + Form1->Height/2 - (Forma->Height/2);
        Forma->BorderStyle = bsSingle;
        Forma->BorderIcons = TBorderIcons() <<biSystemMenu <<biMinimize;
        Forma->Show();

        SendButton = new TButton(Forma);
        SendButton->Parent = Forma;
        SendButton->Left = Forma->Width - SendButton->Width - 15;
        SendButton->Top = Forma->Height - SendButton->Height - 45;
        SendButton->Caption = "ok";       

Зарание спасибо.

Автор: Anikmar 30.4.2007, 16:11
Присвоить свойсту OnClick адрес метода-обработчика.
Создайте в форме метод по образцу buttonщвского OnClick и после создания кнопки напишите:

SendButton->OnClick = MyOnClick;

Автор: Klin 30.4.2007, 18:51
Чтобы не было вопросов smile :

В -cpp файле:
Код

 . . . . . . .
  SendButton->Top = Forma->Height - SendButton->Height - 45;
  SendButton->Caption = "ok";   
  SendButton->OnClick  = MyClick;
 }

 void __fastcall TForm1::MyClick(TObject *Sender)
 {
  Forma->Close();
 }


В -h файле:
Код

class TForm1 : public TForm
{
__published:
 void __fastcall MyClick(TObject *Sender);
 . . . . . . .

Автор: Sergio 30.4.2007, 20:42
Klin, что-то не понял что писать в Н файле. Зачем класс TForm1? Я думал что вот так надо:
В -h файле
Код

class PrivateForm {

 private:
    String Ip;
    String Nick;

    TForm* Forma;
    TMemo* ReceiveMemo;
    TMemo* ReceiveMemo2;
    TButton* SendButton;

 public:
    PrivateForm(String _IP, String _Nick);
    ~PrivateForm();
 private:
 void __fastcall MyClick(TObject *Sender); 
 };

P.S. что за "__published:"?? Потому что мне "компиллер" написал:
Цитата

[C++ Error] File2.h(25): E2289 __published or __automated sections only supported for VCL classes

Автор: Klin 30.4.2007, 21:13
Это я пример написал, с кусом кода из билдера, короче пишешь просто: void __fastcall MyClick(TObject *Sender); 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)