CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    7

    Borland6 C++ EventHandlers

    I have a problem with event handling from code.
    I want to fill a StringGrid row with color. I did that with implementing the OnDrawCell Event.

    I still don't know how to use that event!
    On regular events i write code like:

    Code:
      TMenuItem *itemPod = new TMenuItem(PopupMenu2);
       itemPod->OnClick = ClickingTheButton;
    Code:
    void __fastcall TForm1::ClickingTheButton(TObject *Sender)
    {
    ....
    }
    ---------------------------------------------------------------------------------
    But in this situation i don't know which arguments should i use?!

    Code:
      TMenuItem *itemPod = new TMenuItem(PopupMenu2);
       itemPod->OnClick = ????????????????;             <-----this is missing!

    Code:
    
    void __fastcall TUtakmica::StringGrid1DrawCell(TObject *Sender, int ACol,
          int ARow, TRect &Rect, TGridDrawState State)
    {
    
    
       StringGrid1->Canvas->Brush->Color = clBlue;
       StringGrid1->Canvas->Font->Color = clRed;
       StringGrid1->Canvas->FillRect(Rect);
    
       StringGrid1->Canvas->TextRect(Rect, Rect.Left, Rect.Top, StringGrid1->Cells[ACol][ARow]);
    
    }

    I realized that this event is hapening on formCreate where StringGrid is.
    I want to call this event only on button click and not on formCreate!
    How can i do this!

    Thx!

  2. #2
    Join Date
    Oct 2005
    Posts
    199

    Re: Borland6 C++ EventHandlers

    You cannot assign OnClick -events with OnDrawXXX -events.

    OnClick -event(s) always have one parameter, TObject *Sender. The function on the bottom has invalid parameters to be used to handle click-events.

    Drawing -methods are called every time form is redrawn. If you want the drawing to happen only when you click a button, you can do it e.g. like this:

    Code:
    void __fastcall TForm1::ClickingTheButton(TObject *Sender)
    {
        // set the callback function to the item you want to draw here
        StringGrid1->OnDrawCell = StringGrid1DrawCell;
    
        Form1->Invalidate();  // or: StringGrid1->Invalidate();
    
        // disable drawing
        StringGrid1->OnDrawCell = 0;
    }
    'You help me, and I, in turn, am helped by you!'
    -H.S.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured