473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting the back ground image of Buttons in an Array

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void ChangeButtonsBackgroundimage(string[] NamesOfImageList,string FolderName)
  3.     {
  4.      try
  5.       {
  6.         ArrayList Arr_Button = new ArrayList();
  7.         Arr_Button.Add(this.button1);
  8.         Arr_Button.Add(this.button2);
  9.         Arr_Button.Add(this.button3);
  10.  
  11.         for (int i = 0; i < NamesOfImageList.Length; i++)
  12.         {
  13.            Button TempButton = new Button();
  14.            string FileName = FolderName + @"\" + NamesOfImageList[i] + ".bmp";
  15.            FileName = Get_ImagePath(FileName);
  16.            TempButton.BackgroundImage = Image.FromFile(FileName);
  17.             Arr_Button[i] = TempButton;
  18.  
  19.        }
  20.      }
  21.      catch (Exception ex)
  22.      { }
  23. }
  24.  
Buttons after this function doesn't appear the Background image while I am trace code I found that all property values of TempButtone including Backgroundimage was set to Arr_Button[i] ,BUT why it doesn't appear ??

Thanx in Advance .
Dec 17 '08 #1
4 1942
nukefusion
221 Expert 100+
Because the button that you've added to the array isn't the button in the Controls collection of the form. In your loop you are just creating a new button object and setting the background of that. The button on the form is a different object.

You'll need to change your code to remove the temporary button objects you are creating:

Expand|Select|Wrap|Line Numbers
  1.  private void ChangeButtonsBackgroundimage(string[] NamesOfImageList, string FolderName)
  2.         {
  3.             try
  4.             {
  5.                 List<Button> buttons = new List<Button>();
  6.                 buttons.Add(this.button1);
  7.                 buttons.Add(this.button2);
  8.                 buttons.Add(this.button3);
  9.  
  10.                 for (int i = 0; i < NamesOfImageList.Length; i++)
  11.                 {
  12.                     string FileName = Path.Combine(FolderName, NamesOfImageList[i]);
  13.                     buttons[i].BackgroundImage = Image.FromFile(FileName);
  14.  
  15.                 }
  16.             }
  17.             catch (Exception ex)
  18.             { }
  19.         }
  20.  
Dec 17 '08 #2
PRR
750 Expert 512MB
@MarwaAlSagheer
((Arr_Button[i])as Button).BackgroundImage= TempButton.BackgroundImage;
nukefusion has a better solution....
Dec 17 '08 #3
Mr.nukefusion and Mr.DeepBlue Thanks alooot :) Two solutions are correct.
Have a nice Day
Dec 17 '08 #4
PRR
750 Expert 512MB
@MarwaAlSagheer
Glad we could help ... Do continue to post your queries on Bytes
You too have a great day!
Dec 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave | last post by:
Hi all, I was trying to make an image submit button with a rollover and discovered to my suprise that there is no way to access a form element of the "image" type. I tried specifying it by name...
1
by: pierre.basson | last post by:
Hi, I have a DataList that contains an image and 3 radio buttons. The radio buttons are used to change the status of the image i.e. Approved, Suspended and Deleted. When the form loads, I want...
2
by: Cliff Lane | last post by:
I have an application that allows the user to select fore and back ground colors for command buttons. I use the dialog to select the colors and store the value returned in the db as a string. For...
17
by: santel_helvis | last post by:
Hi All, Could anyone tell me how to rotate the image in javascript. Which concepts I should concentrate to rotate the image
26
by: gswork | last post by:
i hadn't designed a web page from the ground up for about 9 years, then i was asked to do one. I'd dabbled with html and vaigly kept up with some of the developments but other than that i've been...
14
by: Roger Withnell | last post by:
How to I find out what size text the browser is set to? Thanks in anticipation.
3
by: mcnewsxp | last post by:
how can i set a back ground image property on an MDI main form to stretch?
10
elamberdor
by: elamberdor | last post by:
Hello All! Well, I can load in swf's just loverly, but what I have is a sliding menu, with buttons in it, that when pressed, load an image into an empty movieclip. I really just need to know how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.