Windowsフォームアプリケーションでオブジェクトにグラデーションスタイルを適用するいくつかの方法に出くわしました。すべてのメソッドには、OnPaintメソッドのオーバーライドが含まれます。ただし、検証に基づいて実行時にスタイルを変更することを検討しています。
すでにレンダリングされているボタンに新しいグラデーションスタイルを適用するにはどうすればよいですか(BackColorでできるように)?
R、C。
更新:これは私が現在使用しているコードです。効果がないようです
private void Button_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("This is a diagonal line drawn on the control",
new Font("Arial", 10), System.Drawing.Brushes.Blue, new Point(30, 30));
g.DrawLine(System.Drawing.Pens.Red, btn.Left, btn.Top,
btn.Right, btn.Bottom);
this.btn.Invalidate();
}
によって呼ばれている
btn.Paint += new PaintEventHandler(this.Button_Paint);
現在のコードでさらに更新
private void Button_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("This is a diagonal line drawn on the control",
new Font("Arial", 10), System.Drawing.Brushes.Blue, new Point(30, 30));
g.DrawLine(System.Drawing.Pens.Red, btn.Left, btn.Top,
btn.Right, btn.Bottom);
}
private void btn_Click(object sender, EventArgs e)
{
btn.Paint += new PaintEventHandler(this.Button_Paint);();
btn.Invalidate();
}