473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Adding buttons to form help

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.

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)

Nov 23 '06 #1
7 1139

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.

Nov 23 '06 #2
Thanks,

Yes me as in the current form, however i want the button to appear on a
separate form?

lord.zol...@gmail.com wrote:
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.
Nov 23 '06 #3

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()

Nov 23 '06 #4
OK thanks , so what would the code in Form B be?
lo*********@gmail.com wrote:
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()
Nov 23 '06 #5

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

Nov 23 '06 #6
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
lo*********@gmail.com wrote:
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
Nov 23 '06 #7

Marc wrote:
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

What is controldrag?
what part of it doesn't work? what errors does it report?

Nov 23 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Picho | last post by:
Hi all, Is there any .NET way (I am not rulling out API usage) to add button(s) to a form's title bar? I found some non-.NET solutions that did actually work in VB6 but not in the ..NET...
7
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help. I have 3 buttons on a form which add, delete and search for a record. However, when I...
2
by: Doug Slocum | last post by:
Hi, I'm using ASP.NET. I need help adding new buttons to my web page at run time on the server side prior to sending to the client. As the web form is loading, I won't know in advance how many...
1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
0
by: Klaus Jensen | last post by:
Hi! This has been annoying me for a while now, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and...
6
by: Nathan Sokalski | last post by:
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls such as Label controls, because they can be placed...
5
by: alanb | last post by:
Hi, hope someone can help, I need to be able to keep a running total of radio buttons selected, as a user goes through a set of 16 questions, devided in to 4 catorgories, then on "submit" have the...
1
by: Paddy | last post by:
The problem I am facing is as follows: I am populating an HTML table on my webpage with rows of data from a database. The rows may be sometimes 10 and sometimes say,3. I have two buttons on that...
4
by: Jonny Relentless | last post by:
After adding a form to a C# program, I am unable to use it. I want to use form1 as a sort of menu, so that when the user clicks a button, form1 will close and form2 (or form3, etc) will open. What...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.