Composite controls in CF/ VB.Net how?

  • Thread starter Thread starter germanwbauer
  • Start date Start date
G

germanwbauer

Hi:

I could not find it in the newsgroup's archives, I am looking for one
or more articles on how to assemble a composite control made of more
then one CF control, in my case a composite of a label and a text edit
box. I do not need to have design time support, as i can probably add
one of these controls to a form later from VB.NET form code right?

I would prefer VB.NET, but can translate C# if needed.

Any links or hints are very appreciated, as I am a beginner to .NET.
Thanks,
German
 
You might start by simply declaring a new class which inherits from Control.
You can then add some instance variables representing the controls which
will work together to give you the behavior you want. You'll then need to
declare any new properties that you want to make available to your users,
etc.

Yes, to add an instance of your 'control', you'll have to create it
explicitly in code.

You might look at some of the OpenNETCF controls, which *do* have designer
support but which are not really composites, in most cases.
www.opennetcf.org

By the way, a composite control is *not* a particularly good first project
for a newbie. Given that all you want is a text box and a label, why not
just use them separately?

Paul T.
 
Thanks, I did get the composite control working using the approach you
suggested. Along the way I found out that there does not seem to be a
way to dynamically create an array of same composite controls on a
form.
One thing that stumps me though is how to bubble up events from the
controls that make up the composite:
For example I have set up such that when the composite control
received focus it passes it on to it's textbox child control so the
user can start typing in right way. I not yet found a way to redirect
up/down arrow events to mean "go to the previous/next composite
control", it seems stuck in the text box. Is there a way to do pass
the event back to the parent or even the containing form so that when
the user presses "down", focus goes to the next control below.

Any clues much appreciated!
+ G
 
That sounds like a function that your form would want to be responsible for
catching. You might add an event to your composite control which would be
something like Down or Up or ArrowKey (or KeyPress or whatever). That might
be declared like this:

public event EventHandler ArrowKey;

The form would then add event handlers to each of the instances of your
control that it creates. When one of them detects the arrow key, it would
fire the event to all interested parties with code something like this:

ArrowKey(this, EventArgs.Empty);

Although you'd probably pass some arguments...

Paul T.

Thanks, I did get the composite control working using the approach you
suggested. Along the way I found out that there does not seem to be a
way to dynamically create an array of same composite controls on a
form.
One thing that stumps me though is how to bubble up events from the
controls that make up the composite:
For example I have set up such that when the composite control
received focus it passes it on to it's textbox child control so the
user can start typing in right way. I not yet found a way to redirect
up/down arrow events to mean "go to the previous/next composite
control", it seems stuck in the text box. Is there a way to do pass
the event back to the parent or even the containing form so that when
the user presses "down", focus goes to the next control below.

Any clues much appreciated!
+ G

"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> wrote in
message news: said:
You might start by simply declaring a new class which inherits from Control.
You can then add some instance variables representing the controls which
will work together to give you the behavior you want. You'll then need to
declare any new properties that you want to make available to your users,
etc.

Yes, to add an instance of your 'control', you'll have to create it
explicitly in code.

You might look at some of the OpenNETCF controls, which *do* have designer
support but which are not really composites, in most cases.
www.opennetcf.org
 
Back
Top