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

  • Home
  • SEARCH
  • 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 363869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:23:02+00:00 2026-05-12T13:23:02+00:00

Does anybody know how I can write cardImage1.BorderStyle = BorderStyle.Fixed3D; without having to explicitly

  • 0

Does anybody know how I can write “cardImage1.BorderStyle = BorderStyle.Fixed3D;” without having to explicitly declare “cardImage1”?

I’m trying to put it into a method so that I don’t need to write the code to toggle between two Border Styles when a Picture Box is clicked, for every single single picture box (there are 52!)

e.g. for each box currently I would need to have the following in its _click event.

        if (cardImage1.BorderStyle == BorderStyle.None)
        {
            cardImage1.BorderStyle = BorderStyle.Fixed3D;
        }
        else
        {
            cardImage1.BorderStyle = BorderStyle.None;
        }
  • 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-12T13:23:02+00:00Added an answer on May 12, 2026 at 1:23 pm

    Instead of creating a handler for each picture box, you could write a single method o handle the clicks for all your picture boxes:

     protected void onClickHandler(object sender, EventArgs e)
     {
        if (((PictureBox)sender).BorderStyle == BorderStyle.None)
        {
            ((PictureBox)sender).BorderStyle = BorderStyle.Fixed3D;
        }
        else
        {
            ((PictureBox)sender).BorderStyle = BorderStyle.None;
        }
    
    }
    

    You could also write a loop to go over all controls on a form and attac hthe event handler to all picture boxes (if that;s possible in your case)

    // in your form load event do something like this:
    foreach(Control c in this.Controls)
    {
        PictureBox pb = c as PictureBox;
        if(pb != null)
           pb.Click += new EventHandler(onClickHandler); // where onClickHandler is the above function
    }
    

    Of course if you have other picture boxes on the form a solution would be to put the 52 picture boxes you are interested in in a panel and then instead of iterating over all the controls in the form (this.Controls) only iterate over the controls in the panel (thePanelControl.Controls)

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

Sidebar

Ask A Question

Stats

  • Questions 210k
  • Answers 210k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes you can do that in some cases. I suggest… May 12, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer I can't remember if the cookie that ASP.NET sets as… May 12, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer Yes you can: http://blogs.msdn.com/saveenr/archive/2008/09/22/wpf-xaml-saving-an-animation-as-an-avi-video-file.aspx May 12, 2026 at 9:59 pm

Related Questions

Does anybody know how I can programmatically check (using C#) whether my program will
I am playing around with lisp's format function, but I have hit a snag
I need to be able to add an arbitrary section to an ELF file.
I have a 2D array which contains height information. I want to see it

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.