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
  1. Home
  2. General Programming
  3. C#
  4. Painting a button

Painting a button

Scheduled Pinned Locked Moved C#
graphicsquestion
3 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.
  • K Offline
    K Offline
    kalyanPaladugu
    wrote on last edited by
    #1

    Iam trying to paint a button to get a shade in a button. How do i do it. Iam using this code below. Iam using a LinearGradientBrush but it doesn't seem to do anything void button1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Rectangle rcView = this.ClientRectangle; using (LinearGradientBrush brush = new LinearGradientBrush(rcView, this.ColorStart, this.ColorEnd, this.GradientMode)) { g.FillRectangle(brush, rcView); } base.OnPaint(e); } ColorStart and ColorEnd are basically colors. Iam just get the shade of the color from lighter to darker across the button. So my ColorStart is a little lighter color and ColorEnd is a Darker color. Thanks Kal

    N 1 Reply Last reply
    0
    • K kalyanPaladugu

      Iam trying to paint a button to get a shade in a button. How do i do it. Iam using this code below. Iam using a LinearGradientBrush but it doesn't seem to do anything void button1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Rectangle rcView = this.ClientRectangle; using (LinearGradientBrush brush = new LinearGradientBrush(rcView, this.ColorStart, this.ColorEnd, this.GradientMode)) { g.FillRectangle(brush, rcView); } base.OnPaint(e); } ColorStart and ColorEnd are basically colors. Iam just get the shade of the color from lighter to darker across the button. So my ColorStart is a little lighter color and ColorEnd is a Darker color. Thanks Kal

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello Few points: 1- this.ClientRectangle => Should be => button1.ClientRectangle 2- base.OnPaint(e); => Why this?? 3- How do you define: this.ColorStart, this.ColorEnd, this.GradientMode?? Which colors exactly did you use? Very close gradients may fuse together. Now try this code:

      Graphics g = e.Graphics;
      Rectangle rcView = button1.ClientRectangle;

              using (LinearGradientBrush brush = new LinearGradientBrush(rcView,Color.DarkGreen, Color.DarkMagenta, 50 ))
              {
                  g.FillRectangle(brush, rcView);
              }
              //base.OnPaint(e);
      
      K 1 Reply Last reply
      0
      • N Nader Elshehabi

        Hello Few points: 1- this.ClientRectangle => Should be => button1.ClientRectangle 2- base.OnPaint(e); => Why this?? 3- How do you define: this.ColorStart, this.ColorEnd, this.GradientMode?? Which colors exactly did you use? Very close gradients may fuse together. Now try this code:

        Graphics g = e.Graphics;
        Rectangle rcView = button1.ClientRectangle;

                using (LinearGradientBrush brush = new LinearGradientBrush(rcView,Color.DarkGreen, Color.DarkMagenta, 50 ))
                {
                    g.FillRectangle(brush, rcView);
                }
                //base.OnPaint(e);
        
        K Offline
        K Offline
        kalyanPaladugu
        wrote on last edited by
        #3

        Thanks for answering me. I got it to work. You are right its button1.ClientRectangle. I had to again use g.DrawString to draw the name on the button because its lost after i painted Thanks Kal

        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