12:14 p. m. | Posted in




Nota: no hace falta poner los valores de los controles ya que se hacen por código

Texto plano


  1. '* Description : Ejemplo de programa para dibujar en un picturebox
  2. '**********************************************************

  3. 'Variables para almacenar las coordenadas _para los rectángulos y para los círculos
  4. Dim X1 As Long
  5. Dim Y1 As Long
  6. Dim X2 As Long
  7. Dim Y2 As Long

  8. Private Sub Combo1_Click()
  9. Label1.Caption = "Tipo de dibujo: " & Combo1.Text
  10. If Combo1.ListIndex = 1 Then
  11. Check1.Enabled = True
  12. Else
  13. Check1.Enabled = False
  14. End If
  15. End Sub

  16. Private Sub Combo1_KeyPress(KeyAscii As Integer)
  17. KeyAscii = 0
  18. End Sub

  19. Private Sub Form_Load()

  20. 'Agregamos los valores al combo1 que _muestra los posibles dibujos a realizar

  21. With Combo1
  22. .AddItem "Continuo"
  23. .AddItem "Rectangulo"
  24. .AddItem "Circulo"
  25. .AddItem "Punto"
  26. End With

  27. HScroll(0).Min = 0: HScroll(1).Min = 0: HScroll(2).Min = 0
  28. HScroll(0).Max = 255: HScroll(1).Max = 255: HScroll(2).Max = 255
  29. Combo1.ListIndex = 0

  30. End Sub

  31. Private Sub Form_Resize()

  32. 'Redimensionamos los controles
  33. On Error Resume Next

  34. Frame1.Left = (Me.Width - Frame1.Width) / 2
  35. Frame1.Top = Me.Height - (Frame1.Height + 480)

  36. Picture1.Width = Me.Width - 360
  37. Picture1.Height = Frame1.Top - 180

  38. End Sub

  39. Private Sub HScroll_Change(Index As Integer)

  40. 'Esto le da el color de borde al shape1 _de acuerdo al valor de los ScrollBar
  41. Shape1.BorderColor = RGB(HScroll(0).Value, HScroll(1).Value, HScroll(2).Value)

  42. 'Esto le da el color de fondo al shape1 _de acuerdo al valor de los ScrollBar
  43. Shape1.FillColor = RGB(HScroll(0).Value, HScroll(1).Value, HScroll(2).Value)

  44. End Sub

  45. Private Sub Picture1_MouseDown(Button As Integer, _
  46. Shift As Integer, _
  47. X As Single, Y As Single)

  48. 'Almacenamos en estas variables los valores del ratón
  49. X1 = X
  50. Y1 = Y
  51. X2 = X
  52. Y2 = Y

  53. If Combo1.Text = "Rectangulo" Or Combo1.Text = "Circulo" Then
  54. Picture1.PSet (X, Y), Shape1.FillColor
  55. End If
  56. End Sub

  57. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, _
  58. X As Single, Y As Single)

  59. If Button = vbLeftButton Then
  60. 'Línea continua
  61. If Combo1 = "Continuo" Then
  62. Picture1.Line (X1, Y1)-(X, Y), Shape1.FillColor
  63. X1 = X: Y1 = Y
  64. End If
  65. 'Para dibujar los puntos
  66. If Combo1 = "Punto" Then
  67. Picture1.PSet (X, Y), Shape1.FillColor
  68. End If
  69. End If

  70. End Sub

  71. Private Sub Picture1_MouseUp(Button As Integer, _
  72. Shift As Integer, _
  73. X As Single, _
  74. Y As Single)
  75. On Error Resume Next

  76. X1 = 0
  77. Y1 = 0
  78. 'Si estamos en modo de rectángulo
  79. If Combo1 = "Rectangulo" Then

  80. If Check1.Value = 0 Then
  81. 'Si no tiene relleno
  82. Picture1.Line (X2, Y2)-(X, Y), Shape1.FillColor, B
  83. Else
  84. 'si tiene relleno
  85. Picture1.Line (X2, Y2)-(X, Y), Shape1.FillColor, BF
  86. End If
  87. End If

  88. 'Para los círculos
  89. If Combo1 = "Circulo" Then
  90. 'sin relleno
  91. If X > X2 Then
  92. Picture1.Circle (X2, Y2), X - X2, Shape1.FillColor
  93. End If

  94. 'Con relleno
  95. If X2 > X Then
  96. Picture1.Circle (X2, Y2), X2 - X, Shape1.FillColor
  97. End If
  98. End If
  99. End Sub

Category:
��

Comments

0 responses to "Codigo fuente de VB"