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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:34:27+00:00 2026-06-15T19:34:27+00:00

iam new to C# i got some problem, i am create some picturebox in

  • 0

iam new to C#

i got some problem, i am create some picturebox in the Form1 through Form.cs[Design]

i want to accessing the picture box from Form1

so i have to create an object on other class to access Form1.picturebox1

but i can get it right, can some one help me

namespace RaceGame{
class Greyhound
{

    Form1 runner;

    public int StartingPosition = 13;
    public int RacetrackLength = 420;
    public PictureBox MyPictureBox = null;
    public int Location = 0;
    public Random Randomizer;

    public void Run()
    {

        runner.pictureDog1.Location = new Point(13, 100);
    }     
}

this is Form1

namespace RaceGame{public partial class Form1 : Form
{
    Greyhound racing = new Greyhound();
    public Form1()
    {
        InitializeComponent();
    }

    private void raceButton_Click(object sender, EventArgs e)
    {
        racing.Run();
    }



}

}

  • 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-15T19:34:28+00:00Added an answer on June 15, 2026 at 7:34 pm

    Based on the code you’ve provided, your Form1 or ‘runner’ isn’t being assigned.
    You have two options –
    1) make your runner public like so

    public Form1 runner;

    this will allow you to (in your form, not your class) assign the form to this property

    public class Form1
    {
            protected void Form1_Load(object sender, EventArgs e)
            {
                  Greyhound gh = new Greyhound();
                  gh.runner = this;//this line here
                  //then you can call gh.Run()
            }
    }
    

    the other option is to use a constructor, like so –

    class Greyhound
    {
    
        Form1 runner;
    
        public int StartingPosition = 13;
        public int RacetrackLength = 420;
        public PictureBox MyPictureBox = null;
        public int Location = 0;
        public Random Randomizer;
    
        //here
        public Greyhound(Form1 form)
        {
            this.runner = form;
        }
        public void Run()
        {
    
            runner.pictureDog1.Location = new Point(13, 100);
        }     
    }
    

    this will pass the form into the greyhound class for you to access, then in your form code –

    public class Form1
    {
            protected void Form1_Load(object sender, EventArgs e)
            {
                  Greyhound gh = new Greyhound(this);//pass the form as 'this'
                  //then you can call gh.Run()
            }
    }
    

    EDIT:
    based on the form code you gave –

    namespace RaceGame
    {
        public partial class Form1 : Form
        {
             Greyhound racing = new Greyhound();
             public Form1()
             {
                InitializeComponent();
             }
    
             private void raceButton_Click(object sender, EventArgs e)
             {
                  racing.runner = this;//assign property here
                  racing.Run();
             }
        }
    }
    

    and the Greyhound class

    namespace RaceGame
    {
        class Greyhound 
        {
    
            public Form1 runner;//make property public
    
            public int StartingPosition = 13;
            public int RacetrackLength = 420;
            public PictureBox MyPictureBox = null;
            public int Location = 0;
            public Random Randomizer;
    
            public void Run()
            {
    
                runner.pictureDog1.Location = new Point(13, 100);
            }      
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I got a problem with saving my pdf. I want to create an
I have got a new problem .. I can't fix it .. I create
I am rather new to VIM. I got some source code and this is
I am new to programming but had some spare time and just got a
I am new to the iPhone development. I got stuck with a problem. I
I'm working on some code, and got stuck on this stored procedure problem... Have
I am new to Flex (got assigned to maintain an old project at work)
I am new to this asp net mvc but got a strong background in
I am new in Java and have got as a task to find out,
I am new to android. I got one issue during run my first hello

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.