在MouseLeave事件的按钮没有得到正确的图像

时间:2013-10-27 05:40:07

标签: c# winforms

在表单加载中,我将此代码用于所有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上获取图像,哪里是错误

0 个答案:

没有答案