Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:33:52+00:00 2026-05-26T13:33:52+00:00

When a byte from the serial port is received, it enters this handler correctly,

  • 0

When a byte from the serial port is received, it enters this handler correctly, but my label on the GUI does not change. Edit: Yes, it is in the same class as the GUI
Edit 2 The function declaration does not need to be ‘static’…I merely copy-pasted an example from msdn
edit 3 It works after getting rid of the static decleration and using something like this.
Thanks for your help

private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            Form1 gui = new Form1(); //main GUI

            try
            {
                SerialPort sp = (SerialPort)sender;
                string indata = sp.ReadExisting();
                //gui.rxLabel.Text = indata;
                gui.txLabel.Text = "testttingg";
            }
            .......
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:33:53+00:00Added an answer on May 26, 2026 at 1:33 pm

    Why are you declaring a new instance of your form? Just use your form’s txLabel

    In c#:

    this.txLabel.Text = "testing";

    In vb.net:

    Me.txLabel.Text = "testing"

    In the sample code you posted you are creating a new instance / reference to your actual form. Use the existing instance, in addition, use this rather then a new instance.

    I had to edit my question as I noticed you were using a static method.

    Try this:

     public static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
            {
                Form1 f = (Form1) sender;
    
                f.textBox1.Text = "testing";
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                DataReceivedHandler(this, null);     
            }
    

    Of course I am just calling DataReceivedHandler() from a button event, you can call it from your own event. Point being is you need to pass the current instance, this to the function. Once inside the function do not create a new instance of the form, just set a reference to the current form and use that reference to apply the settings to the property (txtBox or Label or whatever).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the code below from a website,and this way of serial port reading
The program listen to messages from serial port in the form or where first
I am receiving data from a device that's sending information over the serial port
I'm trying to open and read from a serial port using the System.IO.Ports.SerialPort class.
I am sending data from a linux application through serial port to an embedded
Hello I'm trying to read some data from the serial port and record it
I'm trying to read raw bytes from a serial port sent by a IEC
I'm trying to read some data on the Serial Port but I doesn't have
this code checks if i have mail from gmail, then sends m over serial
How can i generate bytecode (Byte[]) from a String at runtime, without using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.