Hello i need help about hide and show form . Can anyone provide code to write for hide form and show other form thx you
KillerOfDN -7 Junior Poster in Training
Form1.Hide
Form2.Show
?
ssharish2005 62 Posting Whiz in Training
OK, this question seems a pretty simple at first instance, but there are lot many things which need to be considered while coding this part. There are several ways to solve this problem. One of simple way ways is to coding this on some event, like a button click on something like that:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
Form2.Show()
End Sub
This is something which you can find it very easy. But you might also try adding the same codei the from1.load event. This code donst work as expected. Why?? Becase the form1 seems to the parent thread there and you cant close it or your cant hide .If close the form1 you are closing the whole project. You do a hide by just hiding it on to the system tray.
This is something which I did know already. Being said that I not windows programmer!
ssharish
Jx_Man 987 Nearly a Senior Poster Featured Poster
To show next form without hide previous form :
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Test As New Form4
Test.Show()
End Sub
To show next form with hide previous form :
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Test As New Form4
Test.Show()
Me.Hide()
End Sub
To show next form with close previous form :
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Test As New Form4
Test.Show()
Me.Dispose(False)
End Sub
ssharish2005 62 Posting Whiz in Training
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Test As New Form4
Test.Show()
Me.Dispose(False)
End Sub
Wouldn this made the code system to be still running even after closing the form2??? Since the form1 has been disposed. For it i think it should disposed when you close the form2 but it dosn't, which is a problem!
ssharish
sisi 0 Light Poster
Hi thank you alot for providing me good information . Now i can displaycourseregistrationlist frm but i have one problem with displaying all the information in new frm called courseregistrationlist . Now i am pasting you courseregister form coding where the display botton has no coding . SO can you help me out with displaycourse botton coding to display courseregtrationlist frm with all infomation of courseregister form to courseregistrationlist frm .
Option Strict On
Imports System.IO
Public Class frmcourseregistration
Private m_studentid As New Student()
Private m_filepath As String = Application.StartupPath & _
"\student.txt"
Private m_filepath2 As String = Application.StartupPath & _
"\Course.txt"
Private m_filepath3 As String = Application.StartupPath & _
"\Courseregistration.txt"
Private Sub Btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnsearch.Click
Dim line As String
Dim fields() As String
Dim objsr As StreamReader
objsr = New StreamReader(m_filepath)
line = objsr.ReadLine()
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
If (fields(0) = txtStudentID.Text) Then
txtFirstName.Text = fields(1)
txtLastName.Text = fields(2)
objsr.Close()
Exit Sub
Else
line = objsr.ReadLine()
End If
Loop
objsr.Close()
MessageBox.Show("Student account not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Dim answer As Integer
answer = MessageBox.Show("Do you want to exit?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
If answer = vbYes Then
Application.Exit()
Else
End If
End Sub
Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
Txtstudentid.Text = ""
txtfirstname.Text = ""
Txtlastname.Text = ""
End Sub
Private Sub Btnregister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnregister.Click
'If (Txtstudentid.Text.Length <> 7) Then
' MessageBox.Show("Studentid must be a 7-digit number", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
' Txtstudentid.Focus()
' Exit Sub
'End If
Dim answer As Integer = 0
'Dim line As String
'Dim fields() As String
'Dim objsr As IO.StreamReader
'If File.Exists(m_filepath) Then
' objsr = New StreamReader(m_filepath)
' line = objsr.ReadLine()
' Do Until (line Is Nothing)
' fields = line.Split(Convert.ToChar(","))
' If (fields(0) = Txtstudentid.Text) Then
' MessageBox.Show("StudentID already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
' Txtstudentid.Focus()
' objsr.Close()
' Exit Sub
' Else
' line = objsr.ReadLine()
' End If
' Loop
' objsr.Close()
'End If
'With m_studentid
' .StudentID = CInt(Int(Txtstudentid.Text))
' .FirstName = CStr(txtfirstname.Text)
' .LastName = CStr(Txtlastname.Text)
'End With
answer = MessageBox.Show("Do you really want to register ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
If answer = vbYes Then
Dim objSw As New StreamWriter(m_filepath3, True)
For i As Int16 = 0 To CShort(lstCourseSelected.Items.Count - 1)
objSw.WriteLine(CInt(Txtstudentid.Text) & "," & lstCourseSelected.Items.Item(i).ToString)
Next
objSw.Close()
MessageBox.Show("The register account has been created successfully", "Record saved", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Else
End If
End Sub
Private Sub frmcourseregistration_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim line As String
Dim fields() As String
Dim objsr As StreamReader
objsr = New StreamReader(m_filepath2)
line = objsr.ReadLine()
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
lstCourseList.Items.Add(fields(0))
line = objsr.ReadLine
Loop
objsr.Close()
End Sub
Private Sub Btnselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnselect.Click
If lstCourseList.SelectedIndex <> -1 Then
lstCourseSelected.Items.Add(lstCourseList.SelectedItem)
Else
MessageBox.Show(" PLease select a course from The Course List", "confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
End If
End Sub
Private Sub btnremove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremove.Click
If lstCourseList.SelectedIndex <> -1 Then
lstCourseSelected.Items.Remove(lstCourseList.SelectedItem)
Else
MessageBox.Show(" PLease select a course from The Course List", "confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
End If
End Sub
Private Sub Btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btncancel.Click
Dim line As String
Dim fields() As String
Dim objsr As StreamReader
objsr = New StreamReader(m_filepath)
Dim objSw As New StreamWriter(Application.StartupPath & _
"\Temp.txt", True)
line = objsr.ReadLine()
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
If (fields(0) = Txtstudentid.Text) Then
MessageBox.Show("Do you want really want to cancel your student information", "cancel", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
Else
objSw.WriteLine(fields(0) & "," & fields(1) & "," & fields(2))
End If
line = objsr.ReadLine()
Loop
objsr.Close()
MessageBox.Show("Student information has been cancel successfully", "cancel", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
My.Computer.FileSystem.DeleteFile(m_filepath3)
objSw.Close()
My.Computer.FileSystem.RenameFile(Application.StartupPath & _
"\Temp.txt", "Courseregistration.txt")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End Sub
End Class
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.