[.NET] 把Button寫成checkbox功能

看板Visual_Basic作者 (接近神的男人)時間14年前 (2011/05/12 11:43), 編輯推噓1(105)
留言6則, 5人參與, 最新討論串1/1
在寫一個畫圖的程式 想把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
s / 2 = 0 改成 s mod 2 =0
05/12 12:39, 1F

05/12 13:10, , 2F
嗯 改成MOD就好 自己逐步執行的話,應該很容易就看出來
05/12 13:10, 2F

05/12 13:19, , 3F
那為什麼用除法不行呢> <不就是奇偶數..怎麼第三次後..
05/12 13:19, 3F

05/12 13:21, , 4F
如果 Dim s=boolean,然後 s=not s 不知結果是否相等?
05/12 13:21, 4F

05/12 14:00, , 5F
阿..原來是我自己想錯QQ 3以上的商..就不可能=0
05/12 14:00, 5F

05/12 14:52, , 6F
這個錯誤實在太有娛樂性了 XD
05/12 14:52, 6F
文章代碼(AID): #1DorTp5e (Visual_Basic)