473,326 Members | 2,111 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,326 software developers and data experts.

How Can I Make an Object in Form1 Work in Form2?

Dr Cake
Hello! I've got a calendar in Form 1 in my code, and buttons in Form2. I need these buttons to send codes for this calendar in Form1. How may I make these work? My friend told me to do a function as a new class, but I'm not sure how can I do this. Glad if you can help :)
May 20 '12 #1

✓ answered by Curtis Rutland

Both of those are terrible suggestions. Making it static will have major consequences if you use more than one instance of the form. And India777's answer simply will not work. That's creating a new instance of Form1, not the one that already exists.

Read this:

http://www.dreamincode.net/forums/to...y-other-forms/

Edit: Forgot that I posted that article here at Bytes too:

http://bytes.com/topic/c-sharp/insig...ny-other-forms

The other one has comments where I expand on a few things, so I'll leave it posted.

5 3150
Make control static.

public static Calender clndr = new Calender();
May 21 '12 #2
Create the object for Form1 in Form2.

Form1 frm1=new Form1();
access the Controls in Form1 using the Variable frm1.
May 21 '12 #3
Curtis Rutland
3,256 Expert 2GB
Both of those are terrible suggestions. Making it static will have major consequences if you use more than one instance of the form. And India777's answer simply will not work. That's creating a new instance of Form1, not the one that already exists.

Read this:

http://www.dreamincode.net/forums/to...y-other-forms/

Edit: Forgot that I posted that article here at Bytes too:

http://bytes.com/topic/c-sharp/insig...ny-other-forms

The other one has comments where I expand on a few things, so I'll leave it posted.
May 21 '12 #4
Thanks Curtis! I might be new to C#, but I already knew those other 2 replies wouldn't work, so I didn't even try. But you linked me to really what I needed. Many thanks!!
May 21 '12 #5
Curtis Rutland
3,256 Expert 2GB
No problem. I actually wrote that article, so let me know if you have any questions.
May 21 '12 #6

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

Similar topics

0
by: ATS | last post by:
PRB: Can not get UserControl/HTML/OBJECT to work on XP/SP2/IIS/IE6 Please help, I can not get my UserControl to work from a simple OBJECT tag in a simple HTML web page on Windows XP with SP2...
5
by: John | last post by:
Hi, I can't find a simple example for a simple(?) problem. I am working on an application with a variable in form1, that variable is needed in form2 for a calculation but i can't get that...
3
by: Mateusz Rajca | last post by:
Hello, I have Form1 - the main form with some controls including a button. I have Form2 - the properties form with a combobox and button. The user can select the colors of a button in the...
2
by: Svein Erik | last post by:
C# 2.0 How can i update my progress bar on Form1, from Form2? Form 2 contains a button that is supposed to update the progressbar on Form1 by 5 in value. I can't find out how to do this, please...
9
by: wanyok | last post by:
I thought I had it figured out but I'm still getting errors :( I would appreciate any help I could get. I have two forms: Form1 and frmVerify. Once the info gets submitted on Form1 its text...
1
by: ashwinigopi | last post by:
I have two forms, form1 & form 2. Form1 has datagridview. I am not supposed use any sql command in form1. So i added form2 and wrote the sql commands using stored procedures to get the data from the...
0
by: tkjensen | last post by:
Hi everyone. I hope someone can help me sort this out. My problem is that I need to update my DataGridView on Form2.closing. I need both the Form1 code and Form2 code. So I hope someone want's...
10
maheshwag
by: maheshwag | last post by:
I have to form in my application form1 and form2 form1 having combobox and form2 having textbox I wants to retrieve the value of combobox to textbox by setting property like below. ...
0
Curtis Rutland
by: Curtis Rutland | last post by:
This question is asked practically every day in the C# Forum: "how do I get a value from Form1 to Form2?" or the other way around. There is a shocking amount of bad advice out there on the internet...
1
by: Anil D | last post by:
Hi, I have two forms(form1 and form2). I placed a button in form1 to redirect to form2. now my question is if i click the button form2 is displayed and form1 is disabled and if i close the form2 it...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.