BEST Way to SEND DATA between Multiple Forms | C# Windows Form

Поділитися
Вставка
  • Опубліковано 28 лис 2024

КОМЕНТАРІ • 147

  • @HassaanRaza
    @HassaanRaza  Рік тому +1

    CHECK THIS OUT!
    How to Buy Website Domain & Hosting, Complete Simple Procedure
    ua-cam.com/video/a-3UFt1r_1I/v-deo.html

  • @ricklangston8895
    @ricklangston8895 3 роки тому +18

    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.

    • @HassaanRaza
      @HassaanRaza  3 роки тому +5

      thanks man! thank you so much your appreciation inspire us creators to do more 😁

  • @konichiwaya2448
    @konichiwaya2448 3 роки тому +2

    this just answered 5 pages of modules, I've been fixing my project for 2 weeks! THANK YOU SO MUCH!!!

    • @HassaanRaza
      @HassaanRaza  3 роки тому

      thats is super awesome to know! best of luck with you project.

  • @viniciusmachadovianna
    @viniciusmachadovianna Рік тому +2

    This helped me with an issue I was facing about one whole week. I'm immensely grateful for this content, many blessings for you!

    • @HassaanRaza
      @HassaanRaza  Рік тому +1

      thanks mate, keep going.
      good luck with whatever you are making :)

  • @warzonerustproject7227
    @warzonerustproject7227 3 роки тому +1

    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

  • @mohamedhussein9679
    @mohamedhussein9679 3 роки тому +2

    THIS IS THE BEST!!! THANK YOU 3000!
    I have been looking for this for over 3 weeks now!

    • @HassaanRaza
      @HassaanRaza  3 роки тому +1

      yup its a little tricky to figure.

  • @normal.2002
    @normal.2002 Рік тому +1

    After 2 years and i am here
    Thanks you Indian teacher

    • @HassaanRaza
      @HassaanRaza  Рік тому +1

      haha that's awesome, cheers!
      by the way I'm from Pakistan (so not indian)

    • @normal.2002
      @normal.2002 Рік тому +1

      @@HassaanRaza ohh i am so sorry
      thank you my Pakistan teacher 🥰🥰

    • @HassaanRaza
      @HassaanRaza  Рік тому +1

      hehe

  • @sumaidch1124
    @sumaidch1124 3 місяці тому +1

    Man, You made my Day

  • @zuratchankvetadze6646
    @zuratchankvetadze6646 7 місяців тому

    omg.. you help me a lot.. no blackbox no stackover... thank u man

    • @HassaanRaza
      @HassaanRaza  7 місяців тому

      haha im glad i could be of help :)

  • @janstergaard703
    @janstergaard703 Рік тому

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

  • @ricklangston8895
    @ricklangston8895 3 роки тому +1

    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

  • @fetrush6383
    @fetrush6383 7 місяців тому

    Hi thank you i look for this method over 5 month you saved my life :D

    • @HassaanRaza
      @HassaanRaza  7 місяців тому +1

      hahaha glad you found me XD

  • @dominikweclewski5753
    @dominikweclewski5753 3 роки тому

    Thank you so much. I looked for this for 5 days.

  • @BoorgPL
    @BoorgPL 2 роки тому +2

    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.

  • @francescosantone1858
    @francescosantone1858 2 роки тому

    Perfect tutorial 😍... You are saved my project

  • @trevorloughlin1492
    @trevorloughlin1492 3 роки тому +1

    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.

    • @HassaanRaza
      @HassaanRaza  3 роки тому

      yes you can, good luck with your worj

  • @mihailoradovanovic7283
    @mihailoradovanovic7283 Рік тому +1

    Ty so much! This helped me with my school work a lot

  • @Trexstudio1
    @Trexstudio1 2 роки тому +1

    it say this - System.NullReferenceException: 'Object reference not set to an instance of an object.'

  • @thantsintun100
    @thantsintun100 3 місяці тому

    Thank you. Very clear and simple.

  • @khaibaromari8178
    @khaibaromari8178 3 роки тому +2

    That was amazing, save me a lot of time

  • @OtsileM
    @OtsileM Рік тому

    The name instance does not exist in current context. Am using a multi document winforms with parent and child forms. Any suggestions?

  • @semrasanlioglu
    @semrasanlioglu Рік тому

    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?

  • @signaller
    @signaller 2 роки тому

    Thank you so much i was trying to figure out how to do this!

  • @mahersabit9265
    @mahersabit9265 Місяць тому

    how about when i click the button to open the other form the first form disappears or changed.

  • @44D3N
    @44D3N Рік тому

    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

  • @tadehack_ctz
    @tadehack_ctz Рік тому

    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?

  • @burakoranler6655
    @burakoranler6655 2 роки тому

    thank you for your helpfull videos, hope to see new ones too.

    • @HassaanRaza
      @HassaanRaza  2 роки тому

      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.

  • @Kamil32-nq6be
    @Kamil32-nq6be 4 місяці тому

    Thx man, you really helped me a lot!!

  • @fitrahazizah7267
    @fitrahazizah7267 3 роки тому

    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)

  • @muhammedareeb1464
    @muhammedareeb1464 3 роки тому

    You are a life saver man. Thank you!

  • @nightskyblackx7422
    @nightskyblackx7422 2 роки тому

    I have a question. When I tried it, there was an error with the Show(). Is there something wrong with it?

  • @rashidselemani475
    @rashidselemani475 2 роки тому

    Thanks sir for this tutorial, you help me a lot

  • @manuelcornejo7405
    @manuelcornejo7405 2 роки тому

    Congratulations.Good job!

  • @javasocketexception
    @javasocketexception 2 роки тому

    How am I supposed to get the form1 app on the add new items? I can't find it

  • @ThisIsABadIdeaSrsly
    @ThisIsABadIdeaSrsly 3 роки тому +4

    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!

    • @HassaanRaza
      @HassaanRaza  3 роки тому +3

      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;
      }
      }
      }
      }

    • @HassaanRaza
      @HassaanRaza  3 роки тому +1

      inside form1:
      private void button2_Click(object sender, EventArgs e)
      {
      //USED THE NEWLY CREATED METHOD
      Form2.ChangeAllText(textBox2.Text);
      }

    • @HassaanRaza
      @HassaanRaza  3 роки тому +3

      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

    • @ThisIsABadIdeaSrsly
      @ThisIsABadIdeaSrsly 3 роки тому +1

      @@HassaanRaza Yes, this works perfectly for what I've been working on. Huge thanks to you!
      PS: My mom sends her thanks too!

    • @HassaanRaza
      @HassaanRaza  3 роки тому +3

      hahah remember me in your prayers

  • @RasitTunc15
    @RasitTunc15 Рік тому

    Thank you my friend, you were very useful

  • @KaioPatrick
    @KaioPatrick 3 роки тому

    Awesome, you made it so simple!!!

  • @timothylennryd2528
    @timothylennryd2528 Рік тому

    Great help! Thank you for this video! ^^

  • @beelogtv9549
    @beelogtv9549 2 роки тому

    How to save it in database?
    Like form1 data will show in form2 data and save it.

  • @sabuhiamirov288
    @sabuhiamirov288 3 роки тому

    Hi i have question. how do send class data between multiple form?

  • @enginargaming7262
    @enginargaming7262 3 роки тому

    Hello, I want a picture printed on one form and that picture to appear in the other. How can I?

  • @abdulqahar9852
    @abdulqahar9852 Рік тому

    how to insert and update data in just one button(save) in C# // I need some help

  • @alikemalkulful
    @alikemalkulful 2 роки тому

    Great Technic, Thank you very much. It saved me a lot of work :)

  • @DjSashaWaksOfficial
    @DjSashaWaksOfficial Рік тому

    Great Video - Thank you very much :)

  • @stepbystep1270
    @stepbystep1270 Рік тому

    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?

  • @picexcelbi_ytb
    @picexcelbi_ytb 2 роки тому

    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?

    • @HassaanRaza
      @HassaanRaza  2 роки тому

      yes, if i remember correctly its the datagrid.datasource which contains you can tranfer it the same way.

  • @sgd1925
    @sgd1925 10 місяців тому

    thank you , I need it to my project

  • @med6402
    @med6402 2 роки тому

    you saved my life thank you so much

  • @Cesar_Une
    @Cesar_Une 2 роки тому

    I wanted to do this same command from a server to client, can you help me?

  • @PrivacyNProgramming
    @PrivacyNProgramming 3 роки тому

    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

    • @HassaanRaza
      @HassaanRaza  3 роки тому

      i didn't understood your comment, its really confusing

  • @000adrianelpiola000
    @000adrianelpiola000 Рік тому +1

    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
      @HassaanRaza  Рік тому

      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

    • @000adrianelpiola000
      @000adrianelpiola000 Рік тому +1

      @@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.

  • @davidkei2114
    @davidkei2114 Рік тому

    Thanks All of your coding !

  • @ЧУДОЮДО-к9х
    @ЧУДОЮДО-к9х 2 роки тому

    Thank you from Kazakhstan

    • @HassaanRaza
      @HassaanRaza  2 роки тому

      thanks for commenting brother, im from Paksitan :)

  • @Isamu1013
    @Isamu1013 2 роки тому

    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
      @HassaanRaza  2 роки тому

      it will show up!
      string title = newForm2.getTitle();

    • @Isamu1013
      @Isamu1013 2 роки тому

      @@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.

  • @riverofgolds
    @riverofgolds Рік тому

    How would I do this with radioButtons?

  • @chathuskamahanama7606
    @chathuskamahanama7606 3 роки тому

    Thank you very much 👍👍 very usefull

  • @Alexandra-jc5wc
    @Alexandra-jc5wc 2 роки тому +1

    Is this what we also call "Code to call form"?

    • @HassaanRaza
      @HassaanRaza  2 роки тому

      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.

    • @Alexandra-jc5wc
      @Alexandra-jc5wc 2 роки тому

      @@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.

  • @onurtimur524
    @onurtimur524 2 роки тому

    Great Job Bro Adamsın

  • @varishaaslam563
    @varishaaslam563 2 роки тому +1

    Can u plz tell how can we close form 1 through form 2

    • @HassaanRaza
      @HassaanRaza  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

  • @기린퇴물임
    @기린퇴물임 3 роки тому

    oh thank you this video help me to solve my problem

  • @FarhanAli-km5id
    @FarhanAli-km5id 2 роки тому

    Very nice 👍👍👍

  • @martinqmtakacs4145
    @martinqmtakacs4145 2 роки тому

    Thank you this helped me :)

  • @kurdishprogramming4698
    @kurdishprogramming4698 2 роки тому

    Good💐💐💐👌

  • @xxjaxxful
    @xxjaxxful 3 роки тому

    Best solution ! Thanks

  • @tetraldinodanatividademart4242
    @tetraldinodanatividademart4242 10 місяців тому +1

    very nice

  • @scrapylegit4690
    @scrapylegit4690 3 роки тому

    my problem is for me that i cant figure out how to use a public vector in 2 forms?

    • @HassaanRaza
      @HassaanRaza  3 роки тому +1

      make a new class put a public static vector there than you can use it in all forms

    • @scrapylegit4690
      @scrapylegit4690 3 роки тому

      but how do i that? im new to this?. is it easy?

    • @HassaanRaza
      @HassaanRaza  3 роки тому

      I'll make a video on it this weekend if you can wait.

  • @SadamKam
    @SadamKam 2 роки тому

    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 ..

    • @HassaanRaza
      @HassaanRaza  2 роки тому

      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.

  • @MarethaNurAzizah
    @MarethaNurAzizah Рік тому

    omg thank you so much man

  • @rafaelrodriguessilva9994
    @rafaelrodriguessilva9994 Рік тому

    Thanks for the vid

  • @shiro5410
    @shiro5410 Рік тому

    amazing

  • @andrearruda9005
    @andrearruda9005 2 роки тому

    Thank you So Much!!!!!

  • @jaimeelipascua8528
    @jaimeelipascua8528 2 роки тому

    thanks for this..

  • @guanyuren3008
    @guanyuren3008 Рік тому

    Thanks really a lot!

  • @mustafakemaltaskn4303
    @mustafakemaltaskn4303 Рік тому

    Thanks bro.

  • @aliardi4859
    @aliardi4859 Рік тому

    Bonjour
    merci beaucoup
    🌟🌟🌟🌟🌟

  • @sonhong6253
    @sonhong6253 2 роки тому

    great

  • @irenecarlotto2982
    @irenecarlotto2982 2 роки тому

    THANKS FOR THIS

  • @pako_tube6898
    @pako_tube6898 2 роки тому

    thank you sir

  • @hamzaaitbrik
    @hamzaaitbrik 2 роки тому

    Thank you!

  • @sinarbitonlineservices65
    @sinarbitonlineservices65 Рік тому

    Thank you

  • @smoua4588
    @smoua4588 3 роки тому

    You are God. Thanks!

  • @IvanSchob
    @IvanSchob 3 роки тому

    thanks it helped

  • @Maolana_ModiG
    @Maolana_ModiG Рік тому

    thanks mate

  • @nafisahamid3867
    @nafisahamid3867 10 місяців тому

    Hello

  • @charlyflu9700
    @charlyflu9700 2 роки тому

    I fucking love you

  • @ThaoMeoTV
    @ThaoMeoTV 3 роки тому

    Singleton.

  • @agressive8050
    @agressive8050 3 роки тому

    I love u
    im a man btw lol

  • @a2ei750
    @a2ei750 2 роки тому

    Hello Thank you for your Help, do you have the solution with VB.NET

    • @HassaanRaza
      @HassaanRaza  2 роки тому

      same thing will work for vb, whats the issue?

    • @a2ei750
      @a2ei750 2 роки тому

      I'm trying to do data transfer between two forms with VB.NET using a show method, I can't find the solution.

  • @9962587075
    @9962587075 Рік тому

    Thank you brother

  • @MarejKourani
    @MarejKourani 6 місяців тому

    Thank you Bro.