📄 form1.vb
字号:
Public Class Form1
Private tt As Double
Dim currentStep As Int32
Private isReady As Boolean = False
Dim sne As New Senne
Dim si As MyGraphic
Dim mythread As New Threading.Thread(AddressOf sne.start)
Public Delegate Sub DealComplete()
Public Delegate Sub ShowInformation(ByVal str As String)
Public Delegate Sub DealProgress(ByVal num As Int32)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.isReady = False Then
MessageBox.Show("Not ready for calculation,Please have a check.", "Sorry...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Exit Sub
End If
If mythread.IsAlive Then
MessageBox.Show("One mission is in process...", "Sorry to say:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
init()
Me.TxtConsole.AppendText("Write to:" + strWrite + strNextLine)
start()
Me.StatusStrip1.Items(1).Text = "Calculating..."
End If
End Sub
Sub init()
Me.TxtConsole.Clear()
r0 = Val(Me.Txtr0.Text)
ra = r0
w = Val(Me.Txtw.Text)
beta = Val(Me.Txtbeta.Text)
g = Val(Me.txtg.Text)
steps = Val(Me.Txtsteps.Text)
interval = Val(Me.Txtwt.Text)
gw = New Double() {0, 0, 0, 0, 0, 0, 0, 0, 0}
Me.ProgressBar1.Maximum = steps
Me.btncancel.Enabled = True
End Sub
Private Sub start()
AddHandler sne.returnStep, AddressOf Me.returnstephandler
AddHandler sne.returnWrite, AddressOf Me.returnprinthandler
AddHandler sne.returnComplete, AddressOf Me.returncompletehandler
mythread.Start()
btncancel.Enabled = True
btnpause.Enabled = True
candraw = True
End Sub
Private Sub returnstephandler(ByVal num As Int32)
Invoke(New DealProgress(AddressOf OnshowProgress), num)
End Sub
Private Sub returnprinthandler(ByVal str As String)
Invoke(New ShowInformation(AddressOf OnshowInformation), str)
End Sub
Private Sub returncompletehandler()
Invoke(New DealComplete(AddressOf OndealComplete))
End Sub
Private Sub OndealComplete()
Me.StatusStrip1.Items(1).Text = "Completed."
candraw = False
End Sub
Private Sub ClearData()
itfArray.Clear()
ReDim field(0, 0)
ReDim rho(0, 0), u(0, 0), v(0, 0), flag(0, 0), eps(0, 0), mass(0, 0)
End Sub
Private Sub OnshowInformation(ByVal str As String)
Me.TxtConsole.AppendText(str)
End Sub
Private Sub OnshowProgress(ByVal num As Int32)
If candraw And showon Then
si.redraw(num)
End If
currentStep = num
If num > tt Then
tt += steps / 100
Me.ProgressBar1.Value = num
End If
End Sub
Public Sub New()
' 此调用是 Windows 窗体设计器所必需的。
InitializeComponent()
' 在 InitializeComponent() 调用之后添加任何初始化。
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
init()
End Sub
Private Sub Txtsteps_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtsteps.Validated
validateInt(Me.Txtsteps)
End Sub
Private Sub Txtwt_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtwt.Validated
validateInt(Me.Txtwt)
End Sub
Private Sub validateInt(ByRef txt As System.Windows.Forms.TextBox)
If IsNumeric(txt.Text) Then
txt.Text = Math.Abs(Math.Floor(Val(txt.Text)))
If txt.Text <> "0" Then
Me.ErrorProvider1.SetError(txt, "")
Exit Sub
End If
End If
Me.ErrorProvider1.SetError(txt, "Must be a positive integer!")
End Sub
Private Sub validateNum(ByRef txt As System.Windows.Forms.TextBox)
If IsNumeric(txt.Text) Then
txt.Text = Math.Abs(Val(txt.Text))
If txt.Text <> "0" Then
Me.ErrorProvider1.SetError(txt, "")
Exit Sub
End If
End If
Me.ErrorProvider1.SetError(txt, "Must be a positive number!")
End Sub
Private Sub validateNum0(ByRef txt As System.Windows.Forms.TextBox)
If IsNumeric(txt.Text) Then
txt.Text = Math.Abs(Val(txt.Text))
Me.ErrorProvider1.SetError(txt, "")
Exit Sub
End If
Me.ErrorProvider1.SetError(txt, "Must be a number!")
End Sub
Private Sub Txtbeta_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtbeta.Validated
validateNum0(Me.Txtbeta)
End Sub
Private Sub Txtr0_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtr0.Validated
validateNum(Me.Txtr0)
End Sub
Private Sub Txtw_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtw.Validated
validateNum(Me.Txtw)
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
If mythread.IsAlive Then
Try
mythread.Abort()
Catch
End Try
btncancel.Enabled = False
btnpause.Enabled = False
Me.ProgressBar1.Value = 0
Me.ClearData()
Me.isReady = False
End If
End Sub
Private Sub btnpause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpause.Click
If mythread.IsAlive Then
If mythread.ThreadState = Threading.ThreadState.SuspendRequested Or mythread.ThreadState = Threading.ThreadState.Suspended Then
mythread.Resume()
btnpause.Text = "Pause"
Exit Sub
End If
mythread.Suspend()
btnpause.Text = "Continue"
End If
End Sub
Private Sub llread_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles llread.LinkClicked
If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.isReady = False
Me.ClearData()
ReadData.ReadFromFile(Me.OpenFileDialog1.FileName)
Me.StatusStrip1.Items(0).Text = DataDescription
Me.StatusStrip1.Items(1).Text = "Ready."
Me.isReady = True
candraw = True
If strWrite = "" Then
strWrite = Me.OpenFileDialog1.FileName
Dim k As Int16
k = strWrite.LastIndexOf("\")
strWrite = strWrite.Substring(0, k + 1)
End If
End If
End Sub
Private Sub Llbwriteto_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles Llbwriteto.LinkClicked
If Me.FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strWrite = Me.FolderBrowserDialog1.SelectedPath
If strWrite.LastIndexOf("\") <> (strWrite.Length - 1) Then
strWrite = strWrite + "\"
End If
End If
End Sub
Private Sub Btnshow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnshow.Click
If showon = False And candraw Then
si = New MyGraphic
si.Show()
showon = True
End If
End Sub
Private Sub BtnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAbout.Click
Dim sw As New MyAboutBox
sw.Show()
End Sub
Private Sub txtg_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtg.Validated
validateNum0(Me.txtg)
End Sub
Private Sub ProgressBar1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProgressBar1.MouseHover
Me.ToolTip1.Show(currentStep, Me.ProgressBar1)
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Dim nn As New Status(Me)
nn.Show()
Me.Visible = False
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -