Click here to Skip to main content
15,890,399 members
Home / Discussions / C#
   

C#

 
GeneralRe: String implementation in .NET Framework Pin
DaveyM694-Nov-08 5:32
professionalDaveyM694-Nov-08 5:32 
AnswerRe: String implementation in .NET Framework Pin
PIEBALDconsult4-Nov-08 4:34
mvePIEBALDconsult4-Nov-08 4:34 
GeneralRe: String implementation in .NET Framework Pin
J4amieC4-Nov-08 5:28
J4amieC4-Nov-08 5:28 
QuestionHow to create my own button [usercontrol? or what?] Pin
Matjaz-xyz4-Nov-08 2:34
Matjaz-xyz4-Nov-08 2:34 
AnswerRe: How to create my own button [usercontrol? or what?] Pin
cyber-drugs4-Nov-08 3:34
cyber-drugs4-Nov-08 3:34 
GeneralRe: How to create my own button [usercontrol? or what?] Pin
Matjaz-xyz4-Nov-08 3:41
Matjaz-xyz4-Nov-08 3:41 
GeneralRe: How to create my own button [usercontrol? or what?] Pin
cyber-drugs4-Nov-08 3:54
cyber-drugs4-Nov-08 3:54 
AnswerRe: How to create my own button [usercontrol? or what?] [modified] Pin
DaveyM694-Nov-08 3:47
professionalDaveyM694-Nov-08 3:47 
you don't really need a button - just derive from Control and have an Availability property, override OnClick to set the availability and OnPaint to do the painting.

A very rough mockup to get you started:
using System;
using System.Drawing;
using System.Windows.Forms;

namespace MyControls
{
    public enum Availability
    {
        Available,
        Unavailable,
        Selected,
    }
    public class TriColorButton : Control
    {
        public event EventHandler AvailabilityChanged;
        private Availability availability;
        public Availability Availability
        {
            get { return availability; }
            set
            {
                if (availability != value)
                {
                    availability = value;
                    OnAvailabilityChanged(EventArgs.Empty);
                }
            }
        }
        protected virtual void OnAvailabilityChanged(EventArgs e)
        {
            Invalidate();
            EventHandler handler = AvailabilityChanged;
            if (handler != null)
                AvailabilityChanged(this, e);
        }
        protected override void OnClick(EventArgs e)
        {
            if (availability == Availability.Available)
                Availability = Availability.Selected;
            else if (availability == Availability.Selected)
                Availability = Availability.Available;
            base.OnClick(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            switch (availability)
            {
                case Availability.Unavailable:
                    e.Graphics.FillRectangle(Brushes.Red, e.ClipRectangle);
                    break;
                case Availability.Selected:
                    e.Graphics.FillRectangle(Brushes.Green, e.ClipRectangle);
                    break;
                default:
                    e.Graphics.FillRectangle(Brushes.Blue, e.ClipRectangle);
                    break;
            }
            base.OnPaint(e);
        }
    }
}

[edit]forgot the event keyword! Blush | :O [/edit]

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

modified on Tuesday, November 4, 2008 9:59 AM

QuestionHow do display a form in a seperate thread Pin
EliottA4-Nov-08 2:27
EliottA4-Nov-08 2:27 
AnswerRe: How do display a form in a seperate thread Pin
dybs4-Nov-08 2:41
dybs4-Nov-08 2:41 
AnswerRe: How do display a form in a seperate thread Pin
Dave Kreskowiak4-Nov-08 3:35
mveDave Kreskowiak4-Nov-08 3:35 
GeneralRe: How do display a form in a seperate thread Pin
EliottA4-Nov-08 5:21
EliottA4-Nov-08 5:21 
GeneralRe: How do display a form in a seperate thread Pin
Dave Kreskowiak4-Nov-08 5:55
mveDave Kreskowiak4-Nov-08 5:55 
QuestionHow to read End of Line in C# Pin
Miss_hacker4-Nov-08 2:19
Miss_hacker4-Nov-08 2:19 
AnswerRe: How to read End of Line in C# Pin
#realJSOP4-Nov-08 2:22
mve#realJSOP4-Nov-08 2:22 
GeneralRe: How to read End of Line in C# Pin
Ashfield4-Nov-08 2:42
Ashfield4-Nov-08 2:42 
GeneralRe: How to read End of Line in C# Pin
CPallini4-Nov-08 9:37
mveCPallini4-Nov-08 9:37 
QuestionComparing excel data to XML Pin
ndroo8824-Nov-08 0:55
ndroo8824-Nov-08 0:55 
AnswerRe: Comparing excel data to XML Pin
Mircea Puiu4-Nov-08 1:03
Mircea Puiu4-Nov-08 1:03 
GeneralRe: Comparing excel data to XML Pin
ndroo8824-Nov-08 3:09
ndroo8824-Nov-08 3:09 
GeneralRe: Comparing excel data to XML Pin
Mircea Puiu4-Nov-08 4:26
Mircea Puiu4-Nov-08 4:26 
QuestionExiting Windows Application (from the main form constructor) Pin
Dirso4-Nov-08 0:46
Dirso4-Nov-08 0:46 
AnswerRe: Exiting Windows Application (from the main form constructor) Pin
DanB19834-Nov-08 0:50
DanB19834-Nov-08 0:50 
AnswerRe: Exiting Windows Application (from the main form constructor) Pin
User 66584-Nov-08 0:53
User 66584-Nov-08 0:53 
AnswerRe: Exiting Windows Application (from the main form constructor) Pin
Nicholas Butler4-Nov-08 0:54
sitebuilderNicholas Butler4-Nov-08 0:54 

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.