|
-
Jun 24th, 2021, 09:38 PM
#1
Thread Starter
Addicted Member
[RESOLVED] {Vb.net] Convert toplevel form to low level
I'm creating a form inside the controls.add(myform) function but it says my form is toplevel because I'm calling a form created from the menu above but I want to know how to transform a toplevel form into just a form, and how to deploy some other
is there any way to call notepad.exe as a control without MDI?
-
Jun 24th, 2021, 10:21 PM
#2
Re: {Vb.net] Convert toplevel form to low level
Firstly, you seem to be asking two unrelated questions. What does Notepad have to do with forms inside forms? Notepad is an external application that was not created with Windows Forms so there is no form involved in that case. Please be clear about what it is you're asking and, if you have two unrelated questions, ask them in separate threads.
-
Jun 24th, 2021, 11:31 PM
#3
Thread Starter
Addicted Member
Re: {Vb.net] Convert toplevel form to low level
 Originally Posted by jmcilhinney
Firstly, you seem to be asking two unrelated questions. What does Notepad have to do with forms inside forms? Notepad is an external application that was not created with Windows Forms so there is no form involved in that case. Please be clear about what it is you're asking and, if you have two unrelated questions, ask them in separate threads.
Yes there are two questions because I am also trying to run an .exe that is made in .net to be called like a notepad made in .net.
but the focus itself is me.controls.add(myform)
how to turn a form created in the project into a low level form since basically when I say on my FORM1.vb:
Private Sub Form1_Load(sender As Object, and As EventArgs) Handles MyBase.Load
Dim As New Form window
window.TopLevel = False
window.Visible = True
Me.Controls.Add(window)
window.BringToFront()
End Sub
But when I create a form by visual studio it says when I try to say that my FORM2.vb is low level:
Form2.TopLevel = False
it says the following error:
A higher level form cannot be called by an equal.
and trying to declare that FORM2.TopLevel is false it doesn't let it say it's an error.
Do you know any function that declares the form created by VS2019 as low level?
-
Jun 25th, 2021, 12:07 AM
#4
Re: {Vb.net] Convert toplevel form to low level
Before getting into the issue, we ought to establish whether you should be using forms at all. I have seen a lot of people try to host one form inside another and have problems when they shouldn't be doing that in the first place. Generally speaking, you should be using user controls rather than forms. You add a user control to your project and design it in pretty much the same way as you do a form. Once it's compiled, you use the user control just like any other control. It's even added to the Toolbox automatically. This avoids any issues with hosting forms completely. Is there any reason that you can't create a user control and host that in your parent form rather than trying to host another form?
Last edited by jmcilhinney; Jun 25th, 2021 at 12:27 AM.
-
Jun 25th, 2021, 12:17 AM
#5
Thread Starter
Addicted Member
Re: {Vb.net] Convert toplevel form to low level
 Originally Posted by jmcilhinney
Before getting into the issue, we ought to establish whether you should be suing forms at all. I have seen a lot of people try to host one form inside another and have problems when they shouldn't be doing that in the first place. Generally speaking, you should be using user controls rather than forms. You add a user control to your project and design it in pretty much the same way as you do a form. Once it's compiled, you use the user control just like any other control. It's even added to the Toolbox automatically. This avoids any issues with hosting forms completely. Is there any reason that you can't create a user control and host that in your parent form rather than trying to host another form?
Yes I'm already using user control, but for another thing and really they do what you say. But I need to use forms because it has to be a member of form1 and it will be programmable I'm creating a simple programming template in a mini language where you add controls and basic functions in script and the form is generated with these, and it's universal .NET base .
And the user controls are used in the project toolbox where it is a simulator, as if it were a mini OS that runs the user script and can be customized in realtime.
-
Jun 25th, 2021, 01:12 AM
#6
Re: {Vb.net] Convert toplevel form to low level
I just created a new project and did this:
vb.net Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim f As New Form
f.TopLevel = False
f.SetBounds(0, 0, ClientSize.Width \ 2, ClientSize.Height)
f.Parent = Me
f.Show()
Dim f2 As New Form2
f2.TopLevel = False
f2.SetBounds(ClientSize.Width \ 2, 0, ClientSize.Width \ 2, ClientSize.Height)
f2.Parent = Me
f2.Show()
End Sub
It worked exactly as you would expect. You should give that a try.
-
Jun 25th, 2021, 02:38 AM
#7
Thread Starter
Addicted Member
Re: {Vb.net] Convert toplevel form to low level
 Originally Posted by jmcilhinney
I just created a new project and did this:
vb.net Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim f As New Form
f.TopLevel = False
f.SetBounds(0, 0, ClientSize.Width \ 2, ClientSize.Height)
f.Parent = Me
f.Show()
Dim f2 As New Form2
f2.TopLevel = False
f2.SetBounds(ClientSize.Width \ 2, 0, ClientSize.Width \ 2, ClientSize.Height)
f2.Parent = Me
f2.Show()
End Sub
It worked exactly as you would expect. You should give that a try.
I'm already doing this, actually I want to transform a form made automatically by the visual studio into TopLevel = False and so far I haven't been able to be digging through the form's xml and nothing.
because I created a form normally by visual studio through the menu and wanted to make this toplevel = false because it would make it easier to edit, but your project is much better than mine, I'll amplify mine.
Last edited by LiwisJames; Jun 25th, 2021 at 02:57 AM.
-
Jul 11th, 2021, 10:51 PM
#8
Thread Starter
Addicted Member
Re: {Vb.net] Convert toplevel form to low level
Thanks to everyone I solved it in a simpler way without creating a new control, well it's easy:
I created a form 2 by visual studio, then opened form2.Designer.vb
and went to the following line of code:
Me.ResumeLayout(False)
and above it I inserted the following line:
Me.SetTopLevel(False)
Me.ResumeLayout(False)
after that I put the following result:
Me.SetTopLevel(False)
Me.ResumeLayout(False)
Me.Show()
So returning to form1 instead of calling an mdi child I put the following:
Private Sub Form1_Load(sender As Object, and As EventArgs) Handles MyBase.Load
'this call form two as MDI child (control)
Me.controls.add(form2)
form2.show()
End sub
-
Jul 11th, 2021, 10:56 PM
#9
Re: {Vb.net] Convert toplevel form to low level
That's a great solution... until you change something in the designer and all that code gets blown away. If only they put a comment in that designer file to warn you about that. Oh look, they do.
If you want to do something when the form is created then add your own constructor that calls InitializeComponent (that will be generated automatically if you do it properly) and then put your code in there, where the comment tells you to. That way, no changes will be made to your code because you make a change in the designer. Why couldn't you just do that and set the TopLevel property to False, as I already showed you how to do? You do know that an object can set its own properties, right?
-
Jul 13th, 2021, 04:33 PM
#10
Thread Starter
Addicted Member
Re: {Vb.net] Convert toplevel form to low level
 Originally Posted by jmcilhinney
That's a great solution... until you change something in the designer and all that code gets blown away. If only they put a comment in that designer file to warn you about that. Oh look, they do.
If you want to do something when the form is created then add your own constructor that calls InitializeComponent (that will be generated automatically if you do it properly) and then put your code in there, where the comment tells you to. That way, no changes will be made to your code because you make a change in the designer. Why couldn't you just do that and set the TopLevel property to False, as I already showed you how to do? You do know that an object can set its own properties, right?
It's true every time I compile or change something everything I created disappears from the designer so I copy the file and only rewrite it when it's really necessary.
Well the method you showed it works if I call my second form as one created by code see.
Code:
CODE:
Dim newform as new form2
newform.settoplevel = false
me.controls.add(newform)
newform.show()
But I'm still creating the functions in form2 and while it's not complete it doesn't make additional sense to my first form by code so I'm calling it directly. Your solution makes perfect sense and I'm grateful and I'll use it, but at the current stage of the project there's no need.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|