Visual Basic.NET - problemas al dibujar en visual basic net

 
Vista:

problemas al dibujar en visual basic net

Publicado por yolanda (1 intervención) el 03/06/2008 18:27:25
hola a todos,
tengo un problema, resulta que estoy haciendo una aplicación tipo al paint de windows, y mi problema viene al dibujar, consigo que me dibuje bien, pero claro, yo he creado dos pen, uno que me dibuje y el otro para que me borre todos los circulos o cuadrados que me crea el automáticamente hasta que termino la operación, desde el punto inicial al final, el me crea desde un circulo pequeño hasta el grande final. Yo eso lo he solucionado creandome otro pen que me va borrando, pero lo hace tan bien, que si yo tnego dibujada otra figura en la pantalla, me borra también los pixels por los que va pasando.

Este es el código que yo he puesto:
Public Class frmPrincipal
Inherits System.Windows.Forms.Form

Private Const linea As Short = 1
Private Const elipse As Short = 2
Private Const rectangulo As Short = 3
Private Const poligono As Short = 4
Private Const arco As Short = 5

Private herramienta As Short
Private pulsado As Boolean = False
Private xant, yant, xini, yini As Integer
Private superficie As Graphics
Private superficie2 As Graphics
Private b As Bitmap

Private Sub mnuArchivoSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuArchivoSalir.Click
Me.Close()

End Sub

Private Sub tlbDibujo_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tlbDibujo.ButtonClick
Dim boton As ToolBarButton
boton = e.Button
If (boton Is btnDibujoLinea) Then
stbDibujo.Text = "Dibuja líneas"
herramienta = linea
ElseIf (boton Is btnDibujoElipse) Then
stbDibujo.Text = "Dibuja elipses"
herramienta = elipse
ElseIf (boton Is btnDibujoRectangulo) Then
stbDibujo.Text = "Dibuja rectángulos"
herramienta = rectangulo
ElseIf (boton Is btnDibujoPoligono) Then
stbDibujo.Text = "Dibuja polígonos"
herramienta = poligono
ElseIf (boton Is btnDibujoArco) Then
stbDibujo.Text = "Dibuja arcos"
herramienta = arco
Else
stbDibujo.Text = String.Empty

End If
End Sub

Private Sub frmPrincipal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ancho, alto As Integer
superficie = Me.CreateGraphics()
ancho = Me.ClientSize.Width
alto = Me.ClientSize.Height
b = New Bitmap(ancho, alto)
superficie2 = Graphics.FromImage(b)
End Sub

Private Sub frmPrincipal_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
superficie.DrawImage(b, 0, 0)
End Sub

Private Sub frmPrincipal_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
pulsado = Not (pulsado)
If (pulsado) Then
xant = e.X
yant = e.Y
xini = e.X
yini = e.Y
End If
End Sub

Private Sub frmPrincipal_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Dim borrador As New Pen(Me.BackColor)
Dim lapiz As New Pen(Color.Black)
Dim rectang As New Rectangle(0, 0, 0, 0)
Dim x, y As Integer
x = e.X
y = e.Y
If ((xant <> x) Or (yant <> y)) Then
If (pulsado) Then
Select Case herramienta
Case linea
superficie.DrawLine(lapiz, xant, yant, x, y)
superficie2.DrawLine(lapiz, xant, yant, x, y)
Case elipse
rectang.X = xini
rectang.Y = yini
rectang.Width = xant - xini
rectang.Height = yant - yini
superficie.DrawEllipse(borrador, rectang)
superficie2.DrawEllipse(borrador, rectang)
rectang.Width = x - xini
rectang.Height = y - yini
superficie.DrawEllipse(lapiz, rectang)
superficie2.DrawEllipse(lapiz, rectang)
Case rectangulo
rectang.X = xini
rectang.Y = yini
rectang.Width = xant - xini
rectang.Height = yant - yini
superficie.DrawRectangle(borrador, rectang)
superficie2.DrawRectangle(borrador, rectang)
rectang.Width = x - xini
rectang.Height = y - yini
superficie.DrawRectangle(lapiz, rectang)
superficie2.DrawRectangle(lapiz, rectang)
End Select
End If
xant = x
yant = y
End If
End Sub
End Class

entonces mi pregunta es, como puedo hacer para dibujar un circulo y que no me vaya borrando los pixeles qu ehay en la pantalla.
Necesito ayuda
un saludo
yolanda
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder