473,387 Members | 1,464 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,387 software developers and data experts.

getting textbox value

2
I have form1 which contains radiobutton1 and radiobutton2. And textbox1. I have another form form2 which contains a double x which I'll use it in an equation. I made an if statement that states what to be in textbox1 "12000" or "24000" if radiobutton 2 is selected. in form2 i made the following :
form1 form = new form1();
double x;
x = double.parse(form.textbox1.text);
there is also try and catch statements for inputs in form2.
It compiles without error, however it always shows the messagebox in the catch section.
please tell me what to do.
Thanks
May 1 '11 #1
3 2708
adriancs
122 100+
so you want to pass the value from form1 to form2.

Try this, add these commands in form1:
Expand|Select|Wrap|Line Numbers
  1. public static double X;
  2. private void Form1_Load(object sender, EventArgs e)
  3. {
  4.     this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
  5. }
  6.  
  7. void textBox1_TextChanged(object sender, EventArgs e)
  8. {
  9.     if (Double.TryParse(this.textBox1.Text, out X))
  10.         X = Convert.ToDouble(this.textBox1.Text);
  11.     else
  12.         MessageBox.Show("Error. Input value must be numeric");
  13. }
Add these commands in form2:
Expand|Select|Wrap|Line Numbers
  1. double X;
  2. private void Form2_Load(object sender, EventArgs e)
  3. {
  4.     X = Form1.X;
  5. }
May 1 '11 #2
Omar B
2
I just cannot thank you enough. You really saved my brain because i'm still a beginner in programming and doing a project for the university using C#. Really thank you
May 1 '11 #3
adriancs
122 100+
Hi, you're welcome.

You can pass any value to another form.
One of the method is making the value public static.
Then the value will be accessible in another form.

for example, in this case,

public static double X;

cheers.
May 2 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Raed Sawalha | last post by:
Hi, This is probably pretty simple but... I am dynamically adding rows to a HtmlTable that contain Textbox controls. (There may be more than one server control/textbox in a given cell) How...
2
by: Atreju | last post by:
Ok I got form within a c sharp page. Situation: On the form I have a drop downliwst and a textbox, the dropdownlist is populated with products and the textbox has a default vale of the product...
2
by: Nowezo | last post by:
Hi, Can you please help me, I want to write a dropdown box that have an option 'Other' but when the Other is selected my textbox need to be enable and take the textbox value as an output instead of...
1
by: viral123 | last post by:
Hi all I am using Crystal report and I am running my report successfully for my query but I want to make my query for one specific date. I want to get the date value from the textbox value. ...
2
by: mylog | last post by:
Hi all, I am having a small problem on getting the values of the dynamically generated textboxes in C# windows application. I have successfully read an xml file and put its key and value fields as...
0
by: gopim | last post by:
hi, in my registration form having 20 fields,for this i devide this into three sections by using Multiview and views concept.it is fine but i cant get the value in "password textbox" value.how...
2
by: Archanak | last post by:
Hi, I have one common text box to get email id. I have 2 forms and both form action connects to different programs. I want to use this textbox value(i.e email id) only for both the forms. How...
10
by: pt36 | last post by:
Hi I have a page with a form and a textbox. before to submit the form I want to chek if the inserted value in the textbox is already present in a database. So I need to pass the textbox value...
1
by: visweswaran2830 | last post by:
Hi, I have datagrid control. In that I place textbox, insert link button in hearder template. When I click that Insert button the value from textbox should be loaded into grid. I am capturing at...
0
by: yogarajan | last post by:
Hi All I am create textbox and collect textbox value at runtime using c# my aspx code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> <!DOCTYPE html...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
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...

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.