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

Поделиться
HTML-код
  • Опубликовано: 27 фев 2021
  • the video shows that how can you send data from one form to another form in c#
    modify or access data between forms
    so you can change data of a form, from another form using this method.
    transfer data between forms in windows form c# vb.net.
    pass data form one form to other
    Software Used in This Tutorial:
    -Visual Studios 2019 Community Edition
    Project Description:
    -Based on Windows Form C#.
  • НаукаНаука

Комментарии • 142

  • @HassaanRaza
    @HassaanRaza  11 месяцев назад +1

    CHECK THIS OUT!
    How to Buy Website Domain & Hosting, Complete Simple Procedure
    ruclips.net/video/a-3UFt1r_1I/видео.html

  • @ricklangston8895
    @ricklangston8895 2 года назад +15

    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  2 года назад +5

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

  • @mohamedhussein9679
    @mohamedhussein9679 2 года назад +1

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

    • @HassaanRaza
      @HassaanRaza  2 года назад +1

      yup its a little tricky to figure.

  • @viniciusmachadovianna
    @viniciusmachadovianna Год назад +1

    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 2 года назад +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

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

  • @ricklangston8895
    @ricklangston8895 2 года назад +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

  • @janstergaard703
    @janstergaard703 10 месяцев назад

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

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

  • @ProgramateEstaNene69
    @ProgramateEstaNene69 4 месяца назад

    Thank you very much man. I've tried to do something for my project and didn't know how to do it. Plus, here I've learned that of public static thing, or how to do things global for the Forms. Thanks.

    • @HassaanRaza
      @HassaanRaza  4 месяца назад

      that nice, keep learning happy coding :)

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

  • @Trexstudio1
    @Trexstudio1 Год назад +1

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

  • @signaller
    @signaller 2 года назад

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

  • @zuratchankvetadze6646
    @zuratchankvetadze6646 Месяц назад

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

    • @HassaanRaza
      @HassaanRaza  Месяц назад

      haha im glad i could be of help :)

  • @dominikweclewski5753
    @dominikweclewski5753 2 года назад

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

  • @fetrush6383
    @fetrush6383 Месяц назад

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

    • @HassaanRaza
      @HassaanRaza  Месяц назад +1

      hahaha glad you found me XD

  • @OtsileM
    @OtsileM Год назад

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

  • @fitrahazizah7267
    @fitrahazizah7267 2 года назад

    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)

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

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

  • @muhammedareeb1464
    @muhammedareeb1464 3 года назад

    You are a life saver man. Thank you!

  • @mihailoradovanovic7283
    @mihailoradovanovic7283 Год назад +1

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

  • @normal.2002
    @normal.2002 8 месяцев назад +1

    After 2 years and i am here
    Thanks you Indian teacher

    • @HassaanRaza
      @HassaanRaza  8 месяцев назад +1

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

    • @normal.2002
      @normal.2002 8 месяцев назад +1

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

    • @HassaanRaza
      @HassaanRaza  8 месяцев назад +1

      hehe

  • @nightskyblackx7422
    @nightskyblackx7422 2 года назад

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

  • @KaioPatrick
    @KaioPatrick 2 года назад

    Awesome, you made it so simple!!!

  • @foxyeo1
    @foxyeo1 Год назад

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

  • @khaibaromari8178
    @khaibaromari8178 3 года назад +2

    That was amazing, save me a lot of time

  • @enginargaming7262
    @enginargaming7262 2 года назад

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

  • @beelogtv9549
    @beelogtv9549 2 года назад

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

  • @alikemalkulful
    @alikemalkulful Год назад

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

  • @sgd1925
    @sgd1925 4 месяца назад

    thank you , I need it to my project

  • @ThisIsABadIdeaSrsly
    @ThisIsABadIdeaSrsly 2 года назад +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  2 года назад +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  2 года назад +1

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

    • @HassaanRaza
      @HassaanRaza  2 года назад +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 2 года назад +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  2 года назад +3

      hahah remember me in your prayers

  • @rashidselemani475
    @rashidselemani475 Год назад

    Thanks sir for this tutorial, you help me a lot

  • @RasitTunc15
    @RasitTunc15 8 месяцев назад

    Thank you my friend, you were very useful

  • @stepbystep1270
    @stepbystep1270 Год назад

    for combobox instead of textbox how it will coded as puplic

  • @francescosantone1858
    @francescosantone1858 2 года назад

    Perfect tutorial 😍... You are saved my project

  • @sabuhiamirov288
    @sabuhiamirov288 2 года назад

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

  • @abdulqahar9852
    @abdulqahar9852 Год назад

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

  • @davidkei2114
    @davidkei2114 Год назад

    Thanks All of your coding !

  • @burakoranler6655
    @burakoranler6655 Год назад

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

    • @HassaanRaza
      @HassaanRaza  Год назад

      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.

  • @tadehack_ctz
    @tadehack_ctz 10 месяцев назад

    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?

    • @sonr0xz
      @sonr0xz 8 месяцев назад

      same

  • @Cesar_Une
    @Cesar_Une 2 года назад

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

  • @MarvelAnchor
    @MarvelAnchor 10 месяцев назад

    how would u do this with only one form active and the other hidden?

  • @IBEZU_ytb
    @IBEZU_ytb Год назад

    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  Год назад

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

  • @timothylennryd2528
    @timothylennryd2528 Год назад

    Great help! Thank you for this video! ^^

  • @chathuskamahanama7606
    @chathuskamahanama7606 2 года назад

    Thank you very much 👍👍 very usefull

  • @PrivacyNProgramming
    @PrivacyNProgramming 2 года назад

    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  2 года назад

      i didn't understood your comment, its really confusing

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

  • @xxjaxxful
    @xxjaxxful 2 года назад

    Best solution ! Thanks

  • @riverofgolds
    @riverofgolds Год назад

    How would I do this with radioButtons?

  • @manuelcornejo7405
    @manuelcornejo7405 2 года назад

    Congratulations.Good job!

  • @martinqmtakacs4145
    @martinqmtakacs4145 2 года назад

    Thank you this helped me :)

  • @tetraldinodanatividademart4242
    @tetraldinodanatividademart4242 4 месяца назад +1

    very nice

  • @DjSashaWaksOfficial
    @DjSashaWaksOfficial 6 месяцев назад

    Great Video - Thank you very much :)

  • @FarhanAli-km5id
    @FarhanAli-km5id 2 года назад

    Very nice 👍👍👍

  • @kurdishprogramming4698
    @kurdishprogramming4698 Год назад

    Good💐💐💐👌

  • @andrearruda9005
    @andrearruda9005 Год назад

    Thank you So Much!!!!!

  • @guanyuren3008
    @guanyuren3008 8 месяцев назад

    Thanks really a lot!

  • @user-cs2su7ij5e
    @user-cs2su7ij5e 11 дней назад

    Thank you Bro.

  • @hamzaaitbrik
    @hamzaaitbrik 2 года назад

    Thank you!

  • @sonhong6253
    @sonhong6253 Год назад

    great

  • @med6402
    @med6402 Год назад

    you saved my life thank you so much

  • @shiro5410
    @shiro5410 Год назад

    amazing

  • @user-tm8ej8st6l
    @user-tm8ej8st6l 2 года назад

    Thank you from Kazakhstan

    • @HassaanRaza
      @HassaanRaza  2 года назад

      thanks for commenting brother, im from Paksitan :)

  • @jaimeelipascua8528
    @jaimeelipascua8528 Год назад

    thanks for this..

  • @sinarbitonlineservices65
    @sinarbitonlineservices65 7 месяцев назад

    Thank you

  • @000adrianelpiola000
    @000adrianelpiola000 11 месяцев назад +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  11 месяцев назад

      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 11 месяцев назад +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.

  • @user-fs6wk2ns3g
    @user-fs6wk2ns3g 3 года назад

    oh thank you this video help me to solve my problem

  • @mustafakemaltaskn4303
    @mustafakemaltaskn4303 Год назад

    Thanks bro.

  • @pako_tube6898
    @pako_tube6898 Год назад

    thank you sir

  • @irenecarlotto2982
    @irenecarlotto2982 Год назад

    THANKS FOR THIS

  • @MarethaNurAzizah
    @MarethaNurAzizah 6 месяцев назад

    omg thank you so much man

  • @aliardi4859
    @aliardi4859 Год назад

    Bonjour
    merci beaucoup
    🌟🌟🌟🌟🌟

  • @rafaelrodriguessilva9994
    @rafaelrodriguessilva9994 Год назад

    Thanks for the vid

  • @Maolana_ModiG
    @Maolana_ModiG Год назад

    thanks mate

  • @scrapylegit4690
    @scrapylegit4690 2 года назад

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

    • @HassaanRaza
      @HassaanRaza  2 года назад +1

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

    • @scrapylegit4690
      @scrapylegit4690 2 года назад

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

    • @HassaanRaza
      @HassaanRaza  2 года назад

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

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

  • @IvanSchob
    @IvanSchob 2 года назад

    thanks it helped

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

  • @SadamKam
    @SadamKam Год назад

    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  Год назад

      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.

  • @onurtimur524
    @onurtimur524 2 года назад

    Great Job Bro Adamsın

  • @smoua4588
    @smoua4588 2 года назад

    You are God. Thanks!

    • @HassaanRaza
      @HassaanRaza  2 года назад +1

      just a servant 😉 of God.

  • @nafisahamid3867
    @nafisahamid3867 4 месяца назад

    Hello

  • @charlyflu9700
    @charlyflu9700 2 года назад

    I fucking love you

  • @ThaoMeoTV
    @ThaoMeoTV 2 года назад

    Singleton.

  • @agressive8050
    @agressive8050 2 года назад

    I love u
    im a man btw lol

    • @HassaanRaza
      @HassaanRaza  2 года назад +1

      ;D its brotherly love then.

  • @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 8 месяцев назад

    Thank you brother