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 6023755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:03:10+00:00 2026-05-23T04:03:10+00:00

I have two forms = Form1.CS and SMS.CS on the first form (Form1) i’ve

  • 0

I have two forms = Form1.CS and SMS.CS
on the first form (Form1) i’ve configured and ready to work serialport1. I have button which is called send message. This button opens new form called SMS.cs.

private void SMS_Click(object sender, EventArgs e)
    {
        SMS settings = new SMS();
        settings.ShowDialog();
    }

I’d like to use my configured serialport1 on to forms: Form1 and form SMS.cs. It’s also possible to receive from form SMS data, and send it using serialport1 on Form1 for example:

 private void SMS_Click(object sender, EventArgs e)
    {
        SMS settings = new SMS();
        settings.ShowDialog();
        SerialPort1.Writeln(Data from form SMS)
    }

but i don’t know how to do it. The best idea in my opinion is to send data directly from SMS form..

Edit:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace WindowsFormsApplication1
{
    public partial class SMSForm : Form
    {
        SerialPort SerialP;

        public SMSForm(Object SerialP)
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) 
        {
            SerialP.WriteLine("ATI");
        }
    }
}
  • 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-23T04:03:10+00:00Added an answer on May 23, 2026 at 4:03 am

    Form1 is the SerialPort controller – that is, Form1 configures SerialPort. If you have an event that affects SerialPort, such as `SerialPort1.Writeln’, you should pass a method reference to the dialog constuctor. This will logically keep classes separate while sharing methods.

    You can create a custom EventArgs object to pass the string back to your SerialPort:

    public class WriteToSerialPortEventArgs : EventArgs
    {
        public WriteToSerialPortEventArgs (string Write)
        { WriteBytes = Encoding.GetBytes(write); }  // simplified - see MSDN for more options 
    
        public byte[] WriteBytes
        { get; private set; }   
    }
    

    Form1 sample event delegate passed to your SMS dialog:

    void OnWriteToSerialPort(object sender, WriteToSerialPortEventArgs e )
    {
        SerialPort1.WriteLine(e.WriteBytes);
    }
    

    Write your SMS constructor:

    // field
    Action<object, WriteToSerialPortEventArgs> writeDelegate;
    
    public SMS (Action<object, WriteToSerialPortEventArgs> writeDelegate)
    {
        this.writeDelegate = writeDelegate;
        this.button1.Click += new EventHandler(button1_Click);
    }
    

    … SMS event delegate:

    void button1_Click(object sender, EventArgs e)
    {
        writeDelegate.Invoke(sender, new WriteToSerialPortEventArgs (txtBox.Text);
    }
    

    Technically, you don’t need the full Invoke(...) method signature. I included it for completeness and can be written as:

    writeDelegate(sender, new WriteToSerialPortEventArgs (txtBox.Text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two forms, form A and form B. These forms must differ in
I am using standard windows forms controls under C#. I have two controls which
For simplicity lets say I have two flex mxml pages. form.mxml button.mxml If the
Let's say I have two forms: form1 and form2 . After pressing a NEXT_COMMAND
I have two windows forms.Now I have to close first one and show the
I have a formset that have two forms. forms: class PresClinicForm(forms.Form): _names = list(PresClinic.objects.values_list('pres_clinic_id',
In my vb program, I have two forms that work together to allow you
I have two forms on a page (one is being grabbed by AJAX). I
I have two forms in my rails app. They both exist in separate tabs
I have two completely different forms in one template. How to process them in

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.