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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:45:26+00:00 2026-05-22T18:45:26+00:00

I have a UserControl with several PictureBoxes on it. These are the only controls

  • 0

I have a UserControl with several PictureBoxes on it. These are the only controls on the UserControl. All the PictureBoxes are all named ‘pbx’ plus a color such as ‘pbxGrey’ or ‘pbxBlack’. I have a method that selects one of the PictureBoxes and changes the BorderStyle to represent that it has been selected. I have tried to use the this.Controls[“pbx” + color] method but there is no property for setting the BorderStyle.

    public void SelectColor(string color)
    {
        ClearBorderSyles();
        this.Controls["pbx" + color]. //No BorderStyle property
        SelectedColor = color;
    }

I have also tried this to get at the same property:

    public void SelectColor(string color)
    {
        ClearBorderSyles();
        Picturebox handle = new PictureBox();
        handle = this.Controls["pbx" + color];
        SelectedColor = color;
    }

In this sample VS says that I can’t implcitly convert a Control to a PictureBox. So what I need to know is how do you get a handle on the control so I can change the BorderStyle? Please answer in C#, or in VB if necessary. Thank You.

  • 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-22T18:45:27+00:00Added an answer on May 22, 2026 at 6:45 pm

    You should try using the casting operator:

    Also, you shouldn’t assign handle a new object if you’re planning to throw it away on the next line:

    I would suggest something like:

    if(this.Controls["pbx" + color] is PictureBox)
    {
       PictureBox handle = this.Controls["pbx" + color] as PictureBox;
    }
    

    or:

    using(PictureBox handle = this.Controls["pbx" + color] as PictureBox)
    {
         ...
    }
    

    Of course, you should check that the control isn’t null before trying to assign or use, etc.
    But you get the idea.

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

Sidebar

Related Questions

I have a usercontrol that has several public properties. These properties automatically show up
I have a .NET UserControl (FFX 3.5). This control contains several child Controls -
I have several winforms listbox controls I am hosting in a user control. The
I have a UserControl which I have added to my web.config <add tagPrefix=BCF src=~/controls/MyMessageBox.ascx
I have designed several animated Panel s in C# that all inherit from one
I have an assembly which contains several UserControl objects that I want to be
I have a custom UserControl which contains several TextBoxes with Validators. One TextBox with
I have a UserControl, default one generated by VS, only TextBlock is added: <UserControl
I have a screen with several UserControls, but only one of them remains active.
I have a winform usercontrol with several items (textboxes, buttons,...). Now I am confronted

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.