I have a small piece of code I've been working on that should do the following: Upon entering certain information, it will display a visual representation of a column layout like this
![Name: TwoColumn.png
Views: 37
Size: 401 Bytes]()
This works fine but I cannot get the function to repeat. In other words, if I press the button that puts these functions together, a second time, I get ... nothing. I have had this problem in the past on other code, but for the life of me I can't remember what I did to fix it. After several bad attempts I decided to ask you guys for assistance.
Here is the code:
This works fine but I cannot get the function to repeat. In other words, if I press the button that puts these functions together, a second time, I get ... nothing. I have had this problem in the past on other code, but for the life of me I can't remember what I did to fix it. After several bad attempts I decided to ask you guys for assistance.
Here is the code:
Code:
Imports System.Drawing
Public Class Form1
Private ListStartX As New List(Of Single)
Private ListEndX As New List(Of Single)
Private pt1 As Point
Private sz As Size
Private rect As Rectangle
Private pen As New Pen(Brushes.DodgerBlue, 4)
Private LeftMargin As Single
Private RightMargin As Single
Private TopMargin As Single
Private BottomMargin As Single
Private startX As Single
Private endX As Single
Private Yvalue As Single
Private startPoint As PointF
Private endPoint As PointF
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListStartX.Clear()
ListEndX.Clear()
pt1 = New Point(2, 2)
sz = New Size(79, 104)
rect = New Rectangle(pt1, sz)
TopMargin = TopMargin * 10
BottomMargin = PictureBox1.Height - BottomMargin * 10 - 2
LeftMargin = LeftMargin * 10
RightMargin = PictureBox1.Width - (RightMargin * 10 + 4)
Yvalue = TopMargin
If updnColNum.Value > 1 Then
For i As Integer = 1 To updnColNum.Value
If i = 1 Then
If LeftMargin + (CSng(txtColWidth.Text) * 10) < RightMargin Then
ListStartX.Add(LeftMargin)
ListEndX.Add(LeftMargin + (CSng(txtColWidth.Text) * 10))
Else
ListStartX.Add(LeftMargin)
ListEndX.Add(RightMargin)
End If
Else
If LeftMargin + CSng(txtColWidth.Text) * 10 * (i - 1) + CSng(txtSpacing.Text) * 10 * (i - 1) < RightMargin Then
ListStartX.Add(LeftMargin + CSng(txtColWidth.Text) * 10 * (i - 1) + CSng(txtSpacing.Text) * 10 * (i - 1))
ListEndX.Add(LeftMargin + CSng(txtColWidth.Text) * 10 * i + CSng(txtSpacing.Text) * 10 * (i - 1))
Else
ListStartX.Add(LeftMargin + CSng(txtColWidth.Text) * 10 * (i - 1) + CSng(txtSpacing.Text) * 10 * (i - 1))
ListEndX.Add(RightMargin)
End If
End If
Next
Else
startX = LeftMargin
endX = RightMargin
startPoint = New PointF(startX, Yvalue)
endPoint = New PointF(endX, Yvalue)
End If
'Yvalue = TopMargin
PictureBox1.Invalidate()
'TopMargin = Nothing
'BottomMargin = Nothing
'LeftMargin = Nothing
'RightMargin = Nothing
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
If pt1 <> Nothing AndAlso sz <> Nothing AndAlso rect <> Nothing Then
e.Graphics.DrawRectangle(pen, rect)
End If
If startPoint <> Nothing AndAlso endPoint <> Nothing Then
Do While Yvalue < BottomMargin
startPoint = New PointF(startX, Yvalue)
endPoint = New PointF(endX, Yvalue)
e.Graphics.DrawLine(Pens.Black, startPoint, endPoint)
Yvalue += 4
Loop
ElseIf ListStartX IsNot Nothing AndAlso ListEndX IsNot Nothing Then
Do While Yvalue < BottomMargin
For i As Integer = 0 To ListStartX.Count - 1
startPoint = New PointF(ListStartX(i), Yvalue)
endPoint = New PointF(ListEndX(i), Yvalue)
e.Graphics.DrawLine(Pens.Black, startPoint, endPoint)
Next
Yvalue += 4
Loop
End If
End Sub
Private Sub txtTopMargin_TextChanged(sender As Object, e As EventArgs) Handles txtTopMargin.TextChanged
If txtTopMargin.Text <> "" Or txtTopMargin.Text <> "." Then
TopMargin = CSng(txtTopMargin.Text)
End If
End Sub
Private Sub txtBtmMargin_TextChanged(sender As Object, e As EventArgs) Handles txtBtmMargin.TextChanged
If txtBtmMargin.Text <> "" Or txtBtmMargin.Text <> "." Then
BottomMargin = CSng(txtBtmMargin.Text)
End If
End Sub
Private Sub txtLftMargin_TextChanged(sender As Object, e As EventArgs) Handles txtLftMargin.TextChanged
If txtLftMargin.Text <> "" Or txtLftMargin.Text <> "." Then
LeftMargin = CSng(txtLftMargin.Text)
End If
End Sub
Private Sub txtRgtMargin_TextChanged(sender As Object, e As EventArgs) Handles txtRgtMargin.TextChanged, txtColWidth.TextChanged, txtSpacing.TextChanged
If txtRgtMargin.Text <> "" Or txtRgtMargin.Text <> "." Then
RightMargin = CSng(txtRgtMargin.Text)
End If
End Sub
End Class