i like chatgpt
i like chatgpt
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
See my last edit in the previous code.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true

int X = e.X - 50;
int Y = e.Y - 100;
int Index = X / SquareSize;
if (X > 0 && X < Colors.Length * SquareSize && Y >= 0 && Y <= SquareSize)
{
Selected[Index] = !Selected[Index];
}
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true

int X = e.X - 50;
int Y = e.Y - 100;
int Index = X / SquareSize;
if (X > 0 && X < Colors.Length * SquareSize && Y >= 0 && Y <= SquareSize)
{
Selected[Index] = !Selected[Index];
}
}
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Oh my ghost. I mistyped.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true

int X = e.X - 50;
int Y = e.Y - 100;
int Index = X / 50;
if (e.X > 0 && e.X < Colors.Length * 50 && Y >= 0 && Y <= 50)
{
Selected[Index] = !Selected[Index];
}
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true

int X = e.X - 50;
int Y = e.Y - 100;
int Index = X / 50;
if (e.X > 0 && e.X < Colors.Length * 50 && Y >= 0 && Y <= 50)
{
Selected[Index] = !Selected[Index];
}
}
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Yes. Using Colors.Length is recommended because hardcoding 10 is not flexible.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
I see.
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true

int X = e.X - 50;
int Y = e.Y - 100;
int Index = X / 50;
if (e.X > 0 && Index < 10 && Y >= 0 && Y <= 50)
{
Selected[Index] = !Selected[Index];
}
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true

int X = e.X - 50;
int Y = e.Y - 100;
int Index = X / 50;
if (e.X > 0 && Index < 10 && Y >= 0 && Y <= 50)
{
Selected[Index] = !Selected[Index];
}
}
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
What is your code?
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Wait in 8 hours. I am preparing to sleep sound now. 🙂 https://tenor.com/view/procrastiner-lsf-usm67-sign-language-gif-15604190
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Just another note: The following is wrong
var x = e.X - 50;
var y = e.Y - 100;
var index = x / 50;
if (index >= 0 && index < 10 && y >= 0 && y <= 50)
{
Selected[index] = !Selected[index];
}
var x = e.X - 50;
var y = e.Y - 100;
var index = x / 50;
if (index >= 0 && index < 10 && y >= 0 && y <= 50)
{
Selected[index] = !Selected[index];
}
but the following is correct
var x = e.X - 50;
var y = e.Y - 100;
var index = x / 50;
if (e.X > 0 && index < 10 && y >= 0 && y <= 50)
{
Selected[index] = !Selected[index];
}
var x = e.X - 50;
var y = e.Y - 100;
var index = x / 50;
if (e.X > 0 && index < 10 && y >= 0 && y <= 50)
{
Selected[index] = !Selected[index];
}
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
because I use e.X and e.Y as the distance from the mouse pointer to the left edge and top edge of the window repectively.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
yes
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Either one is ok.
if (e.X >= 50 && e.X < 550 && e.Y >= 100 && e.Y <= 150)
{
var index = e.X / 50 - 1;
Selected[index] = !Selected[index];
}
if (e.X >= 50 && e.X < 550 && e.Y >= 100 && e.Y <= 150)
{
var index = e.X / 50 - 1;
Selected[index] = !Selected[index];
}
or
var x = e.X - 50;
var y = e.Y - 100;
if (x >= 0 && x / 50 < 10 && y >= 0 && y <= 50)
{
var index = x / 50;
Selected[index] = !Selected[index];
}
var x = e.X - 50;
var y = e.Y - 100;
if (x >= 0 && x / 50 < 10 && y >= 0 && y <= 50)
{
var index = x / 50;
Selected[index] = !Selected[index];
}
or
var x = e.X - 50;
var y = e.Y - 100;
if (x >= 0 && x < 500 && y >= 0 && y <= 50)
{
var index = x / 50;
Selected[index] = !Selected[index];
}
var x = e.X - 50;
var y = e.Y - 100;
if (x >= 0 && x < 500 && y >= 0 && y <= 50)
{
var index = x / 50;
Selected[index] = !Selected[index];
}
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
- 0 <= x < 50 represents tile of index = 0 . Any x in this interval when divided by 50 produces 0.*** or truncated to 0. - 50 <= x < 100 represents tile of index = 1. Any x in this interval when divided by 50 produces 1.*** or truncated to 1. - ... - 450 <= x < 500 represents tile of index = 9. Any x in this interval when divided by 50 produces 9.*** or truncated to 9. So var index = x / 50;
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
x/50 represents the index and the index starts from 0 to 9. That is why x/50 must be less than 10 which is the length of the Colors array.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Introducing x and y is not mandatory actually. But I just follow what the teacher wrote.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Yes. you can click tiles if the mouse position (e.X,e.Y) in the region from (50,100) to (550,150). or the distance (x,y) in the region/interval (0,0) to (500,50)
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
finding distance with broken rulers.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
No description
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Distance is the easiest way to understand why the teacher wrote
var x = e.X - 50;
var y = e.Y - 100;
var x = e.X - 50;
var y = e.Y - 100;
x and y are about distance in disguise.
118 replies
CC#
Created by Array on 2/27/2024 in #help
Using MouseClick Event
Distance between a mouse point to the top edge of a tile means the shortest distance from the mouse pointer to the top edge of the tile.
118 replies