Click here to Skip to main content
16,014,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have added multiple form to a penal. now i need to get the active form name from penal
i have use this code to add forms to the penal.

Form1.Penal1.Controls.Add(form1)

now i want to get the active form in the penal.
please help me.

What I have tried:

i have no idea how to get the active form
Posted
Updated 13-Apr-21 11:17am
Comments
CHill60 16-Mar-16 5:38am    
What is a penal?
If you mean a Panel on a Form (a form cannot be on a panel) then try Panel1.Parent.Name
kasunthilina 16-Mar-16 23:09pm    
i have a MDI form with MDI child forms. i was trying to add chart in the MDI form. but when MDI child form is open the chart is come to forword and the open child form gose to back. by using penal i have solved the problem but cannot find the active form forom the penal.
CHill60 17-Mar-16 5:22am    
Try to be more precise when describing your problem.
Chart and Panel are controls that go onto a Form. A child Form cannot "go to the back" of a Chart or a Panel, only another Form.
How many forms do you have open? The MDI Parent Form plus one MDI Child Form? Or more than one MDI Child Form?
What event on the Panel are you trying to use to find the "Active" form?
By "Active" do you mean the form that currently has Focus?
kasunthilina 21-Mar-16 0:16am    
yes. im trying get currently focus form from the penal. just like get currently focus MDI child form.
for MDI i use this code to get currently focus form.

'This is the code in MDI form Save Button
Dim active_form_name As Object = Me.ActiveMdiChild
active_form_name.CurrentFocusformSaveFunction() 'CurrentFocusformSaveFunction is the child form save function.

purpose is:
in my project each form have a save function and im trying to use MDI form save button to preform active form's save function. now i need to do the same inside the penal.
CHill60 21-Mar-16 4:04am    
Assuming you mean "Panel" - what event do you think you could use?
Where is this Panel?
How is the Panel relevant?
You are not making your problem any clearer

1 solution

You cannot directly get an active form inside a panel as the panel would not have loaded at the beginning of the program and will through a Null Exception. Instead you can use the following to gain access of the form inside your panel.

For Each FormName as Form In Panel1.Controls
If FormName.Name = "FrmName" Then
'Do Something
End If
Next

Or you can access any control (not only forms but any other objects) like the following

For Each ControlName as Control In Panel1.Controls
If ControlName.Color = "Black" Then
'Do Something
End If
Next
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900