Click here to Skip to main content
15,881,561 members
Articles / Web Development / ASP.NET

Notes: An MSDN Websites Style Custom Notes Control in ASP.NET and C#

Rate me:
Please Sign up or sign in to vote.
4.76/5 (22 votes)
25 Jan 2008CPOL2 min read 47.7K   214   35  
A Microsoft website style notes control using a web usercontrol in ASP.NET and C#.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.ComponentModel;
[System.ComponentModel.Description("Hello World Demo")]
public partial class NotesControl : System.Web.UI.UserControl
{
  
    private string Txt="Notes";
    private string Desc="Notes Description";
    private Color backColor=System.Drawing.Color.LightGray ;
    private string iPath = "Notes.gif";
    private String notesSize="Medium";
    private int _LineLength = 0;
    public int Result;


    
    #region PropertySet
    //Property for Set Notes Size
    //It either Short, Long or Medium
    public String NotesSize
    {
        
        get
        {
            return notesSize; 
        }
        set
        {
            notesSize = value;
        }
    }
    //Property For Header Text
    public string HeaderText
    {
        get
        {
            return Txt; 
          
        }
        set
        {
            Txt = value;
        }
    }
    //Property For Description
   public string Description
    {
        get
        {
            return Desc ;
        }
        set
        {
            Desc  = value;
        }
    }
    //Property For Backcolor
   public Color BackColor
    {
     get
     {
         return backColor; 
     }
      set
      {
          backColor = value; 
      }
     }
    //Property For ImagePath
    public string imagePath
    {
        get
        {
            return iPath;
        }
        set
        {
            iPath = value;
        }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        //Calculation the Length
         int Factor;
        _LineLength =  Desc.Length;
        switch (notesSize)
        {
             case  "Short":
                Result = _LineLength / 38;
                break;
            case "Medium":
                Result=_LineLength/68;
                break;
            case "Long":
                Result= _LineLength/98;
                break;
        } 

       if (Result == 0)
            Factor = 1;
        else
            Factor = 24 * Result;



        this.Label1.Text = Txt;
        this.Label2.Text = Desc;
        this.Image1.ImageUrl =imagePath; 
        this.Label1.BackColor = backColor; 
        this.Panel1.BackColor = backColor;
        this.Panel1.BorderColor = backColor;
        if (notesSize.Equals("Medium"))
        {
            this.Panel1.Height = 56 + Factor;
            this.Label2.Height = 24 + Factor;
            this.Panel1.Width = 440;
            this.Label1.Width = 422;
            this.Label2.Width = 440;
        }

        if (notesSize.Equals("Short"))
        {
            this.Panel1.Height = 56 + Factor;
            this.Label2.Height = 24+Factor;
            this.Panel1.Width = 240;
            this.Label1.Width = 222;
            this.Label2.Width = 240;
        }
        
        if (notesSize.Equals("Long"))
        {
            this.Panel1.Height = 56 + Factor;
            this.Label2.Height = 24 + Factor;
            this.Panel1.Width = 640;
            this.Label1.Width = 622;
            this.Label2.Width = 640;
        }
     }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
.NET Consultant | Former Microsoft MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author | Speaker | Geek | Blogger | Husband

Blog : http://abhijitjana.net
Web Site : http://dailydotnettips.com
Twitter : @AbhijitJana
My Kinect Book : Kinect for Windows SDK Programming Guide

Comments and Discussions