Draw

  • Thread starter Thread starter Rodrigo Ferreira
  • Start date Start date
Rodrigo said:
How can i draw a line inside a button?

this.button1.Paint +=
new System.Windows.Forms.PaintEventHandler(this.button1_Paint);

private void button1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(
new System.Drawing.Pen(System.Drawing.Color.Red),0,0,10,10);
}
 
and inside a textbox?

darek said:
this.button1.Paint +=
new System.Windows.Forms.PaintEventHandler(this.button1_Paint);

private void button1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(
new System.Drawing.Pen(System.Drawing.Color.Red),0,0,10,10);
}
 
Rodrigo,

The same code would apply to the textbox. The Paint event would allow
you to perform extra paint operations whenever the control was painted.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rodrigo Ferreira said:
and inside a textbox?
 
Nicholas said:
Rodrigo,

The same code would apply to the textbox. The Paint event would allow
you to perform extra paint operations whenever the control was painted.

Hope this helps.

Paint events dont fire up on textbox. If you want make textbox to do so,
you have to use SetStyle method.

public class MyTextBox : System.Windows.Forms.TextBox
{
public MyTextBox()
{
this.SetStyle(ControlStyles.UserPaint, true);
}

protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = this.CreateGraphics();
g.DrawLine(
new System.Drawing.Pen(System.Drawing.Color.Red),0,0,10,10);
}
}
 
please you can be more explicit! I don't understand what you want to say!

Nicholas Paldino said:
Rodrigo,

The same code would apply to the textbox. The Paint event would allow
you to perform extra paint operations whenever the control was painted.

Hope this helps.
 
All Controls have the Paint event. When Windows detects that a Control is in need of refreshing it will trigger the Paint event. You can add paint by subscribing to the PaintEventHandler or in case of Controls like TextBoxes, override the Paint event in an inherited class.

please you can be more explicit! I don't understand what you want to say!

Nicholas Paldino said:
Rodrigo,

The same code would apply to the textbox. The Paint event would allow
you to perform extra paint operations whenever the control was painted.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rodrigo Ferreira said:
and inside a textbox?

Rodrigo Ferreira wrote:
How can i draw a line inside a button?

this.button1.Paint +=
new System.Windows.Forms.PaintEventHandler(this.button1_Paint);

private void button1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(
new System.Drawing.Pen(System.Drawing.Color.Red),0,0,10,10);
}
 
Back
Top