Click here to Skip to main content
16,015,097 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Code Comments Pin
Neil Van Note18-Apr-02 19:06
Neil Van Note18-Apr-02 19:06 
GeneralRe: C# Code Comments Pin
Patrick John Collins18-Apr-02 21:32
Patrick John Collins18-Apr-02 21:32 
GeneralOutlookBar Pin
BLaZiNiX17-Apr-02 18:05
BLaZiNiX17-Apr-02 18:05 
GeneralRe: OutlookBar Pin
James T. Johnson17-Apr-02 18:16
James T. Johnson17-Apr-02 18:16 
GeneralRe: OutlookBar Pin
BLaZiNiX17-Apr-02 18:25
BLaZiNiX17-Apr-02 18:25 
GeneralRe: OutlookBar Pin
James T. Johnson17-Apr-02 18:36
James T. Johnson17-Apr-02 18:36 
GeneralRe: OutlookBar Pin
BLaZiNiX17-Apr-02 18:46
BLaZiNiX17-Apr-02 18:46 
GeneralRe: OutlookBar Pin
James T. Johnson17-Apr-02 19:03
James T. Johnson17-Apr-02 19:03 
To create your own control simply create a new class and derive from System.Windows.Forms.Control; or in VS.NET choose to add a new item and choose Custom Control from the box.

You can then handle the events you want (overriding OnPaint is going to be one of them Smile | :) )

Here's a simple control that creates a very lightweight label

using System;
using System.Drawing;
using System.Windows.Forms;

public class LightLabel : System.Windows.Forms.Control
{
  public LightLabel() : base()
  { 
    // Nothing to set here
  }
 
  public override void OnPaint(PaintEventArgs e)
  {
    Brush textBrush = new SolidBrush(ForeColor);
    Brush background = new SolidBrush(BackColor);
    
    Graphics g = e.Graphics;
    
    g.FillRectangle(background, Bounds);
    g.DrawString(Text, Font, textBrush, Bounds);
 
    textBrush.Dispose();
    background.Dispose();
  }
}
I didn't actually compile the code but that is the general idea behind creating your own control. You'll also want to look at the ControlPaint class for lots of cool drawing effects you find on controls (the etched border, drawing a 'disabled' image, etc).

If you want to get really fancy with your control you'll need to look at Designers which is something I haven't looked at in-depth yet.

James

Simplicity Rules!
GeneralRe: OutlookBar Pin
Ben Kloosterman17-Apr-02 18:48
Ben Kloosterman17-Apr-02 18:48 
GeneralDataSet: no MoveNext or any indexing at all Pin
17-Apr-02 10:38
suss17-Apr-02 10:38 
GeneralRe: DataSet: no MoveNext or any indexing at all Pin
James T. Johnson17-Apr-02 11:51
James T. Johnson17-Apr-02 11:51 
GeneralRe: DataSet: no MoveNext or any indexing at all Pin
18-Apr-02 4:34
suss18-Apr-02 4:34 
QuestionSaving class instance to file?? Pin
HG17-Apr-02 9:41
HG17-Apr-02 9:41 
AnswerRe: Saving class instance to file?? Pin
James T. Johnson17-Apr-02 11:43
James T. Johnson17-Apr-02 11:43 
GeneralLogicalDrives Pin
Mazdak17-Apr-02 9:32
Mazdak17-Apr-02 9:32 
GeneralRe: LogicalDrives Pin
Nick Parker17-Apr-02 9:57
protectorNick Parker17-Apr-02 9:57 
GeneralRe: LogicalDrives Pin
Mazdak18-Apr-02 5:21
Mazdak18-Apr-02 5:21 
GeneralFileAttribute Pin
Mazdak17-Apr-02 8:05
Mazdak17-Apr-02 8:05 
GeneralRe: FileAttribute Pin
James T. Johnson17-Apr-02 12:43
James T. Johnson17-Apr-02 12:43 
GeneralRe: FileAttribute Pin
Mazdak18-Apr-02 5:22
Mazdak18-Apr-02 5:22 
QuestionF1 Help? Pin
Neo Anderson17-Apr-02 6:28
Neo Anderson17-Apr-02 6:28 
AnswerRe: F1 Help? Pin
James T. Johnson17-Apr-02 15:00
James T. Johnson17-Apr-02 15:00 
GeneralAVI Pin
17-Apr-02 5:29
suss17-Apr-02 5:29 
GeneralRe: AVI Pin
James T. Johnson17-Apr-02 16:38
James T. Johnson17-Apr-02 16:38 
GeneralRe: AVI Pin
Mike Nordell17-Apr-02 17:35
Mike Nordell17-Apr-02 17:35 

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.