gpt4 book ai didi

c# - 如何在图片框控件中突出显示图像的特定部分

转载 作者:太空宇宙 更新时间:2023-11-03 13:56:21 25 4
gpt4 key购买 nike

我想在应用程序运行时突出显示图片框控件中图像的特定部分。如何使用 C# 实现这个?

最佳答案

这里有一个示例,当用户将鼠标悬停在图像上时,绘制一个 alpha 矩形悬停在图片框上。请注意,您可以根据需要突出显示图片。

public partial class Form2 : Form
{
private Rectangle mHoverRectangle = Rectangle.Empty;
private const int HOVER_RECTANGLE_SIZE = 20;

public Form2()
{
InitializeComponent();

pictureBox.MouseMove += new MouseEventHandler(pictureBox_MouseMove);
pictureBox.Paint += new PaintEventHandler(pictureBox_Paint);
pictureBox.MouseLeave += new EventHandler(pictureBox_MouseLeave);
}

void pictureBox_MouseLeave(object sender, EventArgs e)
{
mHoverRectangle = Rectangle.Empty;
}

void pictureBox_Paint(object sender, PaintEventArgs e)
{
if (mHoverRectangle != Rectangle.Empty)
{
using (Brush b = new SolidBrush(Color.FromArgb(150, Color.White)))
{
e.Graphics.FillRectangle(b, mHoverRectangle);
}
}
}

void pictureBox_MouseMove(object sender, MouseEventArgs e)
{
mHoverRectangle = new Rectangle(
e.Location.X - HOVER_RECTANGLE_SIZE / 2,
e.Location.Y - HOVER_RECTANGLE_SIZE / 2,
HOVER_RECTANGLE_SIZE,
HOVER_RECTANGLE_SIZE);

pictureBox.Invalidate();
}

希望对你有帮助

关于c# - 如何在图片框控件中突出显示图像的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com