gadget's name used as parameter on a method
gadget's name used as parameter on a method
enter code here:
//Displays the primary color
var ralnr = 9004;
var primColor = 2;
String primaryColor = column[firstIndex, primColor];
var primary = ralcode(primaryColor, out ralnr);
primaryRAL.Text = primaryColor + " " + "RAL" + " " + ralnr;
PictureBox gadget1 = primaryColorBox1;
string ral1 = ralnr.ToString();
backgroundcolorchange(gadget1, ral1);
//Displays the secondary color
var secColor = 3;
String secondaryColor = column[firstIndex, secColor];
var secondary = ralcode(secondaryColor, out ralnr);
secondaryRAL.Text = secondaryColor + " " + "RAL" + " " + ralnr; ;
PictureBox gadget2 = secondaryColorBox2;
string ral2 = ralnr.ToString();
backgroundcolorchange(gadget2, ral2);
hi I'm just new in programming. I was trying to pass the gadget's name
for the first gadget and it worked using the Method that I have
created but for the second gadget it did not worked. How is that?
private void backgroundcolorchange(PictureBox gadget, string ralcode)
{
string strPath = Application.StartupPath + "\images\";
gadget.BackgroundImage = Image.FromFile(strPath + ralcode + ".jpg");
gadget.BackgroundImageLayout = ImageLayout.Stretch;
}
1 Answer
1
I am guessing that primaryColorBox1 is a textbox?
Based on that guess, you would need to pass the whole object to backgroundcolorchange.
This is because you are trying to alter properties off of the textbox.
so your backgroundcolorchange method would be more like
private void backgroundcolorchange(TextBox gadget, string ralcode){ ...
But this is all I can guess based on the information supplied.
sorry the Picture that I tried uploading here to show the problem didn't upload. The gadget is an image container (*picturebox), whenever I press a button it looks for the string and changes the image background according to the string.
– Bert Derige
yesterday
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please type your code into the question, not links to screenshots. Thanks
– d219
yesterday