How to make Control interact with Toolbar?

  • Thread starter Thread starter Jason Yu
  • Start date Start date
J

Jason Yu

Hi,


this problem looks quite simple but it has bugged me for several days, and i
just can't get out of it.

i have a custom Control on a Form, and the Form has a Toolbar as well. when
user clicks on the Control, the Toolbar appears; when user's focus left the
Control, the Toolbar disappears. it's something like in MS Word when you
select an embedded Picture, a Drawing Toolbar will appear and when you
disselect it, the toolbar disappears.

The difficulty is, in my case the Toolbar button states are determined by
one of the Property of the Control, say if the Property is set to "True"
then one button will appear in the Toolbar and vice versa.

since the Control and the Toolbar are from two different classes, so how do
they interact with each other? i want to get property information of the
Control from Toolbar class and get property information of the Toolbar from
the Control class.
Is there any standard way to handle this cross-class issue? I have searched
this on web but didnt get any piece of information on it.


Appreciate any light that can be shed on this subject.


Thanks.

Jason Yu
 
There is, you must create 2 inherited classes one, the
custom control and the other one the toolbar, let's call
them CustomControlEx and ToolbarEx. Then in the custom
control define a field/property of type ToolBarEx and in
the Toolbarex class define a field/property of type
CustomControlEx. Decide which of the controls must be
created first and on the other one force a parameter on
the constructor. For example:

mycontrol = new CustomControlEx();

then, in the custom control constructor you do:

this.mytoolbar = new ToolBarEx(this);

then in the toolbar constructor you do:

public ToolBarEx(CustomControlEx control) : base()
{
this.mycontrol = control;
}

So, now, from inside the control you can access the
toolbar using the mytoolbar field and from inside the
toolbar you can access the control through the mycontrol
field...

I hope this helped...
 
Hi Iulian,

Thanks for the excellent solution, it's awesome :)
It is exactly what i want to know. i will try out your way now and maybe get
some feedback in a couple of hours

Cheers,
Jason Yu
 
Back
Top