Click here to Skip to main content
16,020,253 members
Home / Discussions / C#
   

C#

 
GeneralRe: Convert HDIB to Bitmap, so close and yet so far Pin
Brendan Tregear17-Jul-03 16:01
Brendan Tregear17-Jul-03 16:01 
GeneralIs that possible Pin
Kerad16-Jul-03 22:18
Kerad16-Jul-03 22:18 
GeneralRe: Is that possible Pin
leppie17-Jul-03 7:23
leppie17-Jul-03 7:23 
GeneralGDI+ help Pin
r916-Jul-03 21:36
r916-Jul-03 21:36 
GeneralRe: GDI+ help Pin
r916-Jul-03 23:01
r916-Jul-03 23:01 
GeneralRe: GDI+ help Pin
J. Dunlap17-Jul-03 8:07
J. Dunlap17-Jul-03 8:07 
GeneralRe: GDI+ help Pin
r917-Jul-03 22:55
r917-Jul-03 22:55 
GeneralRe: GDI+ help Pin
J. Dunlap18-Jul-03 11:38
J. Dunlap18-Jul-03 11:38 
If you just need sunken and raised borders, you can use .NET's built-in implementation - System.Windows.Forms.ControlPaint.DrawBorder:



But the ControlPaint.DrawBorder method doesn't do etched and bump borders, where as the code below does:
public enum BorderStyle
{
    Raised,Sunken,Etched,Bump
};

/////THE FOLLOWING SHOULD BE IN A CLASS:

  public static void DrawBorder(Graphics g, 
                                Rectangle rect, 
                                BorderStyle border, 
                                Color color)
  {
      BorderStyle inner=BorderStyle.Raised;
      BorderStyle outer=BorderStyle.Raised;
      switch(border)
      {
          case BorderStyle.Raised:
             inner=BorderStyle.Raised;
             outer=BorderStyle.Raised;
             break;
          case BorderStyle.Sunken:
             inner=BorderStyle.Sunken;
             outer=BorderStyle.Sunken;
             break;
          case BorderStyle.Etched:
             inner=BorderStyle.Raised;
             outer=BorderStyle.Sunken;
             break;
          case BorderStyle.Bump:
             inner=BorderStyle.Sunken;
             outer=BorderStyle.Raised;
             break;
     }
     DrawThinBorder(g,rect,outer,color,inner==outer);
     rect.Offset(1,1);
     rect.Width-=2;rect.Height-=2;
     DrawThinBorder(g,rect,inner,color,false);
}
		
public static void DrawThinBorder(Graphics g, 
                                Rectangle rect,
                                BorderStyle border, 
                                Color color)
{DrawThinBorder(g,rect,border,color,false);}

public static void DrawThinBorder(Graphics g, 
                                Rectangle rect, 
                                BorderStyle border, 
                                Color color,
                                bool outer)
{
    if(border==BorderStyle.Raised)
    {
        DrawUpperCorner(g,rect,new Pen((outer?ColorHelper.LightenColor(color,1):color)));
        DrawLowerCorner(g,rect,new Pen(ColorHelper.DarkenColor(color,(outer?3:1))));
     }else
     {
        DrawUpperCorner(g,rect,new Pen(ColorHelper.DarkenColor(color,(outer?1:2))));
        DrawLowerCorner(g,rect,new Pen((outer?ColorHelper.LightenColor(color,1):color)));		

     }
}
		
public static void DrawUpperCorner(Graphics g, Rectangle rect, Pen pen)
{
    g.DrawLine(pen,rect.X, rect.Y,rect.X,rect.Y+rect.Height);
    g.DrawLine(pen,rect.X, rect.Y,rect.X+rect.Width,rect.Y);
}
public static void DrawLowerCorner(Graphics g, Rectangle rect, Pen pen)
{
    g.DrawLine(pen,rect.X+rect.Width, rect.Y,rect.X+rect.Width,rect.Y+rect.Height);
    g.DrawLine(pen,rect.X, rect.Y+rect.Height,rect.X+rect.Width,rect.Y+rect.Height);
}


BTW, the LightenColor and DarkenColor methods return a lighter or darker version of the color passed in. I can send you the code for them if you like, but I don't want to post it here, as it's too long.


"Blessed are the peacemakers, for they shall be called sons of God." - Jesus

"You must be the change you wish to see in the world." - Mahatma Gandhi







GeneralRe: GDI+ help Pin
r918-Jul-03 12:22
r918-Jul-03 12:22 
GeneralFunction Keys Pin
Riaan van der Westhuizen16-Jul-03 20:40
Riaan van der Westhuizen16-Jul-03 20:40 
GeneralRe: Function Keys Pin
fool16-Jul-03 23:55
fool16-Jul-03 23:55 
GeneralRe: Function Keys Pin
Jim Stewart17-Jul-03 5:18
Jim Stewart17-Jul-03 5:18 
QuestionVertical Text? Pin
peenu16-Jul-03 18:59
peenu16-Jul-03 18:59 
AnswerRe: Vertical Text? Pin
fool17-Jul-03 0:01
fool17-Jul-03 0:01 
GeneralCalling an objects method by an attribute Pin
Ista16-Jul-03 16:45
Ista16-Jul-03 16:45 
GeneralRe: Calling an objects method by an attribute Pin
Anonymous16-Jul-03 16:46
Anonymous16-Jul-03 16:46 
GeneralRe: Calling an objects method by an attribute Pin
Jim Stewart17-Jul-03 5:36
Jim Stewart17-Jul-03 5:36 
GeneralGDI+ performance Pin
peterchen16-Jul-03 14:28
peterchen16-Jul-03 14:28 
GeneralRe: GDI+ performance Pin
Stephane Rodriguez.17-Jul-03 2:44
Stephane Rodriguez.17-Jul-03 2:44 
GeneralRe: GDI+ performance Pin
peterchen17-Jul-03 2:58
peterchen17-Jul-03 2:58 
GeneralRe: GDI+ performance Pin
Stephane Rodriguez.17-Jul-03 3:18
Stephane Rodriguez.17-Jul-03 3:18 
GeneralRe: GDI+ performance Pin
Russell Morris17-Jul-03 7:31
Russell Morris17-Jul-03 7:31 
GeneralRe: GDI+ performance Pin
peterchen17-Jul-03 7:56
peterchen17-Jul-03 7:56 
GeneralNetwork Connect Pin
MrJJKoolJ16-Jul-03 10:54
MrJJKoolJ16-Jul-03 10:54 
GeneralRe: Network Connect Pin
RB@Emphasys17-Jul-03 3:05
RB@Emphasys17-Jul-03 3:05 

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.