-
Please help MDI application!!
I'm working on a project that will create new windows components. (If this is possible).
I have made a button that creates new forms when clicked in the MDI container.
Now I'm just wondering if someone can figure out a code to make it so when I click a button it creates a new button on the new created form.
Please help me, much appreciated.
If your wondering about my code here it is:
Code:
Dim count1 As Integer = 0
Private Sub NewButtonToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewButtonToolStripMenuItem.Click
Dim NewButton As New Button
NewButton.Text = ("Button ") & count1
NewButton.Show()
count += Val(1)
-
Re: Please help MDI application!!
You need to add the button to the forms control array...Don't forget to set it's location and size also. And you need to add handlers as well....I am adding labels, but the code is the same for a button.
vb.net Code:
Dim lblbox As New Label
With lblbox
.Left = locx
.Top = locy
.Width = 30
.Height = 30
.BackColor = Color.White
.BorderStyle = BorderStyle.FixedSingle
.Name = "lblbox"
.Text = r.Next(0, 10)
.Tag = count
End With
Me.Controls.Add(lblbox)
AddHandler lblbox.Click, AddressOf lblbox_click
Private Sub lblbox_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(DirectCast(sender, Label).Tag)
End Sub
-
Re: Please help MDI application!!
thanks for the reply, but Im not sure that this is what Im looking for, nor did it work for me :(
what I need to know is for example:
I made the button create a new form.
Now I want my other button to add a control (such as another button) to that
previously created form.
-
Re: Please help MDI application!!
Why will that not work? Were you getting a error message? That is the code I use to create labels on a form at runtime. You can change it a little to make any control you want.
-
Re: Please help MDI application!!
Well, I'm not sure :/
It gives me an error with:
Code:
.Left = locx
.Top = locy
.Text = r.Next(0, 10)
It underlines locx and locy with blue (error) and only underlines the r in .text with blue.
And I'm not sure that you could create any other controls with this other than a label could you?
-
Re: Please help MDI application!!
locx and locy are varibles that I used to store the location of the control. You can replace them with the location that you want.
the .text = r.next(0,10) assigns a random value to the text property of the control. Since you are creating buttons, that would assign a random number between 1 and 10 and assign it to the caption of the button. You just replace the r.next(1,10) with the text you want to display on the button.
vb.net Code:
Dim NewButton as New Button
With NewButton
.left = 10 'x position of the control in pixels
.Top = 10 'y position of the control in pixels
.Width = 30
.Height = 10
.Name = "Button1"
.Text = "Click Me"
End With
me.Controls.Add(NewButton)
AddHandler NewButton.Click, AddressOf Button_click
Private Sub Button_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(DirectCast(sender, Button).Name)
End Sub
-
Re: Please help MDI application!!
Quote:
Originally Posted by
dave18
locx and locy are varibles that I used to store the location of the control. You can replace them with the location that you want.
the .text = r.next(0,10) assigns a random value to the text property of the control. Since you are creating buttons, that would assign a random number between 1 and 10 and assign it to the caption of the button. You just replace the r.next(1,10) with the text you want to display on the button.
vb.net Code:
Dim NewButton as New Button
With NewButton
.left = 10 'x position of the control in pixels
.Top = 10 'y position of the control in pixels
.Width = 30
.Height = 10
.Name = "Button1"
.Text = "Click Me"
End With
me.Controls.Add(NewButton)
AddHandler NewButton.Click, AddressOf Button_click
Private Sub Button_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(DirectCast(sender, Button).Name)
End Sub
Thanks soooo much for taking the time to explain! :D but im afraid that whenever i click the button nothing happens...no button on the form anywhere?
-
Re: Please help MDI application!!
Can you post your code so I can look at it?
-
Re: Please help MDI application!!
Quote:
Originally Posted by
dave18
Can you post your code so I can look at it?
Yep, but which codes?...
-
Re: Please help MDI application!!
The code that creates the button and the code that creates the form as well.
-
Re: Please help MDI application!!
looks like the button is on the new form, but the button_click eventhandler is in the mdi form?
-
Re: Please help MDI application!!
Quote:
Originally Posted by
.paul.
looks like the button is on the new form, but the button_click eventhandler is in the mdi form?
hmmm maybe I'll have to check but in the meantime (sorry to through all these questions at you guys, but now i cant even debug...)
My error: title - (Invalid OperationException was unhandled)
System.InvalidOperationException was unhandled
Message="An error occurred creating the form. See Exception.InnerException for details. The error is: An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'"
Source="ApriCoT - Krypton"
StackTrace:
at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at WindowsApplication1.My.MyProject.MyForms.get_Form1()
at WindowsApplication1.My.MyApplication.OnCreateMainForm() in C:\Users\Mark\Documents\Visual Studio 2008\Projects\ApriCoT - Krypton\ApriCoT - Krypton\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidOperationException
Message="An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'"
Source="ApriCoT - Krypton"
StackTrace:
at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at WindowsApplication1.My.MyProject.MyForms.get_newapp()
at WindowsApplication1.Form1..ctor() in C:\Users\Mark\Documents\Visual Studio 2008\Projects\ApriCoT - Krypton\ApriCoT - Krypton\Form1.vb:line 335
InnerException: System.InvalidOperationException
Message="The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'"
Source="ApriCoT - Krypton"
StackTrace:
at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 180
at WindowsApplication1.My.MyProject.MyForms.get_Form1()
at WindowsApplication1.newapp.KryptonTextBox1_TextChanged(Object sender, EventArgs e) in C:\Users\Mark\Documents\Visual Studio 2008\Projects\ApriCoT - Krypton\ApriCoT - Krypton\newapp.vb:line 5
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at ComponentFactory.Krypton.Toolkit.KryptonTextBox.k(Object A_0, EventArgs A_1)
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
at System.Windows.Forms.Control.set_Text(String value)
at System.Windows.Forms.TextBoxBase.set_Text(String value)
at System.Windows.Forms.TextBox.set_Text(String value)
at ComponentFactory.Krypton.Toolkit.KryptonTextBox.set_Text(String value)
at WindowsApplication1.newapp.InitializeComponent() in C:\Users\Mark\Documents\Visual Studio 2008\Projects\ApriCoT - Krypton\ApriCoT - Krypton\newapp.Designer.vb:line 38
at WindowsApplication1.newapp..ctor()
InnerException:
-
Re: Please help MDI application!!
If you need to refer to the form in the form_Load event, use me, do not use the form name
vb.net Code:
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Right way
me.label1.text = "Hello"
'Wrong way
form1.label1.text = "Hello"
End Sub
-
Re: Please help MDI application!!
I understand what your saying, but I afraid this doesn't help
-
1 Attachment(s)
Re: Please help MDI application!!
does your error message look like this?
if you doubleclick on the error message it'll take you to the offending line
-
Re: Please help MDI application!!
Quote:
Originally Posted by
.paul.
does your error message look like this?
if you doubleclick on the error message it'll take you to the offending line
No, I have no actual errors in the application.
I click debug and it seems like it's about to load but then comes up with an exception box like I showed above
-
Re: Please help MDI application!!
I am a little confused....
From the error you posted...
Quote:
The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'"
If that is true, you should get a error in the IDE as paul posted. Can you post all the code that is creating the form and the buttons? We need to look at the code to find the problem.
-
Re: Please help MDI application!!
Quote:
Originally Posted by
dave18
I am a little confused....
From the error you posted...
If that is true, you should get a error in the IDE as paul posted. Can you post all the code that is creating the form and the buttons? We need to look at the code to find the problem.
My project has multiple forms but I'll just give your my form1 codes:
Public Class newapp
Private Sub KryptonTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonTextBox1.TextChanged
KryptonTextBox2.Text = (KryptonTextBox1.Text)
Form1.Text = (KryptonTextBox1.Text + (" - ApriCoT Krypton Application"))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
Form1.SaveAsToolStrip.Enabled = True
Form1.AddToolStrip.Enabled = True
Form1.EditTool.Enabled = True
Form1.ToolTitle.Enabled = True
Form1.AppTool.Enabled = True
If CheckBox1.Checked = True Then
MkDir("C:\" + KryptonTextBox2.Text)
Else
'Do nothing//////////////////////////
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub newapp_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Form1.Status.Text = ("Done.")
End Sub
Private Sub newapp_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
End Sub
Private Sub newapp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub KryptonTextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonTextBox2.TextChanged
End Sub
End Class
-
Re: Please help MDI application!!
he meant your newapp.designer.vb file
-
Re: Please help MDI application!!
Quote:
Originally Posted by
.paul.
he meant your newapp.designer.vb file
Public Class newapp
Private Sub KryptonTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonTextBox1.TextChanged
KryptonTextBox2.Text = (KryptonTextBox1.Text)
Form1.Text = (KryptonTextBox1.Text + (" - ApriCoT Krypton Application"))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
Form1.SaveAsToolStrip.Enabled = True
Form1.AddToolStrip.Enabled = True
Form1.EditTool.Enabled = True
Form1.ToolTitle.Enabled = True
Form1.AppTool.Enabled = True
If CheckBox1.Checked = True Then
MkDir("C:\" + KryptonTextBox2.Text)
Else
'Do nothing//////////////////////////
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub newapp_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Form1.Status.Text = ("Done.")
End Sub
Private Sub newapp_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
End Sub
Private Sub newapp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub KryptonTextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonTextBox2.TextChanged
End Sub
End Class
-
Re: Please help MDI application!!
That's not the designer file.
-
Re: Please help MDI application!!
Please post the designer file. There is a button above the solution explorer that says "show all files." Click on that, go to form1, click the plus, and post all the code for the designer file.
Quote:
If you need to refer to the form in the form_Load event, use me, do not use the form name
vb.net Code:
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Right way
me.label1.text = "Hello"
'Wrong way
form1.label1.text = "Hello"
End Sub
You cannot refer to the form by name, you have to use "me" Replace all the form1 with me and try to run the program again.
vb.net Code:
Form1.SaveAsToolStrip.Enabled = True
Form1.AddToolStrip.Enabled = True
Form1.EditTool.Enabled = True
Form1.ToolTitle.Enabled = True
Form1.AppTool.Enabled = True
And please wrap your code in either code tags or vbcode tags. It makes it easier to read.
-
1 Attachment(s)
Re: Please help MDI application!!
Sorry noob moment of me!
my designer file is too long for this post...:/ but the attatchment has a txt file of my form1 designer file:
Attachment 75749
-
Re: Please help MDI application!!
I created a new app and put all your designer code in my project and it built and the form displayed. What problems are you having now? Please post the code you are having problems with (not the designer code, just the code that is not working)
-
Re: Please help MDI application!!
well see thats what im not sure of...
There are no errors in the code...It's just when I debug the form doesn't display and it gives me the exception box with not trace of the exception.
-
Re: Please help MDI application!!
can you zip + post your application?
its probably something simple if you know how
-
Re: Please help MDI application!!
Quote:
Originally Posted by
.paul.
can you zip + post your application?
its probably something simple if you know how
yeah I'll post it
-
Re: Please help MDI application!!
here's my application. I hope you can find the exception so I can debug again and even build! Thanks so much! :D
-
Re: Please help MDI application!!
I downloaded your app and I noticed that you are using ComponentFactory. Are you using the trial or did you pay for it? I'm pretty sure the demo expires, and if it does, that might be why you cannot build the app.
-
Re: Please help MDI application!!
Quote:
Originally Posted by
dave18
I downloaded your app and I noticed that you are using ComponentFactory. Are you using the trial or did you pay for it? I'm pretty sure the demo expires, and if it does, that might be why you cannot build the app.
Well it's a trial, but I made sure not to use any of their components in my app. So that's probably not the problem.
-
Re: Please help MDI application!!
you're using at least 2 of their components. if you remove all the code that refers to them, it'll probably work
-
Re: Please help MDI application!!
You are using the controls in the newapp, newconsoleapp, and newprocessflowapp forms. Remove them, put standard controls in, and try to build again.
-
Re: Please help MDI application!!
Quote:
Originally Posted by
dave18
You are using the controls in the newapp, newconsoleapp, and newprocessflowapp forms. Remove them, put standard controls in, and try to build again.
thanks it worked!!!!!!! thank you soo much!!! this really helped!
Now I just need to figure out ONE more thing...you don't have to help if you don't want to but I'd be soo appreciative considering you've done so much already :D thanks.
My last questions is...I need to figure out how to remove the trial from DevComponents DotNetBar controls/components. Because everytime I try to debug, build or even just work on my project with those controls in it I get the error message of your trial period has expired. and the application closes along with visual basic 2008!
I neeed to use this project.!
-
Re: Please help MDI application!!
The only way to remove the trial is to buy the software. If you are not using any controls from the software, remove the reference to it from project and try to build again.
-
Re: Please help MDI application!!
ugh...alright.
Well back to the other application.
My goal is to make it a GUI/Coding maker application.
Like visual basic itself! :) Ik this will be VERY hard, but I would at least like to know how to make my application generate buttons onto the form and be moved around aswell as other controls like textboxes and such.
-
Re: Please help MDI application!!
here's how to add a button in code. if you want designer style functionality for moving + resizing your button, have a look at the move/resize controls link in my signature:
vb Code:
dim btn as new button
btn.location = new point(50,50)
btn.text = "new button"
me.controls.add(btn)
-
Re: Please help MDI application!!
thanks soo much for the button code!! sadly I do not know where to extract your resize/moveable control to make it work with my project. and the other question I have is: Is there a way I can give the newly created button's codes. Like normal buttons?
-
Re: Please help MDI application!!
Quote:
I do not know where to extract your resize/moveable control to make it work with my project
I would put the code for the buttons with the code that creates the button. That makes it easy to find if you need to change it later.
Quote:
Is there a way I can give the newly created button's codes. Like normal buttons?
I already showed you how to add code to the button. Read post 6 again.