trichview.com

trichview.support




Re: How to select a Control by clicking a button


Return to index


Author

Message

Sergey Tkachenko

Posted: 11/14/2004 22:21:54


There is a method SelectControl().


You can look how to implement selecting components when clicking on them in

the Demos\CBuilder\Editors\Editor 1\ demo:



//--------------------------------------------------------------------------

-

// Event: clicking inserted controls

void __fastcall TForm1::OnControlClick(TObject *Sender)

{

  RichViewEdit1->SelectControl((TControl*)Sender);

}

//--------------------------------------------------------------------------

-

// Insert|Component|Button

// (I modified the code for control insertion, because

// in the new version InsertControl() returns a boolean

// value and it's easy to understand if the control was

// inserted)

void __fastcall TForm1::mitButtonCompClick(TObject *Sender)

{

  ...

  TButton* btn = new TButton((TComponent*)NULL);

  ...

  btn->OnClick = OnControlClick;

  if (RichViewEdit1->InsertControl("",btn,rvvaBaseline))

    RichViewEdit1->SetCurrentItemExtraIntProperty(rvepResizable, 1, True);

}

//--------------------------------------------------------------------------

-

void __fastcall TForm1::RichViewEdit1ControlAction(TCustomRichView *Sender,

TRVControlAction ControlAction, int ItemNo, TControl *&ctrl)

{

  if (ControlAction==rvcaAfterRVFLoad)

  {

    ...

    if (ctrl->InheritsFrom(__classid(TButton)))

      ((TButton*)ctrl)->OnClick = OnControlClick;

    else if (ctrl->InheritsFrom(__classid(TEdit)))

      ((TEdit*)ctrl)->OnClick = OnControlClick;

  }

  ...

}






>

> I'd like to select a component by clicking a button. I use the following

code

> for adding a component:

>

> TEdit* edt = new TEdit((TComponent*)NULL);

> edt->Text = "This is a test";

> edt->OnClick = OnControlClick;

> rve->InsertControl("", edt, rvvaBaseline);

> if (rve->CurItemStyle == rvsComponent)

> rve->SetCurrentItemExtraIntProperty(rvepResizable, 1, True);

>

> Thanks.

>

> Pieter E.





Powered by ABC Amber Outlook Express Converter