I just went through this two or three times and it feels like I just learned in six minutes what would've taken six weeks to learn from other "dry" tutorials. Again, good job.
That was so cool. I've been hacking away at this for over an hour. This video was clear and straight to the point. Thanks. You saved me a lot of time. :D
Hi. I have a problem with the example given here. I have a Form object named EDF1 on the form I have public static cmdrName, shipName_z etc. So I have this code in EDF1 form: public static EDF1 instance; public Label cmdrName_z; public Label shipName_z; and instance = this; cmdrName_z = cmdrName; shipName_z = shipName; Then in the second class project file I have a function public void read_file (string changeFile) in which I read the changes that appeared in the file given as "changeFile". If the change is significant, I enter it into the element on the EDF1 form with the code: EDF1.instance.cmdrName_z.Text = newValue The problem is, I get an exception once in a while: "Invalid cross-thread operation: The 'cmdrName' control is being accessed from a thread other than the thread on which it was created." This exception was originally thrown on this call stack: System.Windows.Forms.Control.Handle.get () System.Windows.Forms.Control.WindowText.set (string) System.Windows.Forms.Control.Text.set (string) ED_Informator.Jurnal.read_file (string) in Jurnal.cs ED_Informator.EDF1.OnChanged (object, System.IO.FileSystemEventArgs) in Form1.cs System.IO.FileSystemWatcher.OnChanged (System.IO.FileSystemEventArgs) System.IO.FileSystemWatcher.CompletionStatusChanged (uint, uint, System.Threading.NativeOverlapped *) System.Threading._IOCompletionCallback.PerformIOCompletionCallback (uint, uint, System.Threading.NativeOverlapped *) Same appeal EDF1.instance.cmdrName_z.Text = newValue There are also two other functions, one of which is called to read some information from the most recently created change log file. The second pre-checks the file after creating a new change log file.
I kept finding programs opening multiple instances of form2 every time I transferred data, but this does exactly what I needed. Since I am using some hardware in combination with advanced mathematical processing to send messages back from the future, you will be first in line for the lottery numbers when everything is up and running. Thank you! I presume I can run a chart control using similar methods? There are so many charts in my program that one form is not enough.
Using the method in this video, I opened the serial port in form 1 and read the value from the serial port in other forms. But other opened forms do not work simultaneously. What can I do about this situation?
Hi, I want to do this but from form1 I want to be able to hide form 2 using a button. So When you press a button on form 1 it will hide form2 something like (form2.Hide();) I have tried lots of ways and none of them are working
I'm not sure if you can help me but whenever I try accessing something from the other form it gives me this exception error: "Object reference not set to an instance of an object." public partial class FormConfig : Form { public static FormConfig instance; public TextBox tbCaminhoCadastros; //Constructor public FormConfig() { InitializeComponent(); instance = this; tbCaminhoCadastros = txtCaminhoCadastros; } } public partial class FormMain : Form { private void wathexSolutions_Load(object sender, EventArgs e) { FormConfig.instance.tbCaminhoCadastros.Text = "test"; } } The exeptions occurs for everything I try to access from "FormConfig" and not just for that textBox, it also happens when I try to access it from the "FormMain" Constructor too, are there anything I'm missing?
I have a question regarding example 2. Let's say I open multiple instances of "Form2" using "button1". If I write something on textbox2 and apply the change pressing "button change form2", will the label in all instances of Form2 change? Or will only the last opened form be affected? After a bit of experimenting, the latter seems to be the case, but I wonder if it's possible to make the change apply to all instances of Form2 instead of just the last one. If you have any ideas I'd like to hear them. In advance, thank you for your time!
form2.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace databtwforms { public partial class Form2 : Form { //list of all instance of form2 opened by form1 private static List instancesList; public Label lab1; //this constructor run only one time because its static for initialization of list static Form2() { instancesList = new List(); } public Form2() { InitializeComponent(); instancesList.Add(this); lab1 = label1; } private void button1_Click(object sender, EventArgs e) { Form1.instance.tb1.Text = "set by form2"; } //NEWLY CREATED METHOD public static void ChangeAllText(string text) { foreach (var item in instancesList) { item.lab1.Text = text; } } } }
so bascially each time we are creating a form2 we are storing instance info in a list, and when its time to change textbox we are change all the instances textboxes
help! i want to make an OS and in it, I tried to detect whether a program is closed or minimized so when I tried to make the "public TextBox tb1;" part, I changed it to "public Form calculator" and I tried to do the "tb1 = textbox1;" and it looks like this "calculator = Form.Calculator;" but it doesn't work, could you help? EDIT!!: i just remembered that instead of using the form name(Calculator.cs) for the same form(Calculator.cs), could have just typed in "calculator = this;" rather than "calculator = Form.Calculator;", still good video tho, its explains a lot of stuff i didn't understand
It is rare, but i have a warning about the posibility of being instance a null value. It has zero sense, and it doesn't does any damage, it is a curiosity.
@@HassaanRaza yes i did, but after this everytime i use the instance the vs says something like the instance can be null. It doesn't matter, the trick works very well.
Hey great Video. I have a question when I create an instance of form 2 in the form 1 click event why can't I access methods/data using that instance name? Form2 newForm2 = new Form2(); string title = newForm2.getTitle; //This doesn't work and says that there is no getTitle function) and in Form2 I have defined public string getTitle() { return titleTextBox.text; } Using your way works perfectly just wonder why.
@@HassaanRaza I had the () in the code just forget them here. The issue was I mistakenly made it Form newForm2 = new Form2() instead of Form2 newForm2 = new Form2() No idea how that happened.
bro first of all, thanks for the tutorial .. how about calling the form directly without creating an instance of it . inside form2 .. form1.textbox1.text .. what's wrong with it .. with all do respect .. it doesn't make sense to me to create multiple public variables in order to get data from the parent form .. I've been doing this for entire my life ..
form1 is not static, so you need the exact instance of form1 to work on thats why its important to create a variable. (the variable store the exact instance of form1) that we want to change.
CHECK THIS OUT!
How to Buy Website Domain & Hosting, Complete Simple Procedure
ua-cam.com/video/a-3UFt1r_1I/v-deo.html
I just went through this two or three times and it feels like I just learned in six minutes what would've taken six weeks to learn from other "dry" tutorials. Again, good job.
thanks man! thank you so much your appreciation inspire us creators to do more 😁
this just answered 5 pages of modules, I've been fixing my project for 2 weeks! THANK YOU SO MUCH!!!
thats is super awesome to know! best of luck with you project.
This helped me with an issue I was facing about one whole week. I'm immensely grateful for this content, many blessings for you!
thanks mate, keep going.
good luck with whatever you are making :)
I went through a lot of videos, not one did not work, I saw yours, checked it and immediately worked, thank you very much, you helped a lot
that's great!
THIS IS THE BEST!!! THANK YOU 3000!
I have been looking for this for over 3 weeks now!
yup its a little tricky to figure.
After 2 years and i am here
Thanks you Indian teacher
haha that's awesome, cheers!
by the way I'm from Pakistan (so not indian)
@@HassaanRaza ohh i am so sorry
thank you my Pakistan teacher 🥰🥰
hehe
Man, You made my Day
omg.. you help me a lot.. no blackbox no stackover... thank u man
haha im glad i could be of help :)
I usually have a hard time with Hinglish. But this time it was WELL WORTH it, thanks !
Also slowing the video a bit down helped a little bit ;-)
That was so cool. I've been hacking away at this for over an hour. This video was clear and straight to the point. Thanks. You saved me a lot of time. :D
that's great to know :)
Hi thank you i look for this method over 5 month you saved my life :D
hahaha glad you found me XD
Thank you so much. I looked for this for 5 days.
thats great to know :)
Hi.
I have a problem with the example given here.
I have a Form object named EDF1 on the form I have public static cmdrName, shipName_z etc.
So I have this code in EDF1 form:
public static EDF1 instance;
public Label cmdrName_z;
public Label shipName_z;
and
instance = this;
cmdrName_z = cmdrName;
shipName_z = shipName;
Then in the second class project file I have a function
public void read_file (string changeFile)
in which I read the changes that appeared in the file given as "changeFile".
If the change is significant, I enter it into the element on the EDF1 form with the code:
EDF1.instance.cmdrName_z.Text = newValue
The problem is, I get an exception once in a while:
"Invalid cross-thread operation: The 'cmdrName' control is being accessed from a thread other than the thread on which it was created."
This exception was originally thrown on this call stack:
System.Windows.Forms.Control.Handle.get ()
System.Windows.Forms.Control.WindowText.set (string)
System.Windows.Forms.Control.Text.set (string)
ED_Informator.Jurnal.read_file (string) in Jurnal.cs
ED_Informator.EDF1.OnChanged (object, System.IO.FileSystemEventArgs) in Form1.cs
System.IO.FileSystemWatcher.OnChanged (System.IO.FileSystemEventArgs)
System.IO.FileSystemWatcher.CompletionStatusChanged (uint, uint, System.Threading.NativeOverlapped *)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback (uint, uint, System.Threading.NativeOverlapped *)
Same appeal
EDF1.instance.cmdrName_z.Text = newValue
There are also two other functions, one of which is called to read some information from the most recently created change log file. The second pre-checks the file after creating a new change log file.
Perfect tutorial 😍... You are saved my project
thank you :)
I kept finding programs opening multiple instances of form2 every time I transferred data, but this does exactly what I needed. Since I am using some hardware in combination with advanced mathematical processing to send messages back from the future, you will be first in line for the lottery numbers when everything is up and running. Thank you! I presume I can run a chart control using similar methods? There are so many charts in my program that one form is not enough.
yes you can, good luck with your worj
Ty so much! This helped me with my school work a lot
that awesome :)
it say this - System.NullReferenceException: 'Object reference not set to an instance of an object.'
Thank you. Very clear and simple.
That was amazing, save me a lot of time
The name instance does not exist in current context. Am using a multi document winforms with parent and child forms. Any suggestions?
Using the method in this video, I opened the serial port in form 1 and read the value from the serial port in other forms. But other opened forms do not work simultaneously. What can I do about this situation?
Thank you so much i was trying to figure out how to do this!
how about when i click the button to open the other form the first form disappears or changed.
Hi, I want to do this but from form1 I want to be able to hide form 2 using a button.
So When you press a button on form 1 it will hide form2 something like (form2.Hide();) I have tried lots of ways and none of them are working
I'm not sure if you can help me but whenever I try accessing something from the other form it gives me this exception error: "Object reference not set to an instance of an object."
public partial class FormConfig : Form
{
public static FormConfig instance;
public TextBox tbCaminhoCadastros;
//Constructor
public FormConfig()
{
InitializeComponent();
instance = this;
tbCaminhoCadastros = txtCaminhoCadastros;
}
}
public partial class FormMain : Form
{
private void wathexSolutions_Load(object sender, EventArgs e)
{
FormConfig.instance.tbCaminhoCadastros.Text = "test";
}
}
The exeptions occurs for everything I try to access from "FormConfig" and not just for that textBox, it also happens when I try to access it from the "FormMain" Constructor too, are there anything I'm missing?
same
thank you for your helpfull videos, hope to see new ones too.
you're welcome, i am working on some good one that you'll see soon, its just hard for me to make time after work.
Thx man, you really helped me a lot!!
How about using com port in multiple windows? can you help me? I have to receive my data from com port in form2 and display it in my main form (form1)
You are a life saver man. Thank you!
I have a question. When I tried it, there was an error with the Show(). Is there something wrong with it?
Thanks sir for this tutorial, you help me a lot
Congratulations.Good job!
thank you :)
How am I supposed to get the form1 app on the add new items? I can't find it
I have a question regarding example 2.
Let's say I open multiple instances of "Form2" using "button1". If I write something on textbox2 and apply the change pressing "button change form2", will the label in all instances of Form2 change? Or will only the last opened form be affected?
After a bit of experimenting, the latter seems to be the case, but I wonder if it's possible to make the change apply to all instances of Form2 instead of just the last one. If you have any ideas I'd like to hear them.
In advance, thank you for your time!
form2.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace databtwforms
{
public partial class Form2 : Form
{
//list of all instance of form2 opened by form1
private static List instancesList;
public Label lab1;
//this constructor run only one time because its static for initialization of list
static Form2()
{
instancesList = new List();
}
public Form2()
{
InitializeComponent();
instancesList.Add(this);
lab1 = label1;
}
private void button1_Click(object sender, EventArgs e)
{
Form1.instance.tb1.Text = "set by form2";
}
//NEWLY CREATED METHOD
public static void ChangeAllText(string text)
{
foreach (var item in instancesList)
{
item.lab1.Text = text;
}
}
}
}
inside form1:
private void button2_Click(object sender, EventArgs e)
{
//USED THE NEWLY CREATED METHOD
Form2.ChangeAllText(textBox2.Text);
}
so bascially each time we are creating a form2 we are storing instance info in a list,
and when its time to change textbox we are change all the instances textboxes
@@HassaanRaza Yes, this works perfectly for what I've been working on. Huge thanks to you!
PS: My mom sends her thanks too!
hahah remember me in your prayers
Thank you my friend, you were very useful
Awesome, you made it so simple!!!
Great help! Thank you for this video! ^^
thats great, you're welcome :)
How to save it in database?
Like form1 data will show in form2 data and save it.
Hi i have question. how do send class data between multiple form?
Hello, I want a picture printed on one form and that picture to appear in the other. How can I?
how to insert and update data in just one button(save) in C# // I need some help
Great Technic, Thank you very much. It saved me a lot of work :)
thats awesome :)
Great Video - Thank you very much :)
you're welcome :)
for combobox instead of textbox how it will coded as puplic
how would u do this with only one form active and the other hidden?
If i would like to share information from FORM to FORM2, by in this case. To appear in Datagridview from From2. It´s the same proccess?
yes, if i remember correctly its the datagrid.datasource which contains you can tranfer it the same way.
thank you , I need it to my project
you saved my life thank you so much
:) live safely from now on.
I wanted to do this same command from a server to client, can you help me?
help! i want to make an OS and in it, I tried to detect whether a program is closed or minimized so when I tried to make the "public TextBox tb1;" part, I changed it to "public Form calculator" and I tried to do the "tb1 = textbox1;" and it looks like this "calculator = Form.Calculator;" but it doesn't work, could you help?
EDIT!!: i just remembered that instead of using the form name(Calculator.cs) for the same form(Calculator.cs), could have just typed in "calculator = this;" rather than "calculator = Form.Calculator;", still good video tho, its explains a lot of stuff i didn't understand
i didn't understood your comment, its really confusing
It is rare, but i have a warning about the posibility of being instance a null value. It has zero sense, and it doesn't does any damage, it is a curiosity.
don't worry its just a stupid warning from vs2022,
if you want to get rid of it use
example
Form? data type instead of Form
@@HassaanRaza yes i did, but after this everytime i use the instance the vs says something like the instance can be null. It doesn't matter, the trick works very well.
Thanks All of your coding !
Thank you from Kazakhstan
thanks for commenting brother, im from Paksitan :)
Hey great Video. I have a question when I create an instance of form 2 in the form 1 click event why can't I access methods/data using that instance name?
Form2 newForm2 = new Form2();
string title = newForm2.getTitle; //This doesn't work and says that there is no getTitle function)
and in Form2 I have defined
public string getTitle()
{
return titleTextBox.text;
}
Using your way works perfectly just wonder why.
it will show up!
string title = newForm2.getTitle();
@@HassaanRaza I had the () in the code just forget them here. The issue was I mistakenly made it
Form newForm2 = new Form2() instead of Form2 newForm2 = new Form2()
No idea how that happened.
How would I do this with radioButtons?
Thank you very much 👍👍 very usefull
Is this what we also call "Code to call form"?
we saving the reference of the form then using it to locate the form that we need to change, don't know if it called by the phrase you wrote.
@@HassaanRaza oh i'm so sorry I thought this is it. I was having a hard time finding something like what I said. Can't even see what is this.
Great Job Bro Adamsın
Can u plz tell how can we close form 1 through form 2
we'll that's a good question, you will be needing the reference of form 1 in your form 2, you can get the reference by "this" keyword
oh thank you this video help me to solve my problem
its great to know!
Very nice 👍👍👍
Thank you this helped me :)
Good💐💐💐👌
Best solution ! Thanks
very nice
my problem is for me that i cant figure out how to use a public vector in 2 forms?
make a new class put a public static vector there than you can use it in all forms
but how do i that? im new to this?. is it easy?
I'll make a video on it this weekend if you can wait.
bro first of all, thanks for the tutorial .. how about calling the form directly without creating an instance of it . inside form2 .. form1.textbox1.text .. what's wrong with it .. with all do respect .. it doesn't make sense to me to create multiple public variables in order to get data from the parent form .. I've been doing this for entire my life ..
form1 is not static, so you need the exact instance of form1 to work on thats why its important to create a variable.
(the variable store the exact instance of form1) that we want to change.
omg thank you so much man
Thanks for the vid
amazing
Thank you So Much!!!!!
thanks for this..
Thanks really a lot!
Thanks bro.
Bonjour
merci beaucoup
🌟🌟🌟🌟🌟
great
THANKS FOR THIS
thank you sir
Thank you!
Thank you
You are God. Thanks!
just a servant 😉 of God.
thanks it helped
thanks mate
Hello
I fucking love you
haha, nice!
Singleton.
I love u
im a man btw lol
;D its brotherly love then.
Hello Thank you for your Help, do you have the solution with VB.NET
same thing will work for vb, whats the issue?
I'm trying to do data transfer between two forms with VB.NET using a show method, I can't find the solution.
Thank you brother
Thank you Bro.