Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling Show - vb.net

I need to show multiple labels to another form then it gives me an error here is my codes i guess I must handle the forms visibility to false thanks in advance
Public Class Form2
Public lbl As New Label
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Controls.Add(lbl)
Me.Visible = False
End Sub
End Class
for loading form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm2.Visible = True
If frm2 IsNot Nothing Then
frm2.Show(Me) 'Show Second Form
End If
End Sub

Related

How do you open an already disposed form in VB?

When I close Form2 it won’t open up again after.
I am using a button click to open up another form. Right now I just have:
Dim Form2 As New Form2
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
Form2.Show()
End Sub
Now whenever I close the form I cannot open it again.
Like this
Private MyForm2 As Form2
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
If MyForm2 Is Nothing OrElse MyForm2.IsDisposed Then
MyForm2 = New Form2
End If
MyForm2.Show()
End Sub

MDI Child form close on new open

How to close MDI Chid form when i want to open a new one.
On this way i open both of them but i want to close the previous when opening the new one.
Private Sub DostupniToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DostupniToolStripMenuItem.Click
Dim frm As New FrmDostupniZaposlenici
frm.MdiParent = Me
frm.Show()
frm.WindowState = FormWindowState.Maximized
End Sub
Private Sub DodajToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DodajToolStripMenuItem.Click
Dim frm As New frmDodajZaposlenika
frm.MdiParent = Me
frm.Show()
frm.WindowState = FormWindowState.Maximized
End Sub
I have around 10 mdi child forms.
Edit :
New code. How to prevent to open form on form. Example i want to close all other mdi forms when new form is open.
On this way if i click on 4 buttons in toolstrip i got 4 forms opened. I don't want that. If i click on button 3 i want to close the previous form and load the form3.
Private Sub DostupniToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DostupniToolStripMenuItem.Click
FrmDostupniZaposlenici.MdiParent = Me
FrmDostupniZaposlenici.Show()
FrmDostupniZaposlenici.WindowState = FormWindowState.Maximized
End Sub
Private Sub DodajToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DodajToolStripMenuItem.Click
frmDodajZaposlenika.MdiParent = Me
frmDodajZaposlenika.Show()
frmDodajZaposlenika.WindowState = FormWindowState.Maximized
End Sub
Private Sub IzmjeniToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IzmjeniToolStripMenuItem.Click
frmIzmjenaZaposlenika.MdiParent = Me
frmIzmjenaZaposlenika.Show()
frmIzmjenaZaposlenika.WindowState = FormWindowState.Maximized
End Sub
Private Sub ObrisiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ObrisiToolStripMenuItem.Click
frmObrisiZaposlenika.MdiParent = Me
frmObrisiZaposlenika.Show()
frmObrisiZaposlenika.WindowState = FormWindowState.Maximized
End Sub
Simply loop through all the open MDI child forms and close them ...
For Each f As Form In Me.MdiChildren
f.Close()
Next
To close an opened child form first, enter the following codes in the click event of the menu item, just immediately after declaring the child form.
ActiveMdiChild.Close()

Changing the background color for Form2

i have two RadioButtons one for Light Blue and the other for Ghost White and a button to show the next Form (Form2)
i want to be able to check on a Radio Button and the backcolor of form2 changes to the checked Radio Button
this is what i have on my coding so far
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
SecondForm.Show()
End Sub
Private Sub rbLightBlue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbLightBlue.CheckedChanged
If rbLightBlue.Checked Then
SecondForm.BackColor = (Color.LightBlue)
End If
End Sub
Private Sub rbGhostWhite_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbGhostWhite.CheckedChanged
If rbGhostWhite.Checked Then
SecondForm.BackColor = (Color.GhostWhite)
End If
End Sub
The problem am having is making the background color change on Form2.
Any answer for this question will be very helpful.
I am not sure what you are doing, it probably has to do with how you are creating your SecondForm, this code does work, see if it helps you narrow it down.
Public Class Form1
Dim SecondForm As Form2 = New Form2
Private Sub rbLightBlue_CheckedChanged(sender As Object, e As EventArgs) Handles rbLightBlue.CheckedChanged
If DirectCast(sender, RadioButton).Checked Then
SecondForm.BackColor = Color.LightBlue
End If
End Sub
Private Sub rbGhostWhite_CheckedChanged(sender As Object, e As EventArgs) Handles rbGhostWhite.CheckedChanged
If DirectCast(sender, RadioButton).Checked Then
SecondForm.BackColor = Color.GhostWhite
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SecondForm.Show()
End Sub
End Class

Show on hover issue

So I have a simple form with a button on it. On the form's MouseEnter event I am setting the button to visible. On the form's MouseLeave event I'm setting the button to hidden. In effect, only when you hover over the form should the button be seen. The problem is that when you put the cursor over the button it disappears. Even if the button is directly in the center of the form it still exhibits this same behavior.
Is there a solution other than putting MouseEnter/Exit events on the button and everything else inside the form?
Public Class VerticalStrip
Private Sub VerticalStrip_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
btnAdd.Visible = False
End Sub
Private Sub VerticalStrip_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter
btnAdd.Visible = True
End Sub
Private Sub VerticalStrip_MouseLeave(sender As Object, e As System.EventArgs) Handles Me.MouseLeave
btnAdd.Visible = False
End Sub
End Class
Yes; in the MouseLeave event, first check if the mouse has in fact left the form:
Public Class VerticalStrip
Private Sub VerticalStrip_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
btnAdd.Hide()
End Sub
Private Sub VerticalStrip_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter
btnAdd.Show()
End Sub
Private Sub VerticalStrip_MouseLeave(sender As Object, e As System.EventArgs) Handles Me.MouseLeave
If Not Me.ClientRectangle.Contains(Me.PointToClient(Windows.Forms.Cursor.Position)) Then
btnAdd.Hide()
End If
End Sub
End Class

Values are not populating in the Form

Using VB.Net (Windows Application)
In the form (called as FirstForm), i am using textbox, add-form Button, search button.
When i click the add-form button, it will give the new form (same as FirstForm)
Code for adding new form
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Dim SecondForm As New FirstForm
SecondForm.Show()
End Sub
Search Button Code
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
If FirstForm.Focus = True Then
FirstForm.textbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
Else
Dim SecondForm As New FirstForm
SecondForm.textbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
End Sub
The above code is working, but If i am in second Form when i click the search button and selected the value, then the value is appearing in the FirstForm textbox, it is not appearing in the SecondForm textbox.
If SecondForm is showing, the selected Value should appear in the SecondForm textbox not in the FirstForm Textbox.
How to solve this issue.
Need Vb.net code Help
Use Me - Reference variable which hold ref. of current form.
Dim frm As FirstForm
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If IsNothing(frm) OrElse frm.IsDisposed Then
frm = New FirstForm
End If
frm.Show()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Me.textbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End Sub
Using "me" will not solve the problem?? why are you referring to the form in a static way?
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
textbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End Sub