Help Disect or Explain please

  • Thread starter Thread starter GodspeedSupreme
  • Start date Start date
G

GodspeedSupreme

Guest
Hello Everyone, Can somebody please explain to me the codes within the component and form1


Component:

Public Class cardPanel
Inherits Panel

Private _percentage As Integer
Public Property percentage() As Integer
Get
Return _percentage
End Get
Set(ByVal value As Integer)
_percentage = value
End Set
End Property

Private _text As String
Public Shadows Property Text() As String
Get
Return _text
End Get
Set(ByVal value As String)
_text = value
End Set
End Property

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(212, 157, 93)), New Rectangle(0, 0, CInt((MyBase.Width / 100) * percentage), 6))
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(Text, MyBase.Font, Brushes.Black, New Rectangle(Point.Empty, MyBase.Size), sf)
MyBase.OnPaint(e)
End Sub

End Class


Form1

Public Class Form1

Dim panels As New List(Of cardPanel)

Private Sub Panel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel2.Click, Panel1.Click
Dim p As Panel = DirectCast(sender, Panel)
Dim newPanel As New cardPanel
newPanel.Left = 6
newPanel.Top = If(p.Parent.Controls.OfType(Of cardPanel).Count > 0, p.Parent.Controls.OfType(Of cardPanel).Max(Function(cp) cp.Bottom) + 6, 19)
newPanel.Width = p.Width
newPanel.Height = 36
newPanel.BackColor = Color.White
newPanel.percentage = 0
newPanel.Text = InputBox("Enter caption")
p.Parent.Controls.Add(newPanel)
panels.Add(newPanel)
AddHandler newPanel.MouseMove, AddressOf cardPanels_MouseMove
AddHandler newPanel.Click, AddressOf cardPanels_Click
p.Top = newPanel.Bottom + 6
ComboBox1.Items.Add(panels.Count - 1)
End Sub

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint, Panel1.Paint
Dim p As Panel = DirectCast(sender, Panel)
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
e.Graphics.DrawString("Add card", p.Font, Brushes.Black, New Rectangle(Point.Empty, p.Size), sf)
End Sub

Private Sub cardPanels_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Const HT_CAPTION As Integer = &H2
Const WM_NCLBUTTONDOWN As Integer = &HA1

If e.Button = Windows.Forms.MouseButtons.Left Then
Dim cp As cardPanel = DirectCast(sender, cardPanel)
Dim gb As GroupBox = DirectCast(cp.Parent, GroupBox)
cp.Parent = Me
Dim p As Point = cp.Location
p.Offset(gb.Location)
cp.Location = p
cp.BringToFront()
cp.Capture = False
Me.WndProc(Message.Create(cp.Handle, WM_NCLBUTTONDOWN, CType(HT_CAPTION, IntPtr), IntPtr.Zero))
Dim c As Control = GetContainerAtPoint(MousePosition)
cp.Left = 6
cp.Top = If(c.Controls.OfType(Of cardPanel).Count > 0, c.Controls.OfType(Of cardPanel).Max(Function(card) card.Bottom) + 6, 19)
cp.Parent = c
c.Controls.OfType(Of Panel).ToArray(0).Top = cp.Bottom + 6
compactCards(gb)
End If

End Sub

Private Function GetContainerAtPoint(ByVal p As Point) As Control
Dim c As Control = Me.Controls.OfType(Of GroupBox).FirstOrDefault(Function(gb) gb.Bounds.Contains(Me.PointToClient(p)))
If c IsNot Nothing Then
Return c
Else
Return Me
End If
End Function

Private Sub compactCards(ByVal parent As GroupBox)
Dim topY As Integer = 19
For Each c As cardPanel In parent.Controls.OfType(Of cardPanel).OrderBy(Function(cp) cp.Top)
c.Top = topY
topY = c.Bottom + 6
Next
parent.Controls.OfType(Of Panel).ToArray(0).Top = topY
End Sub

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
If ComboBox1.SelectedIndex = -1 Then Return
panels(ComboBox1.SelectedIndex).percentage = CInt(NumericUpDown1.Value)
panels(ComboBox1.SelectedIndex).Refresh()
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex = -1 Then Return
NumericUpDown1.Value = panels(ComboBox1.SelectedIndex).percentage
End Sub

Private Sub cardPanels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ComboBox1.SelectedIndex = panels.IndexOf(DirectCast(sender, cardPanel))
End Sub


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
End Class


heres the picture:

02d4256a24b66a5b5ce6a907da7da769._.png


Continue reading...
 
Back
Top