Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. GDI+ help

GDI+ help

Scheduled Pinned Locked Moved C#
winformsgraphicshelptutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    r9
    wrote on last edited by
    #1

    Can someone show me how to draw a raised rectangle on a form using GDI+ ? When the user click the rectangle, then it must be lower. KeyDown = lower; KeyUp = raised; Thanks

    R 1 Reply Last reply
    0
    • R r9

      Can someone show me how to draw a raised rectangle on a form using GDI+ ? When the user click the rectangle, then it must be lower. KeyDown = lower; KeyUp = raised; Thanks

      R Offline
      R Offline
      r9
      wrote on last edited by
      #2

      I need something like this: System.Drawing.Graphics formGraphics = null; System.Drawing.Pen myPen; formGraphics = pictureBox1.CreateGraphics(); myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1); formGraphics.DrawLine(myPen, 5, 5, 105, 5); formGraphics.DrawLine(myPen, 15, 35, 95, 35); formGraphics.DrawLine(myPen, 5, 5, 15, 35); formGraphics.DrawLine(myPen, 105, 5, 95, 35); SolidBrush darkGrayBrush = new SolidBrush(Color.Gray); Point point1 = new Point(5, 5); Point point2 = new Point(105, 5); Point point3 = new Point(15, 35); Point point4 = new Point(95, 35); Point point5 = new Point(5, 5); Point point6 = new Point(15, 35); Point point7 = new Point(105, 5); Point point8 = new Point(95, 35); Point[] curvePoints = new Point[] { point1, point2, point3, point4, point5, point6, point7, point8 }; formGraphics.FillPolygon(darkGrayBrush, curvePoints); but just raised, lower and clickable. How?

      J 1 Reply Last reply
      0
      • R r9

        I need something like this: System.Drawing.Graphics formGraphics = null; System.Drawing.Pen myPen; formGraphics = pictureBox1.CreateGraphics(); myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1); formGraphics.DrawLine(myPen, 5, 5, 105, 5); formGraphics.DrawLine(myPen, 15, 35, 95, 35); formGraphics.DrawLine(myPen, 5, 5, 15, 35); formGraphics.DrawLine(myPen, 105, 5, 95, 35); SolidBrush darkGrayBrush = new SolidBrush(Color.Gray); Point point1 = new Point(5, 5); Point point2 = new Point(105, 5); Point point3 = new Point(15, 35); Point point4 = new Point(95, 35); Point point5 = new Point(5, 5); Point point6 = new Point(15, 35); Point point7 = new Point(105, 5); Point point8 = new Point(95, 35); Point[] curvePoints = new Point[] { point1, point2, point3, point4, point5, point6, point7, point8 }; formGraphics.FillPolygon(darkGrayBrush, curvePoints); but just raised, lower and clickable. How?

        J Offline
        J Offline
        J Dunlap
        wrote on last edited by
        #3

        So you need a rounded-edge rectangle? Right now I have the code for a raised, sunken, etched, or bump border for a rectangle, but not for a rounded-edge rectangle.

        "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

        R 1 Reply Last reply
        0
        • J J Dunlap

          So you need a rounded-edge rectangle? Right now I have the code for a raised, sunken, etched, or bump border for a rectangle, but not for a rounded-edge rectangle.

          "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

          R Offline
          R Offline
          r9
          wrote on last edited by
          #4

          jdunlap: Can you show me the code for a raised / sunken rectangle?

          J 1 Reply Last reply
          0
          • R r9

            jdunlap: Can you show me the code for a raised / sunken rectangle?

            J Offline
            J Offline
            J Dunlap
            wrote on last edited by
            #5

            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 s

            R 1 Reply Last reply
            0
            • J J Dunlap

              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 s

              R Offline
              R Offline
              r9
              wrote on last edited by
              #6

              jdunlap: You can email me the code on: java2@mail.dk Thanks

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups