Painting a button
-
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
-
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
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);
-
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);
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