Quantcast
Channel: Visual Basic Tips and Tricks
Viewing all articles
Browse latest Browse all 2212

Riutilizzo codice gia funzionante

$
0
0

Ciao forum

Ho due Panels. Ho un bottone su ogni panels:

              

                |                                           |                        |                                           |
                |Panel left e Bottone_BEGIN|                        |Panel right e Bottone_END|
                |                                           |                        |                                           |
 
                                      

La prima volta, quando i panel sono fermi, la rubber band (Button_BEGIN --> Button_END) viene disegnata bene.


Ora devo ridisegnare la rubberband ogni volta che sposto i panels e per fissare le idee supponiamo di spostare il panel left.

Ho inserito due flag nel caso servissero:

RubberBand_STATICA = False
RubberBand_DINAMICA = True


Come modificare tale codice?


'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Private Sub BUTTON BEGIN (ByVal sender As System.Object, ByVal e As System.EventArgs)

Bottone_BEGIN = DirectCast(sender, Button)
m_Inizio_Disegno_Linea = True
m_Punto_Fisso =BUTTON END COORDINATE
m_Punto_Mobile = m_Punto_Fisso

End Sub
'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .






'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Private Sub BUTTON END (ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim Panel_Attuale As String
Dim Coordinate_Bottone_Metodi As Point = Control.MousePosition

Bottone_END = DirectCast(sender, Button)

RubberBand_STATICA = False
RubberBand_DINAMICA = True

If Not m_Inizio_Disegno_Linea Then Exit Sub
' Erase the previous line.
ControlPaint.DrawReversibleLine(m_Punto_Fisso, m_Punto_Mobile, Me.BackColor)
' Save the new point.
m_Punto_Mobile = Coordinate_Bottone_Metodi
' Draw the new line.
ControlPaint.DrawReversibleLine(m_Punto_Fisso, m_Punto_Mobile, Me.BackColor)
'flag
m_Inizio_Disegno_Linea = False
'
m_BufferGraphics.DrawLine(Pens.Blue, Me.PointToClient(m_Punto_Fisso), Me.PointToClient(m_Punto_Mobile))
' Redraw to show the new line.
DrawForm(Me.CreateGraphics())


End Sub
'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .




'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Private Sub Form_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove


If RubberBand_STATICA = True Then
' Do nothing if we're not drawing.
If Not m_Inizio_Disegno_Linea Then Exit Sub

' Erase the previous line.
ControlPaint.DrawReversibleLine(m_Punto_Fisso, m_Punto_Mobile, Me.BackColor)

' Save the new point.
m_Punto_Mobile = Control.MousePosition

' Draw the new line.
ControlPaint.DrawReversibleLine(m_Punto_Fisso, m_Punto_Mobile, Me.BackColor)
End If


If RubberBand_DINAMICA = True Then
' Do nothing if we're not drawing.
If Not m_Inizio_Disegno_Linea Then Exit Sub

' Erase the previous line.
ControlPaint.DrawReversibleLine(m_Punto_Fisso, m_Punto_Mobile, Me.BackColor)

' Save the new point.
m_Punto_Mobile = Me.PointToScreen(Control.MousePosition)

' Draw the new line.
ControlPaint.DrawReversibleLine(m_Punto_Fisso, m_Punto_Mobile, Me.BackColor)
End If
End Sub
'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .




'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Private Sub DrawForm(ByVal gr As Graphics)
If Not (m_BufferBitmap Is Nothing) Then gr.DrawImage(m_BufferBitmap, 0, 0)
End Sub
'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .




'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
DrawForm(e.Graphics)
End Sub
'. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Viewing all articles
Browse latest Browse all 2212