Jump to content
xisto Community
jimmy89

Keyboard Buttons

Recommended Posts

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

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
				Me.Controls.Add(frmChild)				frmChild.MdiParent = Me				frmChild.Show()

when i use this code i get the following error:

ArgumentException was unhandled
Top-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 unhandled
Form 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

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

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 tomorrow

Regards & Happy New Year

Share this post


Link to post
Share on other sites

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 you
Dim 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 debug

The 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 time

Instead 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 fullest

All the best

Regards
Faulty
Edited by faulty.lee (see edit history)

Share this post


Link to post
Share on other sites

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

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 up

EDIT: Try to read some books on this, it help understand more bout the basic of it, that way you can program more efficiently
Edited by faulty.lee (see edit history)

Share this post


Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.