Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: seba123neo en Septiembre 14, 2011, 12:24:47 pm
-
Hola, estaba usando este ejemplo de Leandro:
DrawSelectionEx (http://leandroascierto.com/blog/drawselectionex/)
pero me di cuenta que no se puede borrar un objeto dibujado y despues repintarlo en otro lugar.
haber si me explico, en ese ejemplo si trato de "mover" a otra posicion un objeto que esta dibujado no puedo. o sea necesitaria saber como "borrar" un objeto determinado y volverlo a dibujar en otra posicion, ya que si hago un Cls() se me borra todo, pero yo necesito que queden dibujados todos, pero mover uno determinado, estaba pensando hacer un usercontrol pero trataba de evitar esto, haber si alguien sabe como hacerle.
saludos.
-
Hola Seba, no me queda muy claro del todo, pero te tiro algunas sugerencias.
no se si estas trabajando con doble buffer (Autoredraw =true) o si haces esto en el paint
Si vos usas un fondo con un color solido lo que tenes que hacer es cubrir la selección con este color y luego pintar la selección en otra parte.
podes usar esta funcion o bien la misma funcion "LINE" del vb
Option Explicit
Private Declare Function FillRect Lib "user32.dll" (ByVal hdc As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, ByRef lColorRef As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Function FillRectDC(hdc As Long, ByVal oColor As OLE_COLOR, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long) As Boolean
Dim lColor As Long
Dim hBrush As Long
Dim tRECT As RECT
OleTranslateColor oColor, 0&, lColor
hBrush = CreateSolidBrush(lColor)
With tRECT
.Left = x
.Top = y
.Right = x + Width
.Bottom = y + Height
End With
FillRectDC = FillRect(hdc, tRECT, hBrush)
DeleteObject hBrush
End Function
un ejemplo agregas un HScroll1 a un formulario.
Option Explicit
Private Declare Function FillRect Lib "user32.dll" (ByVal hdc As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, ByRef lColorRef As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim OldPosX As Long
Private Function FillRectDC(hdc As Long, ByVal oColor As OLE_COLOR, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long) As Boolean
Dim lColor As Long
Dim hBrush As Long
Dim tRECT As RECT
OleTranslateColor oColor, 0&, lColor
hBrush = CreateSolidBrush(lColor)
With tRECT
.Left = x
.Top = y
.Right = x + Width
.Bottom = y + Height
End With
FillRectDC = FillRect(hdc, tRECT, hBrush)
DeleteObject hBrush
End Function
Private Sub Form_Load()
Me.Show
Me.ScaleMode = vbPixels
Me.Width = 8500
Me.Height = 8700
DoEvents
HScroll1.Max = Me.ScaleWidth
Dim i As Long
For i = 0 To 15
DrawSelectionEx Me.hdc, 10, 10 + (i * 35), 70, 30, Me.BackColor, pvAlphaBlend(QBColor(i), Me.BackColor, 50)
Next
OldPosX = 10
End Sub
Private Sub HScroll1_Change()
FillRectDC hdc, Me.BackColor, OldPosX, 10, 70, 30
DrawSelectionEx Me.hdc, HScroll1.Value, 10, 70, 30, Me.BackColor, pvAlphaBlend(QBColor(0), Me.BackColor, 50)
OldPosX = HScroll1.Value
End Sub
Ahora si vos usas una imagen de fondo (como propiedad picture, no repintandola) podes usar RedrawWindow
el mismo ejemplo pero con una imagen de fondo
Option Explicit
Private Declare Function RedrawWindow Lib "user32.dll" (ByVal hwnd As Long, ByRef lprcUpdate As RECT, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim OldPosX As Long
Private Sub Form_Load()
Me.Show
Me.ScaleMode = vbPixels
Me.Width = 8500
Me.Height = 8700
DoEvents
HScroll1.Max = Me.ScaleWidth
Dim i As Long
For i = 0 To 15
DrawSelectionEx Me.hdc, 10, 10 + (i * 35), 70, 30, Me.BackColor, pvAlphaBlend(QBColor(i), Me.BackColor, 50)
Next
OldPosX = 10
End Sub
Private Sub HScroll1_Change()
RedrawRectWindow Me.hwnd, OldPosX, 10, 70, 30
DoEvents
DrawSelectionEx Me.hdc, HScroll1.Value, 10, 70, 30, Me.BackColor, pvAlphaBlend(QBColor(0), Me.BackColor, 50)
OldPosX = HScroll1.Value
End Sub
Private Function RedrawRectWindow(hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long) As Boolean
Dim tRECT As RECT
With tRECT
.Left = x
.Top = y
.Right = x + Width
.Bottom = y + Height
End With
RedrawWindow hwnd, tRECT, 0&, 1
End Function
comenta un poco como es lo que queres hacer, porque quizas si es algo asi como una lista, te conviene repintar todo o usar doble buffer
-
Leandro, muchas gracias por tu respuesta, sabes como lo resolvi ? pintando dentro de un picturebox, entonces cuando quiero mover el objeto pintado, simplemente muevo el picturebox y lo pintando se mueve tambien...asi de simple, lo que pasa es que yo pense que cada dibujo se podia mover independientemente como si fuera un objeto.
saludos.