Um.
You need to understand what a
using
block does:
It provides a scope for a variable and automatically calls Dispose on that variable's content when control leaves the block by whatever method.
So when you do this:
using (var tb = control as ComboBox)
You are saying "use this existing Control instance, and destroy it when I'm finished.
So the system does just that: your existing Control on the form releases all its resources - including it's Window handle and related information - when you leave the block.
And of course, that means it isn't a Control anymore, and it vanishes.
Only use
using
blocks with
new
class instances.
And if you use
if (a is B)
then you should just cast teh instance, not use
as
as well - as has to do an
is
test itself to check the cast so you are just repeating work!
ComboBox cb = control as ComboBox;
if (cb != null)
{
...
Is fine, and so is
if (control is ComboBox)
{
ComboBox cb = (ComboBox) control;
...
But using both is inefficient.