2016-06-02 10 views
0
protected override void OnPaint(PaintEventArgs e) 
{ 
    base.OnPaint(e); 
    var cp = new Point(Width/2, Height/2); 
    DrawGradientCircle(e.Graphics, cp, 100); 
} 

private void DrawGradientCircle(Graphics gr, Point cp, float radius) 
{ 
    var path = new GraphicsPath(); 
    path.AddEllipse(cp.X - radius, cp.Y - radius, 2 * radius, 2 * radius); 
    using (var brush = new PathGradientBrush(path)) 
    { 
     var blends = new ColorBlend(7); 
     blends.Colors[0] = Color.Violet; 
     blends.Positions[0] = 0; 
     blends.Colors[1] = Color.Blue; 
     blends.Positions[1] = 0.16f; 
     blends.Colors[2] = Color.Aqua; 
     blends.Positions[2] = 0.32f; 
     blends.Colors[3] = Color.Lime; 
     blends.Positions[3] = 0.48f; 
     blends.Colors[4] = Color.Yellow; 
     blends.Positions[4] = 0.64f; 
     blends.Colors[5] = Color.Orange; 
     blends.Positions[5] = 0.82f;  
     blends.Colors[6] = Color.Red; 
     blends.Positions[6] = 1; 
     brush.InterpolationColors = blends; 
     gr.FillPath(brush, path); 
    } 
} 

ボタンがクリックされた後に円を描きたいだけですが、どうやってそれを行うのですか? しかし、私は右のあなたを理解している場合、あなたはブール変数を持つことができ、あなたがボタンをクリックしたときtrueに設定したリンクボタンクリック後の描画方法は?

+0

ドロップボタンをmyButton_Clickを割り当て、その 'Click'イベント、それが動作 – Rhumborl

答えて

1

作る方法がわからない...のようなもの:

private bool _buttonClicked = false; 

void myButton_Click(object sender, EventArgs e) 
{ 
    _buttonClicked = true; 
    this.Invalidate(); // <-- invalidate the form so it's repainted 
    this.Update(); // <-- optional: force a synchronous repaint 
} 

protected override void OnPaint(PaintEventArgs e) 
{ 
    base.OnPaint(e); 

    if(!_buttonClicked) return; 

    // this will only happen after button is clicked 
    var cp = new Point(Width/2, Height/2); 
    DrawGradientCircle(e.Graphics, cp, 100); 
} 

は、上のボタンのClickイベントに

+0

に耳を傾けることを忘れないでください、ありがとうございました!! – Baylleaf

+0

喜んで:-) – Jcl

関連する問題