|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding buttons to form helpHi,
I am using the below code to add a button to form. However it is not working. If I change the form name from 'form1' to 'me' it does add the button to the current form...any ideas. Also does anyone know a way keep any user generated buttons in the form even after the application is closed down,..Im guessing this requires a DB link? button1.Text = "OK" ' Set the position of the button on the form. button1.Location = New Point(10, 10) ' Set the text of button2 to "Cancel". ' Add button1 to the form. form1.Controls.Add(button1) Marc wrote:
> Hi, You mean you actually changed the form's name to "Me"? Ot did you just> > I am using the below code to add a button to form. However it is not > working. If I change the form name from 'form1' to 'me' it does add the > button to the current form...any ideas. chagne a line like this: form1.Controls.Add(button1) to: Me.Controls.Add(button1) ? the "Me" keyword refers to the object that the "Me" keyword is used in, much the same way people use it to refer to themselves when speaking English. I prefer it over refering to a form by its name within itself. > Also does anyone know a way keep any user generated buttons in the form You probably don't need a database for this. You will probably have to> even after the application is closed down,..Im guessing this requires a > DB link? > > button1.Text = "OK" > ' Set the position of the button on the form. > button1.Location = New Point(10, 10) > ' Set the text of button2 to "Cancel". > ' Add button1 to the form. > form1.Controls.Add(button1) serialize the object (form), but it's up to you if you want to serialize it as a file on the local machine where the program is running, or into a database somewhere. Local is probably much easier. By the way, I don't know if buttons, textboxes, or other controls are serializable, I suspect not. I had a similar problem last week. I got around it by only serializing the most relevant data: the text in the text boxes, and the text of certain labels. Search on MSDN for object serializing tutorials for more detailed info. Thanks,
Yes me as in the current form, however i want the button to appear on a separate form? lord.zol***@gmail.com wrote: Show quoteHide quote > Marc wrote: > > Hi, > > > > I am using the below code to add a button to form. However it is not > > working. If I change the form name from 'form1' to 'me' it does add the > > button to the current form...any ideas. > > You mean you actually changed the form's name to "Me"? Ot did you just > chagne a line like this: > form1.Controls.Add(button1) > to: > Me.Controls.Add(button1) > ? > > the "Me" keyword refers to the object that the "Me" keyword is used in, > much the same way people use it to refer to themselves when speaking > English. I prefer it over refering to a form by its name within itself. > > > Also does anyone know a way keep any user generated buttons in the form > > even after the application is closed down,..Im guessing this requires a > > DB link? > > > > button1.Text = "OK" > > ' Set the position of the button on the form. > > button1.Location = New Point(10, 10) > > ' Set the text of button2 to "Cancel". > > ' Add button1 to the form. > > form1.Controls.Add(button1) > > You probably don't need a database for this. You will probably have to > serialize the object (form), but it's up to you if you want to > serialize it as a file on the local machine where the program is > running, or into a database somewhere. Local is probably much easier. > By the way, I don't know if buttons, textboxes, or other controls are > serializable, I suspect not. I had a similar problem last week. I got > around it by only serializing the most relevant data: the text in the > text boxes, and the text of certain labels. > Search on MSDN for object serializing tutorials for more detailed info. Marc wrote:
> Thanks, So you want the user to do something to FormA and then have FormA cause> > Yes me as in the current form, however i want the button to appear on a > separate form? > a button to appear on FormB? The simplest way might be to have an "add_button" procedure in FormB and then have FormA call that procedure. Code in FormA could look like this dim FormB as Windows.Forms.Form 'Assumes that FormB does not yet exist. FormB.add_button() OK thanks , so what would the code in Form B be?
lord.zol***@gmail.com wrote: Show quoteHide quote > Marc wrote: > > Thanks, > > > > Yes me as in the current form, however i want the button to appear on a > > separate form? > > > > So you want the user to do something to FormA and then have FormA cause > a button to appear on FormB? > > The simplest way might be to have an "add_button" procedure in FormB > and then have FormA call that procedure. > Code in FormA could look like this > > dim FormB as Windows.Forms.Form 'Assumes that FormB does not yet exist. > FormB.add_button() Marc wrote:
> OK thanks , so what would the code in Form B be? umm... that really depends on what you want to do.> at the simplest, try: public sub add_button dim myBtn as New Button Me.Controls.Add(myBtn) end sub Hmmm...I tried that and its still not working!.
I tried adding the button from Form B' and it worked fine...its only when i try to add a button from 'Form A' it doesnt work.i.e from one form to another. my code is form B Dim myBtn As New Button Me.Controls.Add(myBtn) form a Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click controldrag.add_button() End Sub lord.zol***@gmail.com wrote: Show quoteHide quote > Marc wrote: > > OK thanks , so what would the code in Form B be? > > > > umm... that really depends on what you want to do. > at the simplest, try: > > public sub add_button > dim myBtn as New Button > Me.Controls.Add(myBtn) > end sub Marc wrote:
Show quoteHide quote > Hmmm...I tried that and its still not working!. What is controldrag?> > I tried adding the button from Form B' and it worked fine...its only > when i try to add a button from 'Form A' it doesnt work.i.e from one > form to another. > > > my code is > > form B > > Dim myBtn As New Button > Me.Controls.Add(myBtn) > > form a > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > controldrag.add_button() > End Sub > > what part of it doesn't work? what errors does it report?
OO design and programming...
Upgrade Question Q: Regular Expressions? tell more about .net framework date time picker and validate event ( is this a bug ? ) Automatic Form Fill in Drag and drop multiple button controls..need help modifying code please??? Managing without .NET for runtime applications Looking For Training Recommendations embem Excel in winford using vb.net |
|||||||||||||||||||||||