views:

110

answers:

1

i am trying to set one of the custom colors of the colordialog to be the current background color of the form. i am doing it like this:

ColorDialog1.CustomColors(0) = Form1.BackColor.ToArgb

it is not working. please help! vb.net code please

please note that i only need a specific element to contain the color. not necessarily 0, but perhaps 9 or 15

+2  A: 

The getter for the CustomColors property of ColorDialog returns a clone of the array of custom colours, so doing what you have in your question will be modifying a copy of the array, not the one used by the dialog.

To set just a single custom colour, get the value of the CustomColors property and assign it to a variable. Change the colours by altering the items in this variable. Once done, set the value of this variable back to the CustomColors property.

As chrissr says (and the MSDN docs), the default value for this is null, so you might have to assign a new array. I tried it in Visual Studio though, and the CustomColors did contain a fully populated array of white.

adrianbanks