0

在表单加载中,我将此代码用于所有 6 个按钮

private void Parent_Load(object sender, EventArgs e) 
{ 
btnExam.SetBounds(btnExam.Location.X, btnExam.Location.Y, 175, 154); 
btnResult.SetBounds(btnResult.Location.X, btnResult.Location.Y, 175, 154); 
btnContactUs.SetBounds(btnContactUs.Location.X, btnContactUs.Location.Y, 175, 154); 
btnClasses.SetBounds(btnClasses.Location.X, btnClasses.Location.Y, 175, 154); 
btnCollegeList.SetBounds(btnCollegeList.Location.X, btnCollegeList.Location.Y,175,154); 
btnAbout.SetBounds(btnAbout.Location.X, btnAbout.Location.Y, 175, 154); 

GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); 
polygon_path.AddPolygon(GetPoints(btnExam.ClientRectangle)); 
polygon_path.AddPolygon(GetPoints(btnResult.ClientRectangle)); 
polygon_path.AddPolygon(GetPoints(btnContactUs.ClientRectangle)); 
polygon_path.AddPolygon(GetPoints(btnClasses.ClientRectangle)); 
polygon_path.AddPolygon(GetPoints(btnCollegeList.ClientRectangle)); 
polygon_path.AddPolygon(GetPoints(btnAbout.ClientRectangle)); 

// Convert the GraphicsPath into a Region. 
Region polygon_region = new Region(polygon_path); 

// Constrain the button to the region. 
btnExam.Region = polygon_region; 
btnResult.Region = polygon_region; 
btnContactUs.Region = polygon_region; 
btnClasses.Region = polygon_region; 
btnCollegeList.Region = polygon_region; 
btnAbout.Region = polygon_region; 

}

以及所有按钮的“MouseEnter_Event”中的以下代码

private void genericButton_event(object sender, EventArgs e) 
{ 
var btn = (Button)sender; 
var imageName = btn.Name; 
btn.Image = (Bitmap)Properties.Resources.ResourceManager.GetObject(imageName); 
}

现在,如果我尝试在“MouseLeave_event”中使用下面的代码而不是我没有得到指定的图像,我没有得到比

private void genericButtonLeave_event(object sender, EventArgs e) 
{ 
var btn = (Button)sender; 
var imageName = btn.Name + "L"; 
btn.Image = (Bitmap)Properties.Resources.ResourceManager.GetObject(imageName); 
}

这就是我为按钮悬停图像所做的一切以获取更改请建议我如何获取图像mouseLeave event,错误在哪里

4

0 回答 0