My former blog at Atozed

These are the posts I've made during 2004 while working for Atozed Software. They are here to serve as an archive, comments have beed stripped and some links may be invalid.

New toy
Moooooooo
See the cow ?
Romanian programmers
FoxPro
Bad work conditions
Amazement
Made in Borland?
In stores now!!!
rome.ro
Having fun?
Haiku
Tech*Ed, Day -1
Tech*Ed, Day 0
Tech*Ed, Day 1
Tech*Ed, Day 2
Tech*Ed, Day 3
The Codezone party
Tech*Ed, Day 4 (and last)
C++
Everybody and his brother is a 'web programmer'
Communism
(.NET) Intraweb components!!!
Firefox surprise
Intraweb for Cω?
Free license!!!
TurboPower
What to blog about, what to share?
A programmer's mind....
Three awards to Atozed!!!!
More recognition
Intraweb Review
All your base are belong to us?
Something's cooking
Usenet archive
The romanian's worst enemy
Underwater
One date to rule them all
X Prize
Intraweb for Lego Mindstorms
H2?
Addicted to net
Earthquake!
How to write a custom Intraweb component using C#
How to customize the Intraweb error page
A smart idea and a bad one
On technical support
Worst possible Internet service provider
XPrize reloaded
Security advisors shooting contest
Nice CodeFez article
Internetless
The day the hypocrisy ends
The Bat is dead, long live Thunderbird!
Impressive. Most impressive.
My idea for a stupid game
Random thought of the day
Are you a Frank Herbert's fan ?
A new way or an old one?
Uninspired names and intercultural fun
Illiteracy in the 21st century
How to write a custom Intraweb component using C#


As this doesn't seem to have made it to the manual, here's an article on how to write a custom Intraweb component using Visual Studio and Intraweb for ASP.NET.


This will eventually make its way into the documentation, but with so much work to do documentation is the last one to get touched and reviewed.

In this example I create a class library ("package" for the Delphi crowd) named "CustomLabels" with one component named "MarqueeLabel". The MarqueeLabel will simply be a label that scrolls horizontally. The HTML element used is "MARQUEE".

In order to have this done, we have to make two important things:

  1. Create a class library
    • New -> Class library -> specify a name (CustomLabels) (This will create a library that packages our custom components.)
  2. Code the control
    • Rename Class1.cs to custom name (MarqueeLabel). Rename the constructor as well.
    • Add Atozed.Intraweb.dll to References (Yes, you have to have Intraweb for ASP.NET installed.)
    • Make the class inherit from Atozed.Intraweb.CompLabel.CustomLabel (The CustomLabel already has most of the properties we need for our label, so there's no point in inheriting from a more basic control)
    • Overwrite RenderHTML (RenderHTML is the procedure the engine calls everytime the component has to generate its HTML code. Whatever you make RenderHTML output will be sent to the user's browser)
    • Expose some of the CustomLabel's properties
    • Add some new properties (marquee direction, speed and scroll amount)


Notes:
- the Browsable attribute must be explicitely set to true for properties reintroduced with 'new'
- the ToolboxItem attribute must be set explicitely to true as well, otherwise the component won't appear in the toolbox

Credits go to Gabriel who's been my personal MSDN and Christina who listened to all I had to say about C# (nothing good). Go ahead and ask Gabriel if you have any questions on .NET, he really knows the stuff. Don't send bad comments to Christina though, use your own wives, girlfriends etc.

Any comments are welcome. In the future there will be a VB.NET example and an example on how to do custom design time painting for the components.


Here's the code (MarqueeLabel.cs):
using System;
using System.Drawing.Design;
using System.ComponentModel;

namespace CustomLabels
{

        public enum MarqueeDirection {mdLeft, mdRight};
        public enum MarqueeBehavior {mbScroll, mbSlide, mbAlternate};

        /// 
        /// Summary description for Class1.
        /// 
        

        [ToolboxItem(true)]
        public class MarqueeLabel : Atozed.Intraweb.CompLabel.CustomLabel
        {
        
                [Browsable(true)]
                new public string Text 
                {
                        get
                        {
                                return base.Text;
                        }
                        set
                        {       
                                base.Text = value;
                        }
                }

                [Browsable(true)]
                new public bool RawText
                {
                        get
                        {
                                return base.RawText;
                        }
                        set
                        {       
                                base.RawText = value;
                        }
                }       

                private MarqueeDirection FDirection = MarqueeDirection.mdLeft;
                public MarqueeDirection Direction
                {
                        get
                        {
                                return FDirection;
                        }
                        set
                        {
                                FDirection = value;
                        }
                }

                private MarqueeBehavior FBehavior = MarqueeBehavior.mbScroll;
                public MarqueeBehavior Behavior
                {
                        get
                        {
                                return FBehavior;
                        }
                        set
                        {
                                FBehavior = value;
                        }
                }

                private int FDelay = 85;
                public int Delay
                {
                        get
                        {
                                return FDelay;
                        }
                        set 
                        {
                                FDelay = value;
                        }
                }

                private int FScrollAmount = 6;
                public int ScrollAmount
                {
                        get
                        {
                                return FScrollAmount;
                        }
                        set 
                        {
                                FScrollAmount = value;
                        }
                }
                
                public MarqueeLabel()
                {
                        //
                        // TODO: Add constructor logic here
                        //
                }

                public override Atozed.Intraweb.HTMLTagUnit.HTMLTag RenderHTML (Atozed.Intraweb.RenderContext.BaseHTMLComponentContext AContext)
                {
                        Atozed.Intraweb.HTMLTagUnit.HTMLTag Result = new Atozed.Intraweb.HTMLTagUnit.HTMLTag(null);
                        Result.ClosingTag = Atozed.Intraweb.MarkupLanguageTagUnit.CloseTag.cbTrue;
                        Result.Tag = "marquee";

                        string LText;

                        if (RawText)
                                LText = Text;
                        else
                                LText = TextToHTML(null, Text, true, true);

                        Result.Contents.AddText(LText, false);

                        if (WebColor != System.Drawing.Color.Empty)
                                Result.AddStringParam("BGCOLOR", Atozed.Intraweb.ColorUnit.Unit.ColorToRGBString(WebColor));

                        Result.AddIntegerParam("DELAY", FDelay);
                        Result.AddIntegerParam("SCROLLAMOUNT", FScrollAmount);

                        if (FDirection == MarqueeDirection.mdLeft)
                                Result.AddStringParam("DIRECTION", "LEFT");
                        else
                                Result.AddStringParam("DIRECTION", "RIGHT");

                        switch (FBehavior)
                        {
                                case MarqueeBehavior.mbScroll:
                                {
                                        Result.AddStringParam("BEHAVIOR", "SCROLL");
                                        break;
                                }
                                case MarqueeBehavior.mbSlide:
                                {
                                        Result.AddStringParam("BEHAVIOR", "SLIDE");
                                        break;
                                }
                                case MarqueeBehavior.mbAlternate:
                                {
                                        Result.AddStringParam("BEHAVIOR", "ALTERNATE");
                                        break;
                                }
                        }

                        return Result;
                }
        }
}