Discussion:
Embedded controls are "alive" during design time
(too old to reply)
r***@gmail.com
2007-04-06 17:43:20 UTC
Permalink
I have a problem that I believe is related to KB839202, but I am more
looking for some sort of work-around, as it appears this is something
Microsoft simply cannot (or will not) fix.

I am building a custom user control that embeds several SWF TextBox
controls onto a scrolling panel. The number of controls need to be
embedded on the control starts out at 3 (the default) but can be
changed by setting NumberOfVisibleInstances Property to a higher or
lower value. I also have an Expanded property that removes the panel
and all textboxes from the control if set to false, and puts them all
back when set to true.

So far, visually, the control seems to work great, it appears
correctly when initially dropped on a design surface, and will appear
correctly in all cases when two properties are changed. However, I am
seeing a very strange behavior if I follow these steps:

1. Drop the control onto a design surface
2. Set Expanded to false (removes panel and all text boxes)
3. Set Expanded back to true (adds panel back and all text boxes)

Now if I hover a mouse over one of the textboxes on my control I don't
get the move cursor. Instead I get an I-Beam cursor. If I click on
the text box, the cursor is placed inside the textbox, and if I type,
the textbox shows the characters I am typing. In short, my control is
active as if it were in run-time. Note that after step 1, even though
I still have panel with three textboxes on it, that the control does
not behave that way. It only behaves that way after I remove the
panel and then re-add it.

I did check the Site property of the Panel and all the TextBox
controls, and sure enough, the Site was null (and so design mode
reports false). I did try setting the Site on the panel and the
textbox controls (so design mode now reports true), but the behavior
above still exists - I still get an I-Beam cursor, I can still click
into the textbox, and I can still enter text into the text box.

All I am really looking for here is a work-around in designmode where
textboxes still look like textboxes. I can set the text boxes to read-
only or enabled=false, but both of these change the textbox so the
backcolor is the same as the color of the panel behind it, and the
textboxes disappear. So far the only hack that I've found that
actually works well is to disable the textbox control and set its
backcolor to white in design mode. But that seems like an unseemly
hack. Does anyone have a more elegant solution?

Thanks for any help you can give.
Bryan Phillips
2007-04-07 02:25:39 UTC
Permalink
What did you set the Site property to? I believe that you should set it
to the same value as the outermost hosted control's Site property.

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net
Post by r***@gmail.com
I have a problem that I believe is related to KB839202, but I am more
looking for some sort of work-around, as it appears this is something
Microsoft simply cannot (or will not) fix.
I am building a custom user control that embeds several SWF TextBox
controls onto a scrolling panel. The number of controls need to be
embedded on the control starts out at 3 (the default) but can be
changed by setting NumberOfVisibleInstances Property to a higher or
lower value. I also have an Expanded property that removes the panel
and all textboxes from the control if set to false, and puts them all
back when set to true.
So far, visually, the control seems to work great, it appears
correctly when initially dropped on a design surface, and will appear
correctly in all cases when two properties are changed. However, I am
1. Drop the control onto a design surface
2. Set Expanded to false (removes panel and all text boxes)
3. Set Expanded back to true (adds panel back and all text boxes)
Now if I hover a mouse over one of the textboxes on my control I don't
get the move cursor. Instead I get an I-Beam cursor. If I click on
the text box, the cursor is placed inside the textbox, and if I type,
the textbox shows the characters I am typing. In short, my control is
active as if it were in run-time. Note that after step 1, even though
I still have panel with three textboxes on it, that the control does
not behave that way. It only behaves that way after I remove the
panel and then re-add it.
I did check the Site property of the Panel and all the TextBox
controls, and sure enough, the Site was null (and so design mode
reports false). I did try setting the Site on the panel and the
textbox controls (so design mode now reports true), but the behavior
above still exists - I still get an I-Beam cursor, I can still click
into the textbox, and I can still enter text into the text box.
All I am really looking for here is a work-around in designmode where
textboxes still look like textboxes. I can set the text boxes to read-
only or enabled=false, but both of these change the textbox so the
backcolor is the same as the color of the panel behind it, and the
textboxes disappear. So far the only hack that I've found that
actually works well is to disable the textbox control and set its
backcolor to white in design mode. But that seems like an unseemly
hack. Does anyone have a more elegant solution?
Thanks for any help you can give.
r***@gmail.com
2007-04-07 14:22:42 UTC
Permalink
Bryan,
Thanks for the response. Yes - I did set the Site property to the
same value as the outermost controls Site property. This had some
interesting effects. Firstly, it did not fix my problem, in design
time, the text boxes still appeared "alive". Secondly, it gave the
"DesignerSerialization" code fits. In the form.designer.cs, for the
form I had dropped my control into, it caused the "measurementWidget1"
variable to be defined multiple times all at once - the first time as
my control type, the next time as a panel, and three subsequent times
as text boxes. It also dumped all over the form's
InitializeComponents causing the "measurementWidget1" variable to be
newed multiple times (once as my widget, once as panel, and three
more times as a textbox). Needless to say, once I had finished my
design session, my Form1.cs class was a complete mess and could not
even compile.

So I figured that setting the Site property might be bad, so I figured
maybe I should cause the internal controls to be sited by creating
them using the IDesignerHost.CreateComponent method. So whenever I
needed to create any control within my control, (for instance, my
scrolling Panel) I did the following:

Panel scrollPanel = null;
IDesignerHost host = this.Container as IDesignerHost;
if (host != null)
{
scrollPanel = host.CreateComponent(typeof(Panel)) as Panel;
}
else
{
scrollPanel = new Panel();
}

// initialize Panel here
this.Controls.Add(scrollPanel);

I did something similar with all my TextBoxes as well. This had an
even stranger effect (if you can believe it). It caused all of the
internal bits of my control to be individually selectable withing the
designer. The were no longer "alive", but it now allowed me to clink
on an individual TextBox within my Control, and it even showed me the
correct properties for that TextBox. So. when I dropped my composite
widget on the form, I could individually select each TextBox on the
widget, and set any of its properties, or even move them around.
This, even though the TextBoxes are private to my control. And
whatever I did to my internal TextBoxes while designing my Form (for
instance set the back color purple) the changes would "stick" and
appear in run time. In this case, the DesignerSerialization code new
exactly what to do. This is very cool, actually, but not at all the
behavior I am looking for. I want my composite control to appear as a
single control, not as a "loose collection" of controls.

Anyway, getting the Site property right does not seem to be my
problem. Apparently, it is just a no-no to add additional controls to
your Controls list at Design time. Can anyone verify this? It seems
ike a pretty strange restriction.

On Apr 6, 10:25 pm, "Bryan Phillips"
Post by Bryan Phillips
What did you set the Site property to? I believe that you should set it
to the same value as the outermost hosted control's Site property.
--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net
Loading...