473,606 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Locatio n = 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 1152

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.Locatio n = 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...@gma il.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.Locatio n = 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.F orm 'Assumes that FormB does not yet exist.
FormB.add_butto n()

Nov 23 '06 #4
OK thanks , so what would the code in Form B be?
lo*********@gma il.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.F orm 'Assumes that FormB does not yet exist.
FormB.add_butto n()
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

controldrag.add _button()
End Sub
lo*********@gma il.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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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
3177
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 forms... I tried painting, but the paintaing area provided by the form is only the client area - no visible way to paint on the title bar.
7
1324
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 click on the respective buttons absolutely nothing happens! I was wondering if anyone could help? The code I have is below... ADDING A RECORD Private Sub cmdaddstudent_Click() On Error GoTo Err_cmdaddstudent_Click
2
1799
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 buttons I'll need or the properties for each until I read a database. For each new button, I need to assign the text, name ('id' for later reference), and set the code-behind to handle the events for each. I hope I'm clear. Could someone suggest...
1
2026
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 product types etc. So for instance Im adding a fruit company while adding a fruit company I allow the user to add types of fruit they carry and display it dynamically using an <asp:table> with image
0
1434
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 adds a handler to the click event. When a button is clicked, the background-color is set to blue.
6
436
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 anywhere. I have managed to add Labels using the following code: Dim extralabel As Label = New Label extralabel.Text = "Generated Label" Me.Controls.Add(extralabel)
5
3673
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 total number showen on screen, or on "submit" loop through the selected radio buttons and get the total. What I have at the moment will loop through all the buttons and just add all the totals, how do I get this code to add together the...
1
1693
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 page "Next" and "Previous" which I want displayed just a couple of lines below the table dynamically. Thus the positions of these buttons would vary depending on how many rows are rendered. I was wondering whether there is a programmatic way of...
4
1867
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 code must I write to make this happen? I am new to programming, so go easy on me with the explanation please. Thank you for any help you can offer.
0
8009
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7939
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8432
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8299
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5962
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5456
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.