OLD
Namespace Core
Friend Module Func
Public OkButton As Button
Public CancelButton As Button
Public ProgBar As ProgressBar
Private Sub ProgressLoop()
Do
Func.ProgBar.PerformStep()
Threading.Thread.Sleep(1)
Loop
End Sub
#Region "Constants"
Public Const DataRoot As String = "C:\AFormData\"
Public Const IMG_PATH As String = "C:\AFormData\img"
Public Const LoadImage As String = "C:\AFormData\img\codemap_zps4115ff7e.jpg"
Public Const LINE_TERMINATOR As String = ">>"
Public Const LoadImageX As Integer = 0
Public Const LoadImageY As Integer = 0
Public Const LoadBarFailedMessage As String = "Loading Bar Denied"
Public Const ResizeMessage As String = "Current Form Resizing"
Public Const NoCommandMsg As String = "Not a command."
#End Region
#Region "Form Vars"
Public Const CURRENT_FORM As Integer = 1
Public Const PREVIOUS_FORM As Integer = 2
Public IsInitialized As Boolean
Public OkButtonLocationX As Integer
Public OkButtonLocationY As Integer
Public LoadingThread As Threading.Thread
#End Region
Function ProgBarTime(ByVal form As Form1) As Integer
Return form.ProgressTime
End Function
Function TboxLocCalc(ByVal form As Form1) As Point
Return New Point(form.Width / 2 + 100, form.Height / 2 + 100)
End Function
Function TboxLocCalc2(ByVal form As Form1) As Point
Return New Point(form.Width / 2 + 100, form.Height / 2)
End Function
Function ButtonLocCalc(ByVal form As Form1) As Point
Return New Point(form.Width / 2 - 100, form.Height / 2 - 100)
End Function
Function Button2LocCalc(ByVal form As Form1) As Point
Return New Point(Func.ButtonLocCalc(form).X - 100, Func.ButtonLocCalc(form).Y)
End Function
Function InitializeFunc(ByVal form As Form1) As Boolean
Dim Ok, Cancel As Button
Ok = New Button
Cancel = New Button
OkButton = Ok
CancelButton = Cancel
If IsNothing(form) Then
Return IsInitialized = False
Else
Debug.Write("Something else?")
End If
If form.InitializeOk = True Then
form.Width = 640
form.Height = 480
form.CurrentString = String.Empty
form.PreviousString = String.Empty
FormBoundsWidth(form)
FormBoundsHeight(form)
Func.ProgBar = Func.CreateProgBar(form)
form.Controls.Add(Func.ProgBar)
'LoadingThread = New Threading.Thread(AddressOf Func.ProgressLoop)
form.Update()
End If
If form.InitializeOk = False Then
Return Func.IsInitialized = False
End If
Return Func.IsInitialized = True
End Function
Function FormBoundsWidth(ByVal form As Object) As Integer
Return form.Bounds.Width
End Function
Function FormBoundsHeight(ByVal form As Object) As Integer
Return form.Bounds.Height
End Function
Function CreateForm() As Form1
Dim f As New Form1
f.FormNum = PREVIOUS_FORM
f.Controls.Add(OkButton)
f.Controls.Add(CancelButton)
f.Show()
f.SendToBack()
Return f
End Function
Function GetTbox(ByVal Form1 As Form1) As TextBox
Return Form1.TextBox1
End Function
Function CreateProgBar(ByVal aform As Form1) As ProgressBar
Dim pb As New ProgressBar
pb.Location = New Point(aform.Width / 400, aform.Height / 300)
pb.Size = New Size(aform.Bounds.Width, aform.Bounds.Height / 4)
Return pb
End Function
Function CreateLoadScreen(ByVal aform As Form1) As Form1
Dim CurrentTime As Integer = 0
Dim gfx As Graphics = aform.CreateGraphics
Dim TotalLoadTime As Integer
Dim LoadTimeResult As Integer = 0
If IsInitialized = False Then
Func.IsInitialized = False
aform.DW_WRITELINE(Func.LoadBarFailedMessage)
aform.SendToBack()
Return Nothing
End If
OkButton.PerformClick()
CurrentTime = CurrentTime + 1
CurrentTime = CurrentTime + 1
If aform.InitializeOk = True Then
gfx.Clear(Color.Black)
aform.InitializeOk = False
End If
CurrentTime = CurrentTime + 1
Dim ld As Image = Image.FromFile(Func.LoadImage)
'gfx.DrawImage(ld, New Point(LoadImageX, LoadImageY))
CurrentTime = CurrentTime + 1
LoadTimeResult = LoadTimeResult + CurrentTime
'Threading.Thread.Sleep(LoadTimeResult)
'Threading.Thread.SpinWait(100)
'Func.ProgBar.Value = 0
'LoadingThread = Nothing
'Do Until aform.ProgressTime >= 0 And aform.ProgressTime >= 8
'Func.ProgBar.PerformStep()
'Loop
Func.LoadTime(aform, gfx)
Return aform
End Function
Function LoadTime(ByVal form As Form1, ByVal gfx As Graphics) As String
Dim x As Integer = 0
Dim LoadingMessage = "Loading"
Dim Counter As String = "."
For x = 0 To 1 * 2
gfx.DrawString(LoadingMessage, New Font("Tahoma", 20), Brushes.Azure, 0, 0)
form.Invalidate()
LoadingMessage += Counter
Threading.Thread.Sleep(1000 * 2)
Next
Return LoadingMessage
End Function
End Module
End Namespace
The Implementaion
Imports WindowsApplication4.Core
Public Class Form1
Inherits System.Windows.Forms.Form
Friend Shared FormNum As Integer
Friend Shared PreviousForm As Form1
Friend Shared Current_Form As Form1
Friend Shared PreviousString, CurrentString As String
Friend Shared ProgressTime As Integer
Friend Shared InitializeOk As Boolean
Event Commands()
#Region " Windows Form Designer generated code "
'Public Sub New()
'MyBase.New()
'This call is required by the Windows Form Designer.
'InitializeComponent()
'Add any initialization after the InitializeComponent() call
'End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 208)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(200, 208)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 1
Me.Button2.Text = "Button2"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(8, 56)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(272, 120)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(8, 184)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(272, 20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = "TextBox2"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(80, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(100, 24)
Me.Label1.TabIndex = 4
Me.Label1.Text = "IonVision"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Sub New()
InitializeComponent()
Func.OkButton = Me.Button1
Func.CancelButton = Me.Button2
Func.IsInitialized = False
Current_Form = Me
InitializeOk = True
AddHandler Commands, AddressOf Command
ProgressTime = 0
Func.InitializeFunc(Me)
Func.IsInitialized = True
'Func.CreateLoadScreen(Me)
End Sub
Private Sub OkButton_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button1.Click
If s.InitializeOk = True Then
Dim CreatedForm = Func.CreateForm
Form1.PreviousForm = CreatedForm
If Func.InitializeFunc(CreatedForm) = False Then
Throw New Exception("Failed to Create Form")
ElseIf True Then
Func.IsInitialized = True
End If
End If
End Sub
Public Shared Sub DW_WRITELINE(ByVal input As String)
If Func.IsInitialized = True Then
GetTbox(Current_Form).AppendText(Func.LINE_TERMINATOR & input & Environment.NewLine)
End If
End Sub
Dim resized As Boolean = False
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
End Sub
Private Sub Command()
If IsNothing(CurrentString) Then
DW_WRITELINE(Func.NoCommandMsg)
Exit Sub
End If
If CurrentString = "Min" Then
Me.Width = 300
Me.Height = 300
Me.Button1.Location = Func.ButtonLocCalc(Me)
Me.Button1.Location = Func.Button2LocCalc(Me)
Me.TextBox1.Location = Func.TboxLocCalc(Me)
Me.TextBox2.Location = Func.TboxLocCalc2(Me)
End If
If CurrentString = "Max" Then
Me.Width = 1024
Me.Height = 768
Me.Button1.Location = Func.ButtonLocCalc(Me)
Me.Button2.Location = Func.Button2LocCalc(Me)
Me.TextBox1.Location = Func.TboxLocCalc(Me)
Me.TextBox2.Location = Func.TboxLocCalc2(Me)
End If
If CurrentString = "Load" Then
For Each Control As Control In Me.Controls
Control.Visible = False
Next
'Func.InitializeFunc(Me)
Func.CreateLoadScreen(Me) 'Load Screen Function
Func.InitializeFunc(Me) 'Reload GUI
For Each Control As Control In Me.Controls
Control.Visible = True
Next
End If
If CurrentString = "Go" Then
Me.InitializeOk = True
Func.InitializeFunc(Me)
'RaiseEvent Commands()
End If
End Sub
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
Select Case e.KeyCode
Case Keys.Enter
CurrentString = CStr(TextBox2.Text)
PreviousString = CStr(TextBox2.Text)
RaiseEvent Commands()
End Select
End Sub
End Class