How to display an Image in a different Form with simple Button press










-2















I have 2 Forms. The first one contains a Button and the other contains a PictureBox.

Now I want to display the PictureBox when the Button is pressed.

I have tried with this code:



private void button3_Click(object sender, EventArgs e)

// in order to hide the first form
this.Hide();
Form2 f1 = new Form2();
f1.ShowDialog();
// to display the pic the second form
Form2.pictureBox1.Visible = true;



But the problem was that it was inaccessible due to protection level.

What can I do?










share|improve this question



















  • 1





    What do you mean with I am using VB.net (c#)? The code you're showing is C#, not VB.Net. Pick one, different languages. -- Having an instance of Form2 created as Form2 f1 = new Form2();, you will then be accessing a Control in Form2 with f1.PictureBox.Visible = true;.. Before .ShowDialog();. -- An instance of Form2 named as f1 can be quite confusing.

    – Jimi
    Nov 13 '18 at 7:11












  • oh sorry about that i meant c#

    – AceSiddig
    Nov 13 '18 at 7:36











  • Ok i tried that it said form 1 does not contain definition for 'pictureBox1' and no extension method for 'pictureBox1'.

    – AceSiddig
    Nov 13 '18 at 7:43











  • Apparently, pictureBox1 is in Form2, not Form1. A piece of the code you have written is not correct. When something is not working, post the code you're actually using, updating you question.

    – Jimi
    Nov 13 '18 at 7:47











  • yes its in form 2 and thanks

    – AceSiddig
    Nov 13 '18 at 8:08















-2















I have 2 Forms. The first one contains a Button and the other contains a PictureBox.

Now I want to display the PictureBox when the Button is pressed.

I have tried with this code:



private void button3_Click(object sender, EventArgs e)

// in order to hide the first form
this.Hide();
Form2 f1 = new Form2();
f1.ShowDialog();
// to display the pic the second form
Form2.pictureBox1.Visible = true;



But the problem was that it was inaccessible due to protection level.

What can I do?










share|improve this question



















  • 1





    What do you mean with I am using VB.net (c#)? The code you're showing is C#, not VB.Net. Pick one, different languages. -- Having an instance of Form2 created as Form2 f1 = new Form2();, you will then be accessing a Control in Form2 with f1.PictureBox.Visible = true;.. Before .ShowDialog();. -- An instance of Form2 named as f1 can be quite confusing.

    – Jimi
    Nov 13 '18 at 7:11












  • oh sorry about that i meant c#

    – AceSiddig
    Nov 13 '18 at 7:36











  • Ok i tried that it said form 1 does not contain definition for 'pictureBox1' and no extension method for 'pictureBox1'.

    – AceSiddig
    Nov 13 '18 at 7:43











  • Apparently, pictureBox1 is in Form2, not Form1. A piece of the code you have written is not correct. When something is not working, post the code you're actually using, updating you question.

    – Jimi
    Nov 13 '18 at 7:47











  • yes its in form 2 and thanks

    – AceSiddig
    Nov 13 '18 at 8:08













-2












-2








-2








I have 2 Forms. The first one contains a Button and the other contains a PictureBox.

Now I want to display the PictureBox when the Button is pressed.

I have tried with this code:



private void button3_Click(object sender, EventArgs e)

// in order to hide the first form
this.Hide();
Form2 f1 = new Form2();
f1.ShowDialog();
// to display the pic the second form
Form2.pictureBox1.Visible = true;



But the problem was that it was inaccessible due to protection level.

What can I do?










share|improve this question
















I have 2 Forms. The first one contains a Button and the other contains a PictureBox.

Now I want to display the PictureBox when the Button is pressed.

I have tried with this code:



private void button3_Click(object sender, EventArgs e)

// in order to hide the first form
this.Hide();
Form2 f1 = new Form2();
f1.ShowDialog();
// to display the pic the second form
Form2.pictureBox1.Visible = true;



But the problem was that it was inaccessible due to protection level.

What can I do?







c#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 8:44









Jimi

7,41241833




7,41241833










asked Nov 13 '18 at 7:05









AceSiddigAceSiddig

27




27







  • 1





    What do you mean with I am using VB.net (c#)? The code you're showing is C#, not VB.Net. Pick one, different languages. -- Having an instance of Form2 created as Form2 f1 = new Form2();, you will then be accessing a Control in Form2 with f1.PictureBox.Visible = true;.. Before .ShowDialog();. -- An instance of Form2 named as f1 can be quite confusing.

    – Jimi
    Nov 13 '18 at 7:11












  • oh sorry about that i meant c#

    – AceSiddig
    Nov 13 '18 at 7:36











  • Ok i tried that it said form 1 does not contain definition for 'pictureBox1' and no extension method for 'pictureBox1'.

    – AceSiddig
    Nov 13 '18 at 7:43











  • Apparently, pictureBox1 is in Form2, not Form1. A piece of the code you have written is not correct. When something is not working, post the code you're actually using, updating you question.

    – Jimi
    Nov 13 '18 at 7:47











  • yes its in form 2 and thanks

    – AceSiddig
    Nov 13 '18 at 8:08












  • 1





    What do you mean with I am using VB.net (c#)? The code you're showing is C#, not VB.Net. Pick one, different languages. -- Having an instance of Form2 created as Form2 f1 = new Form2();, you will then be accessing a Control in Form2 with f1.PictureBox.Visible = true;.. Before .ShowDialog();. -- An instance of Form2 named as f1 can be quite confusing.

    – Jimi
    Nov 13 '18 at 7:11












  • oh sorry about that i meant c#

    – AceSiddig
    Nov 13 '18 at 7:36











  • Ok i tried that it said form 1 does not contain definition for 'pictureBox1' and no extension method for 'pictureBox1'.

    – AceSiddig
    Nov 13 '18 at 7:43











  • Apparently, pictureBox1 is in Form2, not Form1. A piece of the code you have written is not correct. When something is not working, post the code you're actually using, updating you question.

    – Jimi
    Nov 13 '18 at 7:47











  • yes its in form 2 and thanks

    – AceSiddig
    Nov 13 '18 at 8:08







1




1





What do you mean with I am using VB.net (c#)? The code you're showing is C#, not VB.Net. Pick one, different languages. -- Having an instance of Form2 created as Form2 f1 = new Form2();, you will then be accessing a Control in Form2 with f1.PictureBox.Visible = true;.. Before .ShowDialog();. -- An instance of Form2 named as f1 can be quite confusing.

– Jimi
Nov 13 '18 at 7:11






What do you mean with I am using VB.net (c#)? The code you're showing is C#, not VB.Net. Pick one, different languages. -- Having an instance of Form2 created as Form2 f1 = new Form2();, you will then be accessing a Control in Form2 with f1.PictureBox.Visible = true;.. Before .ShowDialog();. -- An instance of Form2 named as f1 can be quite confusing.

– Jimi
Nov 13 '18 at 7:11














oh sorry about that i meant c#

– AceSiddig
Nov 13 '18 at 7:36





oh sorry about that i meant c#

– AceSiddig
Nov 13 '18 at 7:36













Ok i tried that it said form 1 does not contain definition for 'pictureBox1' and no extension method for 'pictureBox1'.

– AceSiddig
Nov 13 '18 at 7:43





Ok i tried that it said form 1 does not contain definition for 'pictureBox1' and no extension method for 'pictureBox1'.

– AceSiddig
Nov 13 '18 at 7:43













Apparently, pictureBox1 is in Form2, not Form1. A piece of the code you have written is not correct. When something is not working, post the code you're actually using, updating you question.

– Jimi
Nov 13 '18 at 7:47





Apparently, pictureBox1 is in Form2, not Form1. A piece of the code you have written is not correct. When something is not working, post the code you're actually using, updating you question.

– Jimi
Nov 13 '18 at 7:47













yes its in form 2 and thanks

– AceSiddig
Nov 13 '18 at 8:08





yes its in form 2 and thanks

– AceSiddig
Nov 13 '18 at 8:08












1 Answer
1






active

oldest

votes


















0














One Way is to Pass the Image Path (string) as argument to Form2. i.e. Create a constructor for Form2 taking a string param. Do the Image Assignment & Visibility thing in Form2 Constructor (obvisouly after InitializeComponents()).



Hack Fix way is to make the PictureBox in Form2 (designer) as Public.






share|improve this answer























  • sorry but am still new to this how can i do that, i changed the picBox to public ok, and created the constructor but still the problem remains

    – AceSiddig
    Nov 13 '18 at 7:58










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275582%2fhow-to-display-an-image-in-a-different-form-with-simple-button-press%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














One Way is to Pass the Image Path (string) as argument to Form2. i.e. Create a constructor for Form2 taking a string param. Do the Image Assignment & Visibility thing in Form2 Constructor (obvisouly after InitializeComponents()).



Hack Fix way is to make the PictureBox in Form2 (designer) as Public.






share|improve this answer























  • sorry but am still new to this how can i do that, i changed the picBox to public ok, and created the constructor but still the problem remains

    – AceSiddig
    Nov 13 '18 at 7:58















0














One Way is to Pass the Image Path (string) as argument to Form2. i.e. Create a constructor for Form2 taking a string param. Do the Image Assignment & Visibility thing in Form2 Constructor (obvisouly after InitializeComponents()).



Hack Fix way is to make the PictureBox in Form2 (designer) as Public.






share|improve this answer























  • sorry but am still new to this how can i do that, i changed the picBox to public ok, and created the constructor but still the problem remains

    – AceSiddig
    Nov 13 '18 at 7:58













0












0








0







One Way is to Pass the Image Path (string) as argument to Form2. i.e. Create a constructor for Form2 taking a string param. Do the Image Assignment & Visibility thing in Form2 Constructor (obvisouly after InitializeComponents()).



Hack Fix way is to make the PictureBox in Form2 (designer) as Public.






share|improve this answer













One Way is to Pass the Image Path (string) as argument to Form2. i.e. Create a constructor for Form2 taking a string param. Do the Image Assignment & Visibility thing in Form2 Constructor (obvisouly after InitializeComponents()).



Hack Fix way is to make the PictureBox in Form2 (designer) as Public.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 7:08









Prateek ShrivastavaPrateek Shrivastava

888511




888511












  • sorry but am still new to this how can i do that, i changed the picBox to public ok, and created the constructor but still the problem remains

    – AceSiddig
    Nov 13 '18 at 7:58

















  • sorry but am still new to this how can i do that, i changed the picBox to public ok, and created the constructor but still the problem remains

    – AceSiddig
    Nov 13 '18 at 7:58
















sorry but am still new to this how can i do that, i changed the picBox to public ok, and created the constructor but still the problem remains

– AceSiddig
Nov 13 '18 at 7:58





sorry but am still new to this how can i do that, i changed the picBox to public ok, and created the constructor but still the problem remains

– AceSiddig
Nov 13 '18 at 7:58

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275582%2fhow-to-display-an-image-in-a-different-form-with-simple-button-press%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3