Results 1 to 38 of 38

Thread: Please help MDI application!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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)

  2. #2
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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:
    1. Dim lblbox As New Label
    2.  
    3.                 With lblbox
    4.                     .Left = locx
    5.                     .Top = locy
    6.                     .Width = 30
    7.                     .Height = 30
    8.                     .BackColor = Color.White
    9.                     .BorderStyle = BorderStyle.FixedSingle
    10.                     .Name = "lblbox"
    11.                     .Text = r.Next(0, 10)
    12.                     .Tag = count
    13.                 End With
    14.  
    15.                 Me.Controls.Add(lblbox)
    16.  
    17.                 AddHandler lblbox.Click, AddressOf lblbox_click
    18.  
    19.     Private Sub lblbox_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    20.         MessageBox.Show(DirectCast(sender, Label).Tag)
    21.     End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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.

  4. #4
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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?

  6. #6
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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:
    1. Dim NewButton as New Button
    2.  
    3. With NewButton
    4.       .left = 10       'x position of the control in pixels
    5.       .Top = 10      'y position of the control in pixels
    6.       .Width = 30
    7.       .Height = 10
    8.       .Name = "Button1"
    9.       .Text = "Click Me"
    10. End With
    11.  
    12. me.Controls.Add(NewButton)
    13.  
    14. AddHandler NewButton.Click, AddressOf Button_click
    15.  
    16.     Private Sub Button_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    17.         MessageBox.Show(DirectCast(sender, Button).Name)
    18.     End Sub

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by dave18 View Post
    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:
    1. Dim NewButton as New Button
    2.  
    3. With NewButton
    4.       .left = 10       'x position of the control in pixels
    5.       .Top = 10      'y position of the control in pixels
    6.       .Width = 30
    7.       .Height = 10
    8.       .Name = "Button1"
    9.       .Text = "Click Me"
    10. End With
    11.  
    12. me.Controls.Add(NewButton)
    13.  
    14. AddHandler NewButton.Click, AddressOf Button_click
    15.  
    16.     Private Sub Button_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    17.         MessageBox.Show(DirectCast(sender, Button).Name)
    18.     End Sub

    Thanks soooo much for taking the time to explain! but im afraid that whenever i click the button nothing happens...no button on the form anywhere?

  8. #8
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    Re: Please help MDI application!!

    Can you post your code so I can look at it?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by dave18 View Post
    Can you post your code so I can look at it?
    Yep, but which codes?...

  10. #10
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    Re: Please help MDI application!!

    The code that creates the button and the code that creates the form as well.

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Please help MDI application!!

    looks like the button is on the new form, but the button_click eventhandler is in the mdi form?

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by .paul. View Post
    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:

  13. #13
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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:
    1. Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3. 'Right way
    4. me.label1.text = "Hello"
    5.  
    6. 'Wrong way
    7. form1.label1.text = "Hello"
    8.  
    9. End Sub

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    I understand what your saying, but I afraid this doesn't help

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    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
    Attached Images Attached Images  

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by .paul. View Post
    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

  17. #17
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    Re: Please help MDI application!!

    I am a little confused....

    From the error you posted...

    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.

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by dave18 View Post
    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

  19. #19
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Please help MDI application!!

    he meant your newapp.designer.vb file

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by .paul. View Post
    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

  21. #21

    Re: Please help MDI application!!

    That's not the designer file.

  22. #22
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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.

    If you need to refer to the form in the form_Load event, use me, do not use the form name

    vb.net Code:
    1. Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3. 'Right way
    4. me.label1.text = "Hello"
    5.  
    6. 'Wrong way
    7. form1.label1.text = "Hello"
    8.  
    9. 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:
    1. Form1.SaveAsToolStrip.Enabled = True
    2. Form1.AddToolStrip.Enabled = True
    3. Form1.EditTool.Enabled = True
    4. Form1.ToolTitle.Enabled = True
    5. Form1.AppTool.Enabled = True

    And please wrap your code in either code tags or vbcode tags. It makes it easier to read.

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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:

    form1designer.txt

  24. #24
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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)

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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.

  26. #26
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Please help MDI application!!

    can you zip + post your application?
    its probably something simple if you know how

  27. #27

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by .paul. View Post
    can you zip + post your application?
    its probably something simple if you know how
    yeah I'll post it

  28. #28

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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!

  29. #29
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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.

  30. #30

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by dave18 View Post
    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.

  31. #31
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    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

  32. #32
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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.

  33. #33

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    Re: Please help MDI application!!

    Quote Originally Posted by dave18 View Post
    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 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.!

  34. #34
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    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.

  35. #35

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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.

  36. #36
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    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:
    1. dim btn as new button
    2. btn.location = new point(50,50)
    3. btn.text = "new button"
    4. me.controls.add(btn)

  37. #37

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    26

    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?

  38. #38
    Lively Member
    Join Date
    Nov 2007
    Posts
    105

    Re: Please help MDI application!!

    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.
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width