Thursday 15 March 2012

vb.net - Why is my basic default .acceptbutton is not working? -



vb.net - Why is my basic default .acceptbutton is not working? -

what have:

i have 2 grouping boxes each text box inside. 3rd text box placed outside both of grouping boxes.

button 1 default take button on form load.

what need:

when button 1 clicked (or come in key pressed), need button 2 become default take button.

my problem:

button 3 becomes default take button rather button 2 in spite of code.

my code: public class form1 private sub form1_load(sender object, e eventargs) handles mybase.load groupbox1.enabled = true groupbox2.enabled = false me.acceptbutton = button1 end sub private sub button1_click(sender object, e eventargs) handles button1.click messagebox.show("button 1 pressed!") groupbox1.enabled = false groupbox2.enabled = true me.acceptbutton = button2 end sub private sub button2_click(sender object, e eventargs) handles button2.click messagebox.show("button 2 pressed!") groupbox1.enabled = true groupbox2.enabled = false me.acceptbutton = button1 end sub end class

the problem after press button 1 button 3 gets focus. prepare adding code focus button need in button 1 click event. "button2.focus()" etc..

private sub button1_click(sender object, e eventargs) handles button1.click messagebox.show("button 1 pressed!") groupbox1.enabled = false groupbox2.enabled = true me.acceptbutton = button2 button2.focus() end sub private sub button2_click(sender object, e eventargs) handles button2.click messagebox.show("button 2 pressed!") groupbox1.enabled = true groupbox2.enabled = false me.acceptbutton = button1 button1.focus() end sub

vb.net visual-studio

No comments:

Post a Comment