[.NET] 把Button寫成checkbox功能
在寫一個畫圖的程式
想把button寫成類似checkbox的功能
Ex 按第一下按鈕 顯示一個圓 再按一次同一個按鈕清這圖片
以下是我的寫法
Dim s,w As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim g As Graphics = PictureBox1.CreateGraphics
If s / 2 = 0 Then
For i As Integer = 0 To ptArray.Count - 1
Dim tmpPT As Point = CType(ptArray(i), Point)
g.DrawEllipse(Pens.Green, tmpPT.X - w \ 2, tmpPT.Y - w \ 2,
w, w) '畫圓
Next i
Else
g.Clear(Me.BackColor)
For i As Integer = 0 To ptArray.Count - 1
Dim tmpPT As Point = CType(ptArray(i), Point)
g.FillRectangle(Brushes.Red, tmpPT.X, tmpPT.Y, 4, 4) '畫點
Next i
End If
s = s + 1
End sub
以上是我在picture上用滑鼠點擊就會畫出一個點,此點座標存於陣列中
Button3 點擊時 會以點為圓心畫圓
再次點擊Button3時會清除畫面把點過的點再畫出來=清除圓
預計出現的結果 是按一次畫圓 再次按下圓清除
但按下第三次後喪失任何攻能...應該再次出現的阿
--
◢██◣▎ █▇▆▅▄ ◣ ◢ ◢█◣◢█◣ ┐│ ╔║║
▊◣ ◢▎ ▉ ◢█◣ ◢█◣█ █◢█◣███████▆◣ │┤ ║║║
◥██◤ ▊ ▋ █ ▋▄◤◥█◤▌▄◤◥████◤ ▌ ▋ 人│ ║╠╣
◥█◣◢◣ ▋ ◥█▋▌◥▄▃ █ ◥▅▂ ◥██◤ ▌ ▊ │ ║║║
▅▅▍ ◥◤ ╰─ ╚║║
—— The Red Captain Gee~Gee~Gee~Gee Tae~Tae~Tae~Tae~Tae~yeon~by jimmy508
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.230.83.74
→
05/12 12:39, , 1F
05/12 12:39, 1F
推
05/12 13:10, , 2F
05/12 13:10, 2F
→
05/12 13:19, , 3F
05/12 13:19, 3F
→
05/12 13:21, , 4F
05/12 13:21, 4F
→
05/12 14:00, , 5F
05/12 14:00, 5F
→
05/12 14:52, , 6F
05/12 14:52, 6F