2

我想获取 ToolStripButton 图像的位置,我该怎么做?我试过这样:

private void ToolStripButton_MouseHover(object sender, EventArgs e)
{
    Graphics formGraphics = this.CreateGraphics();
    GraphicsUnit units = GraphicsUnit.Point;
    RectangleF imageBoundsF = reloadToolStripButton.Image.GetBounds(ref units);
    Rectangle boundRect = Rectangle.Round(imageBoundsF);
    Size imageSize = new Size(reloadToolStripButton.Image.Width, reloadToolStripButton.Image.Height);
    Rectangle imageRect = new Rectangle(boundRect.Location, imageSize);
    formGraphics.Dispose();

    if (imageRect.Contains(Cursor.Position))
    {
        // Do what i want ;)
    }
}

但是 x 和 y 始终为 0,并且位置似乎也为 0,那么我怎样才能获得图像的位置呢?boundRect.Location 始终为 0 ..

4

0 回答 0