i want to pass data from my FrmArmy to FrmMain and i use login form to open FrmMain..
Me.Hide
Dim FMain As New FrmMain
FMain.ShowDialog()
then i open FrmArmy from FrmMain..
Dim FArmy As New FrmArmy
FArmy.ShowDialog()
BtnArmy.Enabled = False
and what i want here is.. how to change BtnArmy in FrmMain to
BtnArmy.Enabled = True
when FrmArmy Closed
This Code Does not working..
FrmMain.BtnArmy.Enabled = True
Thanks.
FrmMain is a class, you need to disable it on the instance FMain
Dim FArmy As New FrmArmy
Me.BtnArmy.Enabled = False ' disable on show
FArmy.ShowDialog()
Me.BtnArmy.Enabled = True ' reenable after it hides (?)
We have no context, I assume this is in a Button Click event. This may not be needed, because they cant click stuff on other forms while the dialog is open, anyway.
But you have another issue: Dialogs are resources which are not automatically disposed. If these are called a lot, you could leak resources:
Using fArmy As New FrmArmy
Me.BtnArmy.Enabled = False ' disable on show
FArmy.ShowDialog()
Me.BtnArmy.Enabled = True ' reenable after it hides (?)
End Using ' auto dispose of Dialog
Related
I've got a form, frmEmail which is called using f.ShowDialog (Where f is an instance of frmEmail).
How can I, when closing the form, open an instance of frmOrder but set fOrder.MdiParent = frmMain?
frmMain is my MDI form, frmOrder is a form I need to open, and frmEmail is the form I'm opening it from.
My code at the moment is
revoke = True
Dim f As New frmOrder(con, False, False, , orderNum)
f.MdiParent = ' Not sure what to put here?
f.Show()
Me.Close()
Do I need to pass in a variable that stores reference to frmMain? Is there another way to do it?
Obviously I can't use f.MdiParent = Me.MdiParent, because as I mentioned before, frmEmail is opened using f.ShowDialog so has no MdiParent.
You can still open a form in ShowDialog and set the "Owner" property.
Where you're opening frmEmail, instead of opening it like using f.ShowDialog(), use f.ShowDialog(Me.MdiParent) (If your MDI form is the parent of the form where you open frmEmail, otherwise just tweak it as relevant).
That way, when opening frmOrder, you set the MdiParent property to be frmEmail's owner property.
Dim f As New frmOrder(con, False, False, , orderNum)
f.MdiParent = Me.Owner
f.Show()
I have a custom form which is open as Form.ShowDialog()
This form acts as a confirmation form. It asks a question whether you want to accept or decline the previously entered input in ComboBox & TextBox.
If you click OK, the input is saved into Excel File.
If you click Cancel, the input is not saved.
The problem I am having is that:
When you click cancel. The form.ShowDialog() is closed. (Which is fine.)
But when the form.ShowDialog() is open again. It retains the focus on the Cancel Button. So if you try to confirm the entry with "Enter" key, you cancel it instead.
My question is. Why does the Form.ShowDialog() retain the focus on the buttons after closing?
The Form.ShowDialog() has accept button "OK" [tabindex = 1], and cancel button "Cancel" [tabindex = 2] which are set to Enter key, and Esc key.
(To note again)The focus of the buttons remains after closing the form.
The portion of the code using the Dialog:
ElseIf ComboBoxBP.SelectedItem = ComboBoxBP.SelectedItem And TextBoxBP.Text = TextBoxBP.Text Then
form.Label1.Text = ComboBoxBP.SelectedItem
form.Label2.Text = TextBoxBP.Text
form.ShowDialog()
If form.DialogResult = Windows.Forms.DialogResult.Yes Then
SiE()
ElseIf form.DialogResult = Windows.Forms.DialogResult.No Then
LabelBPBot.Text = "Canceled."
End If
End If
When you use .ShowDialog() closing the form does not dispose of it as with a normal form. This is because once a Dialog "closes" it actually just hides so we can get info from it before it actually goes away.
The second issue is that forms are classes (it says so at the top of every one of them:)
Public Class Form1
...
So, instances of them should be created. VB allows Form1.Show or Form1.ShowDialog() to use a "default instance" and it is a shame that it does.
Combine these 2 tidbits and what you have is a case where the form you showed last time is still around in the same state as when you last used it, including the last focused control. You are only using a "fresh copy" of the form the first time, after that, you are just reusing the old instance. Remedy:
Using Dlg As New Form1 ' form1 is the class, dlg is the instance
... do stuff
Dim res As DialogResult = Dlg.ShowDialog()
If res = Windows.Forms.DialogResult.OK Then
'... do stuff
End If
End Using ' dispose of Dlg
Eventually, you will run into similar issues using the default instance of the other forms (LForm.Show). Just Say No to Default Form instances.
this my code to open addUserform
Dim adduser As New frmadduser
adduser.MdiParent = Me
adduser.Visible = True
when user open ChangePassword form
Dim changepassword As New frmchangepassword
changepassword.MdiParent = Me
changepassword.Visible = True
I want to ask, how to close current form automatically after user open changepassword form. Iam use me.close, that's code not work.Thankyou
How you will close current form? if you are dealing with MDI Parent form , then it will not close. please make sure that which form you wanna close
for example if you are on Form1 and you want to open Form2 then you can do following steps.
form2.Mdiparent=MDIParent
form2.Show()
Me.Dispose()
I have an issue that is really starting to do my head in...
My application has a ListView control that is populated with items. When you double click on an item it creates a new instance of a form. It then creates a new panel and adds the form to the panel. However, for the life of me I cannot work out how to close the form inside the panel.
Inside my DoubleClick event:
Dim frm As New frmStorePage(_store.Code, _store.Name)
'Create a new panel with the store page
Dim pnl As New Panel
pnl.Name = _store.Code
pnl.BackColor = SystemColors.Control
pnl.Size = New Size(1522, 892)
pnl.Location = New Point(3, 3)
frm.TopLevel = False
frm.Name = _store.Code
pnl.Controls.Add(frm)
frm.Show()
pnlStores.Controls.Add(pnl)
pnl.BringToFront()
...
Inside my Close event:
Dim panel As Panel = CType(pnlStores.Controls.Find(lsvOpenStoreList.SelectedItems(0).Name, False)(0), Windows.Forms.Panel)
For Each control As Control In panel.Controls
If TypeOf control Is Windows.Forms.Form And control.Name = panel.Name Then
control.Dispose()
End If
Next
pnlStores.Controls.Remove(panel)
panel.Dispose()
pnlStoreList.BringToFront()
...
I have also tried declaring my form as a global variable but still cannot seem to close it.
The form has a number of timer events that get stopped when the form closes, however, even though the panel gets closed, the timer events are still running. It seems that the form is still active in the background.
Any help would be appreciated.
Due to a silly oversight, I failed to see that the code I was using to dispose of all the controls and close the form was not in the FormClosing event, but actually under a Command Button called Close. Therefore, my closing procedures were never getting called and thus the timers remained active.
Thanks
Hoping someone can help me with this. I have two separate but related Forms, one of which contains a WebBrowser control. The user fills out some information on Form 1 and clicks a button with the following code:
If Form2Shown = False Then
Dim memoscreen As New Form2
Form2Ref = memoscreen
memoscreen.show()
Form2Shown = True
memoscreen.TopMost = OptionOnTop
Else
Dim memoscreen As Form2
memoscreen = Form2Ref
memoscreen.TopMost = OptionOnTop
memoscreen.QuickRefresh()
End If
The QuickRefresh sub in Form2 is the method that navigates. It is called both when the form is loaded as well as manually in the code above:
Public Sub QuickRefresh()
Dim HM As Form1
HM = Form1Ref
Me.Text = "retrieving information..."
Me.AxWebBrowser1.Navigate("SomeValidURL")
HM.Focus()
HM.SetHugoFocus()
End Sub
The problem I'm having is that the first time QuickRefresh is called (i.e. when Form2 is loaded) the navigation is successful and the page displays fine. If I then click the button on Form1 again, the page does not change. The Text attribute and window focus does change however, so I know the method is firing.
Some things I've tried/checked:
AllowNavigation is set to True on the WebBrowser control
Have tried looping while the browser is busy while calling Application.DoEvents()
Any suggestions would be appreciated. Thanks.
From your "Internet Options dialog > General Tab > Settings Button > Check for newer version of stored page" change that option to *Every Time I visit the webpage". That setting impacts how the webbrowser control deals with the refreshing.
Use the method refresh.
browser.Navigate("http://www.google.com") : browser.Refresh()