-1

Basically getting an exception error and Im stumbled, I have tried googling but have not found anything and it's really frustrating me now.

        public static Graphics graphics;


        [STAThread]
            static void Main(string[] args)
            {

            GetWindowRect(handle, out rect);
            rect.width = rect.left - rect.right;
           rect.height = rect.bottom - rect.top;

            window = new OverlayWindow(rect.left, rect.top, rect.width, rect.height)
            {
                IsTopmost = true,
                IsVisible = true
                

            };

            graphics = new Graphics()
            {
                MeasureFPS = true,
                PerPrimitiveAntiAliasing = true,
                TextAntiAliasing = true,
                UseMultiThreadedFactories = false,
                VSync = true,
                Height = window.Height,
                Width = window.Width,
                WindowHandle = IntPtr.Zero
            };

            window.CreateWindow();
            graphics.WindowHandle = window.Handle;
            graphics.Setup();


            Thread t = new Thread(Tutorial);
            t.Start();   
    ..... ```



 public static void Tutorial()
    {
        while (true)
        {
            graphics.BeginScene();
            graphics.ClearScene();


            graphics.DrawCrosshair(graphics.CreateSolidBrush(Color.Red), new Point(1920 / 2, 1080 / 2), 5, 2, CrosshairStyle.Plus);


            graphics.EndScene();
        }
    } ```

Again this gives me an exception that the Height or Width isnt valid and im honestly insanely confused. I have tried googling it a lot more but cannot find anything. any help appreciated would honestly be great, many thanks!

Spacey
  • 21
  • 5

1 Answers1

1

Your calculation

rect.left - rect.right

will give a negative value, which is out of range (it should be rect.right - rect.left instead).

Lemon Sky
  • 677
  • 4
  • 10
  • Hey, appreciate the response, I just retried but still getting the same exception, appreciate you pointing that out though! – Spacey May 04 '21 at 21:07
  • What line does the exception occur and have you looked at what you're passing in each argument to that method? – Lemon Sky May 04 '21 at 21:14
  • Line 280, and that line is ``` Thread t = new Thread(Tutorial);``` along with ``` t.Start();``` underneath, I don't see the problem? – Spacey May 04 '21 at 21:18