VB.Net Standard Control Appearance Problems

G

Greg

I am used to using third party controls when it comes to setting up
appearences. But, now I am using Visual Basic.Net controls that come standard
with the product. I've come across a frustration situation with the combo box
and text box controls.

I setup the text box control appearence settings the way I want the control
to appear. Basically, I have set the "Border Style=FixedSingle", which
results in the control taking on a flat appearence and a black border around
the control.

Now, I want to make my combo box take on the same appearence, as I like all
of the controls in my application to take on the same characteristics. Now,
for the combo box I look in the Apperance Group and do not find a "Border
Style" property. The only thing clost to it that I see is the
"FlatStyle=Flat", which makes the combo box control appear flat, but the
border of the control is not highlight with a black border, thus both of my
controls look nothing alike.

Now, I have read some books on VB.Net and if I recall correctly, these
controls inherit from the Control class. I would take this to mean that all
the controls take on the same properties and methods as inherited from the
base control class.

But, what I have found is that both the text box and combo box controls have
different Appearence properties and thus I cannot use a common set of
settings to make the controls look the same, using the same appearance
settings. I come from an Access background, and I always give the controls in
my application the same appearance and it makes my application look very
professional.

How can I make the combo box and text box controls take on the same
appearancees so they look to take on the same Appearance characteristics.

If anyone can help me get these two controls to take on the same appearance
characteristics, that would be greatly appreciated.

Greg
 
J

Joergen Bech

That example would have a few problems in the real world, e.g.

1) It does not enumerate the controls recursively. Only the
controls that are direct children of the form, but not those of
groupboxes, etc.

2) It draws the rectangles on the form, rather than the
textboxes. In other words, the rectangles would be drawn
behind the textboxes. I have not run the sample, but I cannot
see how it could possibly work.

3) If a single pixel of the form background is exposed (i.e.
invalidated by another form moved away from it), all the
textbox borders would be redrawn (or rather, they would not
- see above). If, on the other hand, a textbox on the form
was invalidated (the textbox window - not the value),
nothing would happen, which is the exact opposite of what
is needed.

4) Even if it worked, similar code would have to be written
to handle other control types, i.e. the TypeOf case would
have to be extended.

5) This snippet of code would have to be added to every
form that needed to control its children in this manner.

The correct approach would be to create a "MyTextBox" class
(or whatever) that inherits from TextBox and override some of the
base methods to handle custom drawing and provide properties
for controlling its appearance when dropped on a form.

Regards,

Joergen Bech
 
J

Joergen Bech

While it is true that System.Windows.Forms.TextBox inherits from
System.Windows.TextBoxBase, which in turn inherits from
System.Windows.Forms.Control, the latter does not provide
properties for controlling the appearance of a control.

The Control class provides a common set of methods and
properties for creating, destroying, sizing, etc. a Windows
control, as well as handling keyboard and mouse inputs.

Most of the stuff is abstract, though, and inherited classes
override many of these in order to handle whatever control
they are wrapping.

In many cases, the controls seen in the .Net toolbox are
wrappers around standard Win32 controls and their appearances
are often at the mercy of the operating system settings.
They were not handwritten from the ground up for the .Net
framework.

Often it requires a great deal of work at the message level to
coerce such controls into a common theme.

Unless you just need to fix a single control, rolling your own is
way too much work. Even if you do decide to do it on your own,
you might run into trouble when you run your app on a differently
themed Windows installation unless you are prepared to customize
*every* control you work with.

Instead of trying to make one control look like the other,
you would probably be better off by either

1) leave the appearance entirely up to the operating system, i.e.
leave all settings related to appearance at their default values, or

2) buy/use a suite of controls (e.g. Infragistics NetAdvantage) that
provide a large toolbox of controls utilizing common appearance
properties across all controls.

Regards,

Joergen Bech
 
C

Cor Ligthert[MVP]

Joergen,

It is only meant to show that it can be done.

For the rest, I completely agree with you about this and your other message
in this thread.

I don't think that I can add something to that.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top