Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Fine-grained presentational control

Back to Forum: Tech Off
  • User profile image

    With CSS, you can change the appearance of webforms (W3C definition, not ASP.NET) controls.

    Consider this:

    input[type="text"] {
        border-top: 1px solid black;
        border-left: 1px solid white;
        border-right: none;
        border-bottom: none;
        background: #EEE url("CoolBackground.jpg") no-repeat middle left;
        padding: 10px;
        padding-left: 15px;

    This all renders fine in web-browsers that show the controls being all sexy and stuff, but in DotNET, the System.Windows.Forms.TextBox control only has a "BackgroundColor" and "Border" property.

    So how do web-browsers apply all these styles to the standard Common Controls? And how can you do the same in DotNET?

  • User profile image
    Mike Dimmick

    IE does not use standard Windows controls for most of its on-screen controls. Instead, they're windowless ActiveX controls. The exception is the SELECT element, which is a windowed element. That's why you can't overlay text on top of a SELECT in Internet Explorer (e.g. with a popup DHTML menu) - because the parent window isn't allowed to paint over its child.

    The main reason for this is that Windows has a limit on the number of windows it can create. If full control windows were used, Windows would run out of Desktop Heap very quickly. A windowless control simply paints itself (on request) on its parent's window surface.

    These windowless controls are a separate codebase from the Windows controls - therefore it's possible to do much more with them than the standard controls allow.

    Standard controls support a certain amount of styling by sending the WM_CTLCOLOR* family of messages to their parent window. System.Windows.Forms uses this feature (I think!) to support the colouring properties for the controls.

    System.Windows.Forms.TextBox has a BackgroundImage property. To do the border, I think you'd have to set BorderStyle.None or BorderStyle.FixedSingle then overpaint it (by handling the Paint event, or overriding OnPaint).

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.