hey guys i just started using C# im trying to change the backcolor when the mouse if pressed and moved, it works fine when the window is small, however when i maximize the window the colors stop changing and keeps on crashing saying that Color.FromArgb(x,y,g+=1)
cannot exceed 255,i tried preventing this using an if statement but still doesnt work. thanks in advance :)
this is my code so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace _4
{
class Class1 : Form
{
int x;
int y;
int q=0;
int r = 20;
int b = 80;
int g = 2;
Point loc;
Class1()
{
this.MouseMove += new MouseEventHandler(Class1_MouseMove);
BackColor = Color.FromArgb(15, 150, 144);
}
void Class1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
loc = e.Location;
x = loc.X;
y = loc.Y;
if(r>=255 ||r<0)
{
r = 0;
}
if (b >= 255 || b < 0)
{
b = 0;
} if (g >= 255 || g < 0)
{
g = 0;
}
BackColor = Color.FromArgb(x, y, g += 1);
}
}
static void Main()
{
Application.Run(new Class1());
}
}
}