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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:47:55+00:00 2026-05-25T14:47:55+00:00

I am attempting to make an image control be displayed after a port check

  • 0

I am attempting to make an image control be displayed after a port check is run.

namespace MonitorFlux
{
    public partial class Form1 : Form
    {

        PortChecks PortCheckObject = new PortChecks();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        public static void CheckHTTP()
        {
            string hostname = "google.com";
            int portno = 80;

            IPAddress ipa = (IPAddress)Dns.GetHostAddresses(hostname)[0];

            Form1 formobject = new Form1();  // Create new class object, so can call other methods in the class
            try
            {
                System.Net.Sockets.Socket sock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
                sock.Connect(ipa, portno);
                if (sock.Connected == true) // Port is in use and connection is successful
                {

                    MessageBox.Show("Port is Open");
                    formobject.displayGreen();
                }
                sock.Close();

            }
            catch (System.Net.Sockets.SocketException ex)
            {
                if (ex.ErrorCode == 10061) // Port is unused and could not establish connection 
                {
                    formobject.displayRed();
                    MessageBox.Show("Port is Closed");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }

        }

        public void displayGreen()
        {
            pictureBox2.Visible = false;
            pictureBox1.Visible = true;
        }

        private void displayRed()
        {
            pictureBox2.Visible = true;
            pictureBox1.Visible = false;
        }

        private void testCheck_Click(object sender, EventArgs e)
        {
            CheckHTTP();
            // MessageBox.Show(PortCheckObject.httpport);
        }


    }
}

It won’t let me call a method from within the try clause e.g. displayRed()

So I create an object of Form1 class to run the displayRed() method, although when the method runs it doesn’t hide the image controls as expected. I assume this is because I have create another instance of the class. (If I run the method normally – not using an object, the image controls are hidden correctly.)

So I guess my questions is how can I get around this issue?

Please let me know if I have not explained the situation very well and I’ll try my best to elaborate. Thanks

  • 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-25T14:47:56+00:00Added an answer on May 25, 2026 at 2:47 pm

    CheckHTTP is static and you can’t call instance methods from a static method unless, like you’ve shown, you create a new object in that method, in which case you are working with a different object so you likely won’t get the behavior you want.

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

Sidebar

Related Questions

I'm attempting to make a parallax page, but when I change the placeholder image
I am attempting to make an app in which you can load an image
I am attempting to make a GET request for a single image on another
I am attempting to make a dynamic image with PHP, and I can't find
I am attempting to make a gallery that calls the image names from a
Attempting to make a NSObject called 'Person' that will hold the login details for
I'm attempting to make a StateMachine execute some database action between states. So I
I am attempting to make a program in C which presents a GUI and
I'm attempting to make use of the UIDocumentInteractionController mechanism in iPhone OS 3.2, but
I am attempting to make the sidebar in WordPress be made of a single

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.