Click here to Skip to main content
15,892,537 members
Articles / Web Development / ASP.NET
Article

WebBoxes

Rate me:
Please Sign up or sign in to vote.
4.38/5 (21 votes)
13 Mar 20032 min read 198.1K   1.3K   71   32
Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support. If you can FTP to your site, then the fonts are usable, no admin rights required.

Sample Image - screenshot.gif

Introduction

A while back I had a conversation with Paul Watson, telling him how nice rounded corners are in display "boxes". So a few days back I started working on what you see here. I also wanted some funky features like collapsibility, and font support that does not rely on installed fonts on the web server. The control consists of 2 parts:

  • The CollapsableControl with designer support.
  • Image.aspx a.k.a. the "graphics server"

The CollapsableControl

This control is nothing more than a table that acts as a front-end to the graphics server. It also acts as a container for child controls. Basically, the control requests graphics for certain parts of it.

The graphics server

This is a code-behind version of Nick Parker's ASP.NET article, but has been modified to accept parameters in the form of a query string. For example:

HTML
<img src="Image.aspx?type=UpArrow&width=20&height=20&
                           forecolor=Black&backcolor=DodgerBlue">

This will create an UpArrow image and display it (as an image).

Points of interest

Using fonts from the web directory

C#
static void InitPF(string path) 
{ 
  pf = new PrivateFontCollection(); 
  string[] ttfs = Directory.GetFiles(path, "*.ttf"); 
  for (int i = 0; i < ttfs.Length; i++) 
  { 
    pf.AddFontFile(ttfs[i]); 
  } 
} 

static PrivateFontCollection pf;

Just pass Server.MapPath("") from the page to get the path. Note: this has to be static, else there will be serious side effects on the web server.

Why PNG?

This is the only solution at this stage. But even PNG has it problems in GDI+. I find colors are darker than there CSS counterpart, and thus the header and footer are both images. Also, transparency does not work in IE6. GIF is also a problem in the sense that:

  1. You need licensing, and
  2. I am yet to find a way to make adaptive palette transparent GIF in .NET.

JPEG, is just a big NO-NO for its size/quality cost.

Sending a PNG file to a non-seekable Stream (such as Response.OutputStream)

C#
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, ImageFormat.Png);
byte[] msar = ms.ToArray();
Response.OutputStream.Write(msar, 0, msar.Length);
ms.Close();

Showcase site

Notes and problems

  • Changing properties of the CollapsableControl in the VS.NET designer will blatantly delete all the child controls of the control. Tip (as Paul will second me): DON'T USE IT (to set properties, set them via HTML).
  • Content does not display in VS.NET designer. Not sure if above has something to do with this. Everything else is rendered correctly.

Usage and installation instructions are in the readme file.

Enjoy :)

Updates

  • 0.5
    • Added Showcase site :) There you can see WebBoxes in DataLists, outside DataLists, etc. Also have a derived menu control. The whole site's images are generated, except for 4 photos and the logo. Comments welcome as always.
  • 0.4
    • Fixed support for most browsers. IE5+, Mozilla 1.1+, Netscape 6.2+ . Mozilla based browsers shows the hand (pointer) cursor now. Thanks Daniel Cazzulino :).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralChrome Pin
Dmitri Nеstеruk18-Nov-08 6:13
Dmitri Nеstеruk18-Nov-08 6:13 
GeneralBackground Color Pin
nanishta14-Apr-05 15:27
nanishta14-Apr-05 15:27 
GeneralHelp.... Pin
enjoycrack6-Dec-04 1:11
enjoycrack6-Dec-04 1:11 
Generalvb.net....I know, I know Pin
Michael J. Collins10-Sep-03 10:48
professionalMichael J. Collins10-Sep-03 10:48 
GeneralAlways the right size Pin
hansharro28-Jul-03 14:25
hansharro28-Jul-03 14:25 
GeneralRe: Always the right size Pin
leppie4-Jan-04 11:05
leppie4-Jan-04 11:05 
GeneralBetter solution for background color issue Pin
Christian Tratz20-Dec-02 3:17
Christian Tratz20-Dec-02 3:17 
GeneralRe: Better solution for background color issue Pin
leppie5-Jul-03 20:21
leppie5-Jul-03 20:21 
GeneralGarbage Friendly Pin
Esteves17-Dec-02 12:33
Esteves17-Dec-02 12:33 
GeneralRe: Garbage Friendly Pin
leppie18-Dec-02 4:14
leppie18-Dec-02 4:14 
GeneralUsing td to reduce size of image Pin
alper17-Dec-02 1:14
alper17-Dec-02 1:14 
GeneralRe: Using td to reduce size of image Pin
leppie17-Dec-02 6:14
leppie17-Dec-02 6:14 
GeneralIt doesn't work on Mozilla/NS Pin
Daniel Cazzulino [XML MVP]15-Dec-02 16:31
Daniel Cazzulino [XML MVP]15-Dec-02 16:31 
GeneralRe: It doesn't work on Mozilla/NS Pin
David Stone15-Dec-02 18:52
sitebuilderDavid Stone15-Dec-02 18:52 
GeneralRe: It doesn't work on Mozilla/NS Pin
Daniel Cazzulino [XML MVP]16-Dec-02 1:12
Daniel Cazzulino [XML MVP]16-Dec-02 1:12 
GeneralRe: It doesn't work on Mozilla/NS Pin
Kannan Kalyanaraman20-Dec-02 18:41
Kannan Kalyanaraman20-Dec-02 18:41 
GeneralRe: It doesn't work on Mozilla/NS Pin
Daniel Cazzulino [XML MVP]21-Dec-02 7:39
Daniel Cazzulino [XML MVP]21-Dec-02 7:39 
GeneralRe: It doesn't work on Mozilla/NS Pin
Zathrus13-Jan-03 8:01
Zathrus13-Jan-03 8:01 
GeneralRe: It doesn't work on Mozilla/NS Pin
Zathrus13-Jan-03 7:59
Zathrus13-Jan-03 7:59 
GeneralRe: It doesn't work on Mozilla/NS Pin
leppie16-Dec-02 6:22
leppie16-Dec-02 6:22 
GeneralRe: It doesn't work on Mozilla/NS Pin
Daniel Cazzulino [XML MVP]16-Dec-02 8:16
Daniel Cazzulino [XML MVP]16-Dec-02 8:16 
GeneralRe: It doesn't work on Mozilla/NS Pin
leppie16-Dec-02 10:23
leppie16-Dec-02 10:23 
GeneralRe: It doesn't work on Mozilla/NS Pin
Anonymous13-Mar-04 14:39
Anonymous13-Mar-04 14:39 
GeneralRe: It doesn't work on Mozilla/NS Pin
Daniel Cazzulino [XML MVP]14-Mar-04 18:04
Daniel Cazzulino [XML MVP]14-Mar-04 18:04 
The author of this article himself has recognized that fixing the non-working stuff was a trivial thing. I can only infer that you didn't take the time to compare the effort required to make W3C DOM vs MS DOM, which for the most part (in my experience) involves replacing document.all with document.getElementById. Can you tell me what's the terrible complicated thing about the W3C DOM?! It's almost equal to MS's, but all browsers implement it, INCLUDING IE.
So, what's the big issue with standards? Just follow them and you get broader audience, and a sort of future proff product: for example, MS will not release any more IEs in the future. So what? If you developed standards compliant sites, you don't have to worry at all. Tell your customer MS doesn't want to make browsers anymore, but that your app will continue to work in any other browser as well.
If you didn't do that, you will have to tell your customer that you need to make major rewrites or migrate the whole thing to the latest new ultra-cool idea MS decided you should use. I'd say you would lose a customer that way...

Daniel Cazzulino
My Weblog

Books:
Beg. C# Web Apps
ASP.NET Components Toolkit
Beg. Web Programming w/VB.NET & VS.NET
Pro ASP.NET Server Controls
Generalnice, but... Pin
stefan b11-Dec-02 9:41
stefan b11-Dec-02 9:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.