我有一个放置文本和图像的 StatusStripLabel。现在我想为文本和图像调用独立事件。就像在文本点击上一样。应该是Text_Click..在图像单击时应该是Image_Click..
上述情况在可能或不??????
有点可能...您可以根据ToolStripStatusLabel
中使用的图像的边界测试MouseUp
事件MouseEventArgs
的位置。
private void statusLabel_MouseUp(object sender, MouseEventArgs e)
{
ToolStripStatusLabel statusLabel = (ToolStripStatusLabel)sender;
GraphicsUnit unit = GraphicsUnit.Pixel;
if (statusLabel.Image.GetBounds(ref unit).Contains(e.Location))
MessageBox.Show("Clicked on image.");
else
MessageBox.Show("Clicked on text.");
}
不过,有一些先决条件:ToolStripStatusLabel.TextImageRelation
必须设置为 TextImageRelation.ImageBeforeText
ToolStripStatusLabel.ImageScaling
必须设置为 ToolStripItemImageScaling.None
。否则,您将不得不添加更多逻辑。