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

  • SEARCH
  • Home
  • 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 8442933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:58:46+00:00 2026-06-10T08:58:46+00:00

I am making a Time clock for fun and to learn C#. I have

  • 0

I am making a Time clock for fun and to learn C#.

I have the time down, and the start, stop, clear.

However I am having issues with a “Notes” section. Ideally I’d like to be able to write notes into a field, and have an “Edit” button to allow the user to open a window for more options relating to text editing. (with the text from the Form1 rich text box)

My issue comes from copying the data from one form to another.

Here is the code:

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;

namespace PunchOut
{
public partial class PunchOut : Form
{
    public PunchOut()
    {
        InitializeComponent();
    }
    int i = 0;
    private void button3_Click(object sender, EventArgs e)
    {
        timer1.Enabled = true;
        i++;

        TimeSpan t = TimeSpan.FromSeconds(i);

        textBox2.Text = string.Format("{0:D2}:{1:D2}:{2:D2}",
                                        t.Hours,
                                        t.Minutes,
                                        t.Seconds);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        timer1.Enabled = false;

    }

    private void button1_Click(object sender, EventArgs e)
    {
        textBox2.Clear();
        textBox2.Text = ("00:00:00").ToString();
    }

    private void button6_Click(object sender, EventArgs e)
    {

    }

    public void button4_Click(object sender, EventArgs e)
    {
        new Form2().Show();
        richTextBox1.Text = Form2.richTextBox1.Text;

    }
}
}

Here is the Form2 code:

namespace PunchOut
   {
    public partial class Form2 : Form
    {
       public Form2()
       {
            InitializeComponent();
       }

        public void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            richTextBox1.Text = PunchOut.richTextBox1.Text;
        }
    }
}

Currently, I get an error that states:

an object reference is required for the non-static field, method, or property ‘PunchOut.PunchOut.richTextBox1’

and

an object reference is required for the non-static field, method, or property ‘PunchOut.Form2.richTextBox1’

Why do I get these errors?

  • 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-06-10T08:58:48+00:00Added an answer on June 10, 2026 at 8:58 am

    lots of unneeded work going on there. I hope I explained this well enough

    Breakdown:
    We add a String Member Variable so that we can put the contents of a RichTextBox into a string and pass that instead of using the RichTextbox control.
    We change the constructor to take a string parameter which is the RTF text that you want to change. Now Form2 can change any RTF text and not be specifically tied to just the richTextbox1 on the punchoutForm.

    We then change the updating of the member variable to when the form is closing otherwise you are changing it with each keystroke which is a lot of unnecessary method calls.

    namespace PunchOut
    {
        public partial class Form2 : Form
        {
             public String richText;
             public Form2(String rText)
             {    
                  InitializeComponent();
                  this.richTextBox1.Rtf = rText;
    
             }
    
            private void Form2_FormClosing(object sender, FormClosingEventArgs e)
            {
                richText = this.richTextBox1.Rtf;
            }
        }
    }
    

    Then in your button4_Click. Use Rtf to include the codes otherwise just use a plain textbox

    Now in your button click event handler we create a new form and assign it to a variable. We then call showdialog. The reason for showdialog is that this will make the form the top most form so that a user cannot go back to the punchout form and make a change to the richtextbox which would then make the text in the Form2 obsolete as it would no longer represent the correct RTF text in the punchout form. When the user is done editing the text and closes the form we then request the edited rtf text by accessing the richText Member Variable of Form2. The reason you can access this after the form has closed is that the form is not disposed until the method returns, your local variable lives within the scope of the method.

    public void button4_Click(object sender, EventArgs e)
    {              
        Form2 f2 = new Form2(richTextBox1.Rtf);
        f2.ShowDialog();
        richTextBox1.Rtf= f2.richText;
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a small on-line clock (both for fun and to learn a bit
I'm thinking about making a Hubot clock-based notifier (think It's 5, time to go
I have tough time making this design decision. I could go with traditional new
I'm having a hard time making sense of the Doctrine manual's explanation of cascade
I'm having a hard time making the connection between testing and code. I could
Hello I am having a hard time making this UI element look the way
For some time i have been making more or less little games. One level
I have a pretty basic assignment, but am having an issue making my main
I'm planning on making a clock. An actual clock, not something for Windows. However,
I'm making HTML5 canvas application. For animation, I need high resolution clock time. How

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.