The exception that is thrown when one of the arguments provided to a method is not valid.

  • Thread starter Thread starter Rinaldo
  • Start date Start date
R

Rinaldo

Hi,

My code:

kleur = binFavorietReader.ReadInt32();
Color kl = Color.FromArgb(kleur);
BackColor = kl;

but get an exeption: The exception that is thrown when one of the
arguments provided to a method is not valid.

transparent backgroundcolors not handled.
 
Details:

System.ArgumentException was unhandled
Message="Voor dit besturingselement worden doorzichtige achtergrondkleuren
niet ondersteund."
Source="System.Windows.Forms"
StackTrace:
bij System.Windows.Forms.Control.set_BackColor(Color value)
bij System.Windows.Forms.Form.set_BackColor(Color value)
bij RadioSpeler.Radiospeler.Radiospeler_Load(Object sender, EventArgs
e) in C:\Users\Rinaldo\Documents\Visual Studio
2008\Projects\RadioSpeler\Full\RadioSpeler\Radiospeler.cs:regel 853
bij System.Windows.Forms.Form.OnLoad(EventArgs e)
bij System.Windows.Forms.Form.SetVisibleCore(Boolean value)
bij System.Windows.Forms.Control.set_Visible(Boolean value)
bij
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
bij
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
bij System.Windows.Forms.Application.Run(Form mainForm)
bij RadioSpeler.Program.Main() in C:\Users\Rinaldo\Documents\Visual
Studio 2008\Projects\RadioSpeler\Full\RadioSpeler\Program.cs:regel 15
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
InnerException:
 
Rinaldo said:
My code:

kleur = binFavorietReader.ReadInt32();
Color kl = Color.FromArgb(kleur);
BackColor = kl;

but get an exeption: The exception that is thrown when one of the
arguments provided to a method is not valid.

transparent backgroundcolors not handled.

Well, that seems fairly clear to me - you've provided a transparent
background colour, and the control doesn't support that.
 
Hi,

My code:

kleur = binFavorietReader.ReadInt32();
Color kl = Color.FromArgb(kleur);
BackColor = kl;

but get an exeption: The exception that is thrown when one of the
arguments provided to a method is not valid.

transparent backgroundcolors not handled.

As Jon says, the exception seems pretty clear.

As far as why you're getting the exception, note the name of the method
you're using to initialize the Color. FromArgb(). From==>A<==rgb().
Emphasis on "A". That's "alpha" and it means that it expects the number
you're passing into include an alpha component (i.e. transparency).

It seems likely that the color value you're reading is just as plain
24-bit color value, so the alpha is 0 (i.e. completely transparent).

You need to make sure you have a color with the alpha component set to 255
(i.e. completely opaque) before using it somewhere that transparent colors
aren't supported (like for background colors). IMHO, the easiest way to
do that is just use the FromArgb() overload that takes the alpha and color
separately:

Color kl = Color.FromArgb(255, Color.FromArgb(kleur));

Why there's no Color.FromArgb(Int32, Int32) so that you can avoid going
through the constructor twice, I don't know. But it shouldn't be a big
deal. This is unlikely to ever be a performance bottleneck.

Pete
 
Hi Pete,

English is not my motherlanguage, I do not understand all errors.
I saw that the color I was writing was always 0.
Unfornually, I leave it :(

Thanks for support.

"Peter Duniho" <[email protected]> schreef in bericht
Hi,

My code:

kleur = binFavorietReader.ReadInt32();
Color kl = Color.FromArgb(kleur);
BackColor = kl;

but get an exeption: The exception that is thrown when one of the
arguments provided to a method is not valid.

transparent backgroundcolors not handled.

As Jon says, the exception seems pretty clear.

As far as why you're getting the exception, note the name of the method
you're using to initialize the Color. FromArgb(). From==>A<==rgb().
Emphasis on "A". That's "alpha" and it means that it expects the number
you're passing into include an alpha component (i.e. transparency).

It seems likely that the color value you're reading is just as plain
24-bit color value, so the alpha is 0 (i.e. completely transparent).

You need to make sure you have a color with the alpha component set to 255
(i.e. completely opaque) before using it somewhere that transparent colors
aren't supported (like for background colors). IMHO, the easiest way to
do that is just use the FromArgb() overload that takes the alpha and color
separately:

Color kl = Color.FromArgb(255, Color.FromArgb(kleur));

Why there's no Color.FromArgb(Int32, Int32) so that you can avoid going
through the constructor twice, I don't know. But it shouldn't be a big
deal. This is unlikely to ever be a performance bottleneck.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top