Hi
Actually painting with Transparant brush will not draw/overwrite any thing.
To get the desired result you need to clear the pixels using the setpixel method.
Here I've just cleared the pixels using the rectangle (which you've given as 4x4).
Imports System.Drawing
Public Class Form1
Dim canpaint As Boolean = False
Dim g As Graphics
Dim target As New Bitmap(200, 200)
Dim b As Brush
Enum dmode
d
e
End Enum
Dim m As dmode = dmode.d
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.R
m = dmode.d
b = Brushes.Red
Case Keys.G
m = dmode.d
b = Brushes.Green
Case Keys.K
m = dmode.d
b = Brushes.Black
Case Keys.T
m = dmode.e
End Select
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PictureBox1.Image = target
b = Brushes.Black
g = Graphics.FromImage(target)
End Sub
Private Sub PictureBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.LostFocus
canpaint = False
End Sub
Private Sub Picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
canpaint = True
End Sub
Private Sub Picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If canpaint = True Then
If m = dmode.d Then
g.FillEllipse(b, e.X, e.Y, 4, 4)
Else
For i As Integer = e.X To e.X + 4
For j As Integer = e.Y To e.Y + 4
target.SetPixel(i, j, Color.Transparent)
Next
Next
End If
updateimage()
End If
End Sub
Private Sub Picturebox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
canpaint = False
End Sub
Private Sub updateimage()
PictureBox1.Image = target
End Sub
End Class