图片按钮的制作方法 [英] How to make image button

查看:27
本文介绍了图片按钮的制作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么能做到这一点.我知道我可以使用按钮组件,但是当我给它一个图像时,它周围有一些灰色的东西.使用图像按钮如何为悬停效果显示另一个图像

I was wondering how could I do this. I know I can use the button component but it has the little gray stuff around it when I give it a image. With image button how could I show another image for the hover effect

推荐答案

您想创建一个没有边框但用户将鼠标悬停在其上时显示不同图像的按钮?您可以这样做:

You want to create a button with no border but displays different images when the user hovers over it with the mouse? Here's how you can do it:

  1. 在表单中添加一个 ImageList 控件,添加两张图片,一张用于按钮的正常外观,另一张用于鼠标悬停时的外观.

  1. Add an ImageList control to your form at add two images, one for the button's normal appearance and one for when the mouse is hovering over.

添加您的按钮并设置以下属性:
FlatStyle = Flat
FlatAppearance.BorderColor(也可能是 MouseOverBackColorMouseDownBackColor)到表单的背景颜色
ImageList = 您添加到表单中的 ImageList
ImageIndex 到普通图片的索引值

Add your button and set the following properties:
FlatStyle = Flat
FlatAppearance.BorderColor (and maybe MouseOverBackColor & MouseDownBackColor) to your form's background color
ImageList = the ImageList you added to the form
ImageIndex to the index value of your normal image

为按钮编写 MouseHover 和 MouseLeave 事件,如下所示:

Code the MouseHover and MouseLeave events for the button like this:

// ImageList index value for the hover image.
private void button1_MouseHover(object sender, EventArgs e) => button1.ImageIndex = 1;

// ImageList index value for the normal image.
private void button1_MouseLeave(object sender, EventArgs e) => button1.ImageIndex = 0;

我相信这会给你想要的视觉效果.

I believe that will give you the visual effect you're looking for.

这篇关于图片按钮的制作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆