G
Guest
i have been able to create a custom control that overrides the onpaint method to create a multiline button. However, i can't think of a way to align this text to center. Thoughts
Current code that I have
private bool pressed = false
public WrappingButton(
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e
pressed = true
this.Invalidate()
base.OnMouseDown (e)
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e
pressed = false
this.Invalidate()
base.OnMouseUp (e)
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe
Graphics graphics = pe.Graphics
Pen pen = new System.Drawing.Pen(Color.Black)
SolidBrush brush = new SolidBrush(Color.Black)
Rectangle rect = new Rectangle(5, 5, this.Width-10, this.Height-10)
SolidBrush brushFill = new SolidBrush(Color.Silver)
if (pressed
brushFill.Color = Color.Black
brush.Color = Color.White
graphics.FillRectangle(brushFill, 2, 2, this.Width-4, this.Height-4)
Font font = new Font(this.Font.Name, this.Font.Size-1, FontStyle.Bold)
graphics.DrawString(this.Text, font, brush, rect)
graphics.DrawRectangle(pen, 2, 2, this.Width-4, this.Height-4)
base.OnPaint(pe)
}
Current code that I have
private bool pressed = false
public WrappingButton(
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e
pressed = true
this.Invalidate()
base.OnMouseDown (e)
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e
pressed = false
this.Invalidate()
base.OnMouseUp (e)
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe
Graphics graphics = pe.Graphics
Pen pen = new System.Drawing.Pen(Color.Black)
SolidBrush brush = new SolidBrush(Color.Black)
Rectangle rect = new Rectangle(5, 5, this.Width-10, this.Height-10)
SolidBrush brushFill = new SolidBrush(Color.Silver)
if (pressed
brushFill.Color = Color.Black
brush.Color = Color.White
graphics.FillRectangle(brushFill, 2, 2, this.Width-4, this.Height-4)
Font font = new Font(this.Font.Name, this.Font.Size-1, FontStyle.Bold)
graphics.DrawString(this.Text, font, brush, rect)
graphics.DrawRectangle(pen, 2, 2, this.Width-4, this.Height-4)
base.OnPaint(pe)
}