How to check MDI child form is already opened - vb.net

i have an application that contain MDI parent and child form. I have to show the different type of data in grid. so i created a common form with grid and pass the dataset. now how do i check the specific data form is already opened or not. here my code.
Public Function FindMdiChild(ByVal Title As String) As Boolean
If Application.OpenForms.Count = 0 Then Exit Function
For Each t As Form In Application.OpenForms
If t.Text.ToString = Title.ToString Then
t.Activate()
Return True
End If
Next
End Function
The problem is some times its stuck on this specific line "If t.Text.ToString = Title.ToString Then".
please help me to resole this issue.

Related

Show/Hide FileExplorer in Access Form

I've been trying to use a combobox to show/hide a PDF viewer that I've added into a MS Access form.
When I use the form_current event, then the form only updates when I move between the data entries. When I use the afterupdate event, the same code does nothing at all.
Does anyone have a fix? The code I have used is below, which I have tried both the AfterUpdate event for the Browser and the Form_Current event for the whole form
Private Sub PDFT900_AfterUpdate() / Private Sub Form_Current()
Dim ESNComb As String
ESNComb = Me.ESNCombo.Column(1)
If ESNComb Like "9????" Then
Me.PDFT900.Visible = True
Else
Me.PDFT900.Visible = False
End If
End Sub
In the code below, I'm hiding and showing the Adobe PDF Reader ActiveX control named, "AcroPDF0". Since the Like operator returns true on an expression match and false on a mismatch or no match, it serves as a simple boolean switch for the visible property. I've used the (*) wild card instead of (?). It works {shrug}. See demonstration images below.
Private Sub ESNCombo_AfterUpdate()
'AcroPDF0.Visible = ESNCombo.Text Like "P*"
AcroPDF0.Visible = ESNCombo.Column(0) Like "P*"
AcroPDF0.src = acroPDFOSrc
End Sub
ComboBox List Items
"File Browser" Selected in ComboBox
Toggled ComboBox back to "PDFT900"

Having trouble with show/hide/visible in VB .net It only works the first time

I have a multi form application I'm close to finishing, but I have a HUGE problem.
I need to keep a main form open, basically a communications task, that opens other forms that display general status and asks for various user input. The problem is that when any form is requested either automatically by the status from the communications engine, or via user button press. The first time a form is requested there is no problem, however the second time any given form is requested, it shows on the windows task bar, but will not open on the screen. All form switching in this application is handled by the same routine.
NOTE: The form named "WEDGE_MENU_SCREEN" is the form that stays open and active, only one other form should be active at any time.
Here is the code.
Public Function GoToForm(Requested_form As Form) As Boolean
'in a multi form app, we only want ONE form active on screen at any given time.
'all screen change requests should come from the same operating thread
Dim Not_found_form As Boolean = True
' Dim frm As Form
Dim formNames As New List(Of String)
Dim xformNames As New List(Of String)
'get a list of active forms running under this main thread LESS the static one
For Each currentForm As Form In Application.OpenForms
If currentForm.Name <> "WEDGE_MENU_SCREEN" Then
formNames.Add(currentForm.Name)
End If
Next
'from that list create another less the requested in the case that the requested form is already up
For Each currentFormName As String In formNames
If currentFormName <> Requested_form.Name Then
xformNames.Add(currentFormName)
End If
Next
'if the second list is not empty
If xformNames.Count > 0 Then
'hide all active forms in the second list
For Each currentFormName As String In xformNames
Application.OpenForms(currentFormName).Visible = False
Application.OpenForms(currentFormName).Opacity() = 0
Next
End If
'then activate the requested form
Requested_form.Visible = True
Requested_form.Opacity = 1
Return True
End Function
FURTHER NOTE: I have tried the following as well
Application.OpenForms(currentFormName).Hide()
with Requested_form.Show()
ALSO
Application.OpenForms(currentFormName).Close()
with Requested_form.Show()
Any help would be greatly appreciated.
-Jim
Maybe if you make the logic a bit simpler it would help. The 3 loop can be combined into one.
For Each currentForm As Form In Application.OpenForms
If currentForm.Name <> "WEDGE_MENU_SCREEN" AndAlso currentForm.Name <> Requested_form.Name Then
currentForm.Visible = False
currentForm.Opacity() = 0
End If
Next

How to find parent form name ? vb.net

I want the name of the parent form in vb.net . Where I came from.
Like
`if parent-form.name = 'something' then
do something.
else
do something else.`
It's not a MDI form.
Edit:
I want exactly like that:
parentForm.vb:
chidform.showdialog()
In childform there is textbox
childForm.vb:
if parentForm is parentForm1 than fill textbox.text = 2
else fill textbox.text = 3
You will understand what I want.
Assumption: I worked under the assumption that this is an MDI application and you would want to read the name of the top parent and for reasons unknown you cannot refer to a singleton reference to the form (for instance current form runs from a library).
I wrote an extension mode to get the top parent since the immediate parent of an MDI child window is an MDIClient without a name.
<Extension>
Public Function GetTopParent(currentControl As Control) As Control
Dim parent As Control = Nothing
Do While currentControl IsNot Nothing
parent = If(currentControl.Parent, parent)
currentControl = currentControl.Parent
Loop
Return parent
End Function
Then when you need the name of the parent you can do the following.
MessageBox.Show(Me.GetTopParent().Name) ' This just shows the name but you can do your comparison here.

How do I save textboxes with tabs depending which tab is open?

I am trying to create a document writer in vb.net
So I decided to add a tab control, so I can create a new tab when I press a button. I would like to save the text in the tab that is open. I created a function the returns the text depending on what tab is open, but that only works for the two default tabs. I don't know how I would save if I've created a new tab.
The function to get the text is this:
Public Function getText() As String
If tabPage1.Visible = True Then
Return mainText.Text
ElseIf tabPage2.Visible = True Then
Return textBox1.Text
End If
End Function
I've done some research online, I've even looked at SharpDevelop's source code and I couldn't find anything.
Thanks in advance!
EDIT :
Public Sub setText(Byval value As String)
If tabPage1.Visible = True Then
mainText.Text = value
ElseIf tabPage2.Visible = True Then
textBox1.Text = value
End If
End Sub
Does anyone know how I would do an open feature determined on what tab is open (as before.)
If I understand you correctly, you are trying to have a textbox in each of your tabPages generated dynamically. If this is the case you could generalize your GetText function with this code
Function GetText() As String
If tabControl1.SelectedTab IsNot Nothing Then
Return tabControl1.SelectedTab.Controls.OfType(Of TextBox)().First().Text
End If
End Function
This requires that you have at least one textbox in each page (and your TabControl is named tabControl1). The SelectedTab property (if not nothing) is the current tabPage displayed by your tabControl

VB.NET Call Sub of another form

I know, that there are many questions related to this, but still I cannot find a workable solution.
Usually, it would work like this: A form creates an instance of another form in it's container like this:
Dim PolInstIn As New SubForm1
Private Sub LoadDetail()
PolInstIn.TopLevel = False
PolInstIn.Name = "Sub From"
PolInstIn.FormBorderStyle = Windows.Forms.FormBorderStyle.None
PolInstIn.Dock = DockStyle.Fill
Me.GroupBox6.Controls.Add(PolInstIn)
PolInstIn.Show()
End Sub
Then it's easy to call a Public Sub from the sub form like this:
Call PolInstIn.MyPublicSubInSubForm1()
However, this doesn't work for me in this case. When I run MyPublicSubInSubForm1() it doesn't throw any error, but does no action. If I write a value to SubForm1 textbox and read it back, it reads, but I don't see it on the screen, so I suspect it is written to some other accidental instance.
I suspect it is because my parent form is also an instance of an form created in very similar way like SubForm1. Basically the ParentForm is a form loaded into tabPage and SubForm1 is a module loaded into ParentForm. It can exist in many copies (tabs).
Could you point to any simple solutions?
Regards,
Libor
I see this question got a lot of views, so here is an answer.
1) No visual response of child form (only results) - this could have happened if I created more then 1 instances of the form. The example is just an example, but if one use it (accidentally) this way, it may result in new definition of a child form every time (and consequent symptoms like the ones described). In practice, I split form loading from loading data into to the form (done by a public sub in that form).
2) If you want also a back reference (to i.e. parent grid form), define a Public ParentFormGrid as GridName (note ParentForm is a reserved name) and on loading a child form, set
PollInstIn.ParentFormGrid = Me
This way you can alway asccess the parent form, i.e. reload the grid when you save changes on a line edited in child form.
make Private Sub LoadDetail() to a public :
Public Sub LoadDetail()
It work on my project. Hopely its what you want
Dim PolInstIn As New SubForm1
Private Sub LoadDetail()
PolInstIn.Name = "Sub From"
PolInstIn.Show()
PolInstIn.TopLevel = False
PolInstIn.FormBorderStyle = Windows.Forms.FormBorderStyle.None
PolInstIn.Dock = DockStyle.Fill
PolInstIn.Update()
PolInstIn.Refresh()
Me.GroupBox6.Controls.Add(PolInstIn)
End Sub