Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何制作一个可以单击的图像,而不是图像周围的任何区域?_C#_Visual Studio - Fatal编程技术网

C# 如何制作一个可以单击的图像,而不是图像周围的任何区域?

C# 如何制作一个可以单击的图像,而不是图像周围的任何区域?,c#,visual-studio,C#,Visual Studio,例如,当前如果我将图像放在标签或图片框中,并希望用户单击图像,则透明背景也可以单击,这是我不希望看到的,因为否则我放置的多个图像的“点击框”将重叠。 非常感谢您的帮助。您可以确定单击位置是否在Picturebox图像大小内 private void pictureBox1_Click(object sender, EventArgs e) { if (((MouseEventArgs)e).X <= pictureBox1.Image.Width &&

例如,当前如果我将图像放在标签或图片框中,并希望用户单击图像,则透明背景也可以单击,这是我不希望看到的,因为否则我放置的多个图像的“点击框”将重叠。
非常感谢您的帮助。

您可以确定单击位置是否在Picturebox图像大小内

private void pictureBox1_Click(object sender, EventArgs e)
{
    if (((MouseEventArgs)e).X <= pictureBox1.Image.Width &&
        ((MouseEventArgs)e).Y <= pictureBox1.Image.Height)
    {
        MessageBox.Show("Valid Click");
    }
} 
private void pictureBox1\u单击(对象发送方,事件参数e)
{

如果(((MouseEventArgs)e).X,您可以尝试获取单击颜色的像素,而只处理非透明像素。问题并不长,但显然您忽略了一个关键点:“透明背景也可以单击,我不希望这样”。这个问题不是很清楚:图片盒中的图片周围都是透明背景还是图片本身内部的透明像素?如果您认为不清楚,请提问而不是回答。我需要50信誉度来添加评论。由于问题已经结束,我建议您删除此答案以避免进一步的信誉丧失