jimmy89 0 Report post Posted December 22, 2006 (edited) Select Case e.KeyCode Case Keys.F2 frmChild.MdiParent = Me frmChild.Show() Me.Controls.Add(frmChild) End Select this code still gives me same error as before Edited December 22, 2006 by Jimmy89 (see edit history) Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted December 23, 2006 Select Case e.KeyCode Case Keys.F2 frmChild.MdiParent = Me frmChild.Show() Me.Controls.Add(frmChild) End Selectthis code still gives me same error as before Controls.Add has to be call before you call "show()". And about the error, what error was it? I remember you were saying that it's not focus, but you never mention any error. You have to be clear with your term, or else others will get confuse. If you don't mind, can you explain a bit bout what your code is suppose to do, and so far what have been achieved and which part is not working as you intended it to. With an overview, it would be easier to solve you problem Share this post Link to post Share on other sites
jimmy89 0 Report post Posted December 26, 2006 Me.Controls.Add(frmChild) frmChild.MdiParent = Me frmChild.Show() when i use this code i get the following error:ArgumentException was unhandledTop-level control cannot be added to a control.when i rearrange the code so that the declaration of the parent form comes before adding the control Me.Controls.Add(frmChild) frmChild.MdiParent = me frmChild.show() i get a different error:ArgumentException was unhandledForm cannot be added to the Controls collection that has a valid MDI parent.Parameter name: value Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted December 26, 2006 Do You mind to zip your code and attach it here? Share this post Link to post Share on other sites
jimmy89 0 Report post Posted December 26, 2006 i have attached the code zipped. the frmChild that i have been referring to in the code is actually named frmWebHelp. Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted December 27, 2006 i have attached the code zipped. the frmChild that i have been referring to in the code is actually named frmWebHelp. Sorry, do you mind to attach a more complete codes, cause i need to see what went wrong. The one you attached is just the button event. I can't see the property of those forms. If possible, you attach the .vb file of frmMain and frmChild Share this post Link to post Share on other sites
jimmy89 0 Report post Posted December 27, 2006 yeah, sorry about that. I have just attached everything for those two forms Share this post Link to post Share on other sites
jimmy89 0 Report post Posted January 1, 2007 hi, i was just checking in to see if you have worked out any solutions to my problem! thanks for your help! Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted January 3, 2007 hi, i was just checking in to see if you have worked out any solutions to my problem! thanks for your help! Hi, sorry for the delay, quite busy with some customer supports lately. Btw, you code is done using visual basic 2005 right? I'm only using 2003. Installing 2005 now. If it goes successful tonight, i'll get back to you tomorrowRegards & Happy New Year Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted January 3, 2007 (edited) Hi,Ok, i've tested. Just this code you posted earlier works fine for me frmChild.MdiParent = mefrmChild.show Sorry for giving you the wrong info on Controls.Add(). I seldom use MDI for my software. I find it confusing.Anyway, you also need to enable "KeyPreview" (Misc) for your main form for the keyboard event to work properly.After seeing you code, i do have a few comment for youDim response As Microsoft.VisualBasic.MsgBoxResult Use this instead of interger, that way your code of If response = 6 Then can be written as If response = MsgBoxResult.Yes Then which is a lot of easier to read and debugThe 2nd thing is try to use as much OOP strategy as possible. One of it is keep all this code that show your MDI Child in side one function, then call the function from those menu and key event. That way, it's easier to maintain the code. If you need to change the way your Help Windows appear, just change that function. All those event that call the function gets the changes. f not, you'll have to look through all your codes to make the changes, and you might miss it, trust me, it does, all the timeInstead of Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown Dim response As Microsoft.VisualBasic.MsgBoxResult Select Case e.KeyCode Case Keys.F1 MsgBox("You asked for help") Exit Sub Case Keys.F2 frmWebHelp.MdiParent = Me frmWebHelp.Show()..... more code Private Sub WebHelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WebHelpToolStripMenuItem.Click frmWebHelp.MdiParent = Me frmWebHelp.Show() End Sub You change it to Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown Dim response As Microsoft.VisualBasic.MsgBoxResult Select Case e.KeyCode Case Keys.F1 MsgBox("You asked for help") Exit Sub Case Keys.F2 ShowfrmWebHelp()..... more code Private Sub WebHelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WebHelpToolStripMenuItem.Click ShowfrmWebHelp() End Sub Private Sub ShowfrmWebHelp() frmWebHelp.MdiParent = Me frmWebHelp.Show() End Sub VB.Net implemented a lot of OOP features compare to VB6, it's totally re-engineered, thus why not use that to our fullestAll the bestRegardsFaulty Edited January 3, 2007 by faulty.lee (see edit history) Share this post Link to post Share on other sites
jimmy89 0 Report post Posted January 3, 2007 Thanks for your help! changing the key preview property seems to have fixed the problem. Also, thanks for the code fixes, they all made sense and i have changed my code too. Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted January 4, 2007 (edited) Thanks for your help! changing the key preview property seems to have fixed the problem. Also, thanks for the code fixes, they all made sense and i have changed my code too. Glad it helps. Keep upEDIT: Try to read some books on this, it help understand more bout the basic of it, that way you can program more efficiently Edited January 4, 2007 by faulty.lee (see edit history) Share this post Link to post Share on other sites
jimmy89 0 Report post Posted January 4, 2007 thanks! i'll look into it! Share this post Link to post Share on other sites
iGuest 3 Report post Posted October 25, 2007 Name:Basel OlayyanEmail:basel_baselll@hotmail.comOpinion/*: Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown Select Case e.KeyCode Case Keys.F1 MessageBox.Show("F1") Case Keys.F5 MessageBox.Show("F5") Case Keys.F6 AndAlso e.Shift 'Shift + F6 End Select End SubI have used this code but when I but ant button or text box or any thing on the form this even not working and I don't know wht to do Plz if you have any Suggestion how to do it it well be appreciated and thx for your help -Basel Olayyan Share this post Link to post Share on other sites