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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:15:51+00:00 2026-06-08T15:15:51+00:00

I have a pictureBox with an image inside. I want, when i click on

  • 0

I have a pictureBox with an image inside.
I want, when i click on a button the image should hide and click again to show the image.

In the pictureBox, using paint event i am drawing some lines.
So if im doing pictureBox1.Refresh(); it will draw the lines. I want that if i click on a button the image will not display on/off.

pictureBox1 = null; or pictureBox1.Image.Dispose(); doesn’t work it’s showing me big red x with white background.

  • 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-08T15:15:53+00:00Added an answer on June 8, 2026 at 3:15 pm

    For toggling the image in your PictureBox you can create a 1 pixel bitmap and assign it to the picture box when you want hide your image, then assign your image back again. I am a little unclear of what the second part of your question is asking, any drawing in the picturebox’s Paint Event will remain unless you exclude it in the Paint Event based on some Condition. If you want to draw a line in the box an toggle it on/off from a button see my second example.

    i.e.

    public partial class Form1 : Form
    {
        Bitmap nullBitmap = new Bitmap(1, 1); // create a 1 pixel bitmap
        Bitmap myImage = new Bitmap("Load your Image Here"); // Load your image
        bool showImage;  // boolean variable so we know what image is assigned
        public Form1()
        {
            InitializeComponent();
            pictureBox1.Image = myImage;
            showImage = true;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            if (showImage)
            {
                pictureBox1.Image = nullBitmap;
                showImage = false; 
            }
            else
            {
                pictureBox1.Image = myImage;
                showImage = true;
            }
        }
    }
    

    Second Example

    public partial class Form1 : Form
    {
        bool showLines;
        public Form1()
        {
            InitializeComponent();
            showLines = true;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            if (showLines)
            {
                showLines = false;
                pictureBox1.Invalidate();
            }
            else
            {
                showLines = true;
                pictureBox1.Invalidate();
            }
        }
    
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if(showLines)
                e.Graphics.DrawLine(Pens.Purple, 0, 0, 100, 100);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have picturebox with displaying image when i click on button its fine...
I have a PictureBox control I want to display an image in it. I
On a form I have a PictureBox , a button to load image in
I have a GUI window form. I want to set image to pictureBox and
I have a control (picturebox), in which I want to draw an 2D image
I have an image in a PictureBox, and I want to print it. No
I have an application that displays an image inside of a Windows Forms PictureBox
I have a picturebox which displays an image of a music note. I want
I'm implementing panning of a large image in a PictureBox control, and I have
I have a transparent rectangle on a picture box,if i click next,the next image

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.