Changing a picture box visibility from C# code
NickName:Pardon_me Ask DateTime:2014-08-20T07:51:43

Changing a picture box visibility from C# code

So I tried to create a new form and reference it...the compiler didn't mind this but it clearly wasn't changing the visibility of my picturebox. this is how I was calling my method found in my form, FROM my c# script.

Form1 updateForm = new Form1();
updateForm.setLights();

It called the method, and seemed like it worked! Until I read a post about instancing forms, and how by creating a "new" instance of Form1, that anything referenced by my updateForm would not change what I would see on my Form1.

So what I need to do is to call the function in setLights() which is in my Form1, and get it to change the visibility of my image on that form, from my C# code. Please see below (i understand the issue of the instancing problem mentioned above, but I left it in so that hopefully it will give better insight into what I am "trying" to do :) ALSO, please keep in mind that setLightCall() is running in a separate thread. Thanks in advance!

This code is also in my main c# script, and is the main function that I use to call my threads

static void Main(string[] args)
    {
        Thread FormThread = new Thread(FormCall);
        FormThread.Start();

        Thread setLightThread = new Thread(setLightCall);
        setLightThread.Start();

        log4net.Config.XmlConfigurator.Configure();
        StartModbusSerialRtuSlave();
    }

This code is in my main C# script

public  void setLightCall(Form1 parent)
    {
        Form1 updateForm = new Form1();
        while(true)
        {
            updateForm.setLights();

        }


    }

The below code is in my form1

public void setLights()
    {
        Input1GreenLight.Visible = false;
    }

Copyright Notice:Content Author:「Pardon_me」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25394756/changing-a-picture-box-visibility-from-c-sharp-code

More about “Changing a picture box visibility from C# code” related questions

Changing a picture box visibility from C# code

So I tried to create a new form and reference it...the compiler didn't mind this but it clearly wasn't changing the visibility of my picturebox. this is how I was calling my method found in my form...

Show Detail

Toggling Picture Box visibility C#

Why is the picture box control's visibility property not working here. I have initially set them to false, so that when the screen loads they are not visible. But then I wish to toggle this. I have...

Show Detail

Is it possible to rotate a picture box without C# code on the Form Designer or change shape of picture box border?

I am very new to C# and WinForms. I am trying to create a segmented display where certain segments turn on and off (Using Microsoft Visual Studio 2015). Right now I am placing picture boxes with

Show Detail

Picture box On Picture Box

This is in regards to C# coding, im quite new to this programming language, and do not know much about any other as well, but what i would like to achieve is to have a picture box as the background...

Show Detail

Changing WPF border visibility after opening dialog box

I have a border control that I am using as a loading screen overlay over my main window for when I am opening a couple large files. To do this, I am changing the visibility property of the border to

Show Detail

Dynamically changing image in picture box not working

I've been trying to figure this out off-and-on for weeks. In my VB 2010 Forms application, I have a number of picture boxes which are populated with images from other picture boxes using the drag-...

Show Detail

C#: Picture Box control not working properly

I am developing a new desktop application in C# using Windows Forms. In one of my form i put the "Picture Box" control which dynamically loads a new pic, each time when user performs a specific ope...

Show Detail

Catch QWidget real visibility status changing

I have C++ Qt 5.2.1 based project and one of graphic component looks like: +-- ParentWidget == QScrollArea ----------+ | |^| | +-- MiddleWidget == QWidget ...

Show Detail

CSS : picture instead of backface-visibility = hidden

I am trying to make 3D picture tables with three.js, and all is working fine, however, I would be able to have two pictures back-to-back with only 1 div : in my element, I have a background, and I...

Show Detail

Change the picture in picture box in C#

I am not sure what is my mistake but i am telling you it works before. I want to change the picture in picture box based on the user's choice. The 1st picture i put is in the picture control box. ...

Show Detail