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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:37:28+00:00 2026-05-13T07:37:28+00:00

Im getting this error when trying to run a program in creating, how shold

  • 0

Im getting this error when trying to run a program in creating, how shold i interpet the error message, the macro runs just fine for many loops but then just suddely it breaks, giving this error.

************** Exception Text **************
System.ArgumentException: Value of '-1' is not valid for 'blue'. 'blue' should be greater than or equal to 0 and less than or equal to 255.
   at System.Drawing.Color.CheckByte(Int32 value, String name)
   at System.Drawing.Color.FromArgb(Int32 alpha, Int32 red, Int32 green, Int32 blue)
   at System.Drawing.Color.FromArgb(Int32 red, Int32 green, Int32 blue)
   at Dispatcher_Tool.ColorCheck.GetPixelAtCursor()
   at Dispatcher_Tool.ColorCheck.getPixel()
   at Dispatcher_Tool.ColorCheck.checkColorBlack(Int32 blackCordsX, Int32 blackCordsY)
   at Dispatcher_Tool.main_normal.checkColor()
   at Dispatcher_Tool.main_normal.startMacro(TextBox valX)
   at Dispatcher_Tool.main_normal.button5_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

code around this point is,

    [DllImport("gdi32")]
    private static extern int GetPixel(IntPtr hdc, int x, int y);
    [DllImport("User32")]
    private static extern IntPtr GetWindowDC(IntPtr hwnd);



    #region Pixel color test

    private static readonly IntPtr DesktopDC = GetWindowDC(IntPtr.Zero);

    public static System.Drawing.Color GetPixelAtCursor()
    {
        System.Drawing.Point p = Cursor.Position;
        int color = GetPixel(DesktopDC, p.X, p.Y);
        return System.Drawing.Color.FromArgb(color & 0xFF, color >> 8 & 0xFF, color >> 16);
    }
  • 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-13T07:37:29+00:00Added an answer on May 13, 2026 at 7:37 am

    The error message is fairly clear – you’re calling Color.FromArgb, but you’re giving it a “blue” value of -1, which is invalid. From the docs:

    blue
    Type: System.Int32
    The blue
    component value for the new Color.
    Valid values are 0 through 255.

    Quite how you fix that will depend on what your code is trying to do.

    EDIT: Okay, now that you’ve posted the code I strongly suspect it’s returning CLR_INVALID, which I’m guessing is the bit pattern for -1 (i.e. all bits set). You’re just shifting that, which is being sign-extended so you’re still just getting -1.

    It’s very easy to avoid this causing an exception – just mask the blue value in the same way you’re masking the others:

    return Color.FromArgb(color & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF);
    

    However, that’s really just going to hide the problem – you’ll end up with white where really you don’t have a valid value. You should potentially check whether color == -1 and act appropriately. Again, that exact behaviour will depend on your application.

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

Sidebar

Ask A Question

Stats

  • Questions 390k
  • Answers 390k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer With reflection you can load an assembly and find out… May 15, 2026 at 12:58 am
  • Editorial Team
    Editorial Team added an answer Your best approach is to save the Image to disk… May 15, 2026 at 12:58 am
  • Editorial Team
    Editorial Team added an answer This should work just fine. Your problem lies somewhere else.… May 15, 2026 at 12:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.