如何自定义像这样的按钮控件?
我想制作一个像这样的自定义按钮控件(图像按钮可以)。
我是新用户,所以不能在这里发布图片。所以我上传了图片这里
尝试后我现在有点绝望一些教程
任何建议都将受到高度赞赏。
谢谢
更新08/10/2019:我很多年前就问过这个问题,当时我没有上传图片的权限,所以我上传到第三方网站的图片是现在已经走了很久了。我收到了很多关于重新上传图像的请求,所以这是我八年前做的那个项目的记忆,我只是找到了一些与我的记忆相匹配的关于窗口窗体的随机图像
I want to make a custom button control (image button is ok) like this one.
I'm a new user, so I can't post image here. So I uploaded the picture here
I'm kind of desperate right now after trying some tutorials
Any suggestion is highly appreciated.
Thanks
Updated 08/10/2019: I asked this question so many years ago, and at that time I didn't have the permission to upload image, so the image I uploaded to the third party site is long gone now. I got many requests about re-uploading the image, so here is what I remember from that project I did eight years ago, I just find some random images about window form that match my memory
This is when the button is in normal state
This is when the button is hovered or clicked, with the rounded border
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建一个继承自 Button 的类,以将所有样式保留在一个位置。要执行悬停和按下状态,您可以覆盖按钮的鼠标输入/离开事件并更改样式。
这是我们的一个项目的示例(我更改了颜色,但您明白了)。在我们更改一些颜色的地方,您可以切换图像。
You could create a class that inherits from Button to keep all your styling in one place. To do the hover and pressed states you can override the mouse enter / leave events of the button and change style.
Here is an example from one of our projects (I changed the colours but your get the idea). Where we change some colours you could switch the images.
看不到图片,但我想你可以更改按钮的边框并设置背景图像。
Can't see the picture but I guess you can change the border of the button and set a background image.
我认为最简单的方法是设置按钮的一些属性,如下所示,
然后编写更新代码
:
我不知道我是否正确,但我认为您也可以通过放置按钮和标签来实现您的目标在面板内并根据您的选择排列它们。将
button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
初始化为Label.Text="Normal"
。然后在鼠标进入面板时,在按钮周围绘制一个带有边框的矩形,并将标签文本更改为“Hover
”。就像单击面板一样,您也可以根据您的需要更改矩形边框并设置label.Text="OnClick"
。I think the simplest way is set some properties of the button like below and
then write the code for
Update:
I don't know whether I am going correct or not but I think You can also achive your goal by putting a Button and a label inside a panel and arrange them according to your choice. Make the
button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
at initial withLabel.Text="Normal"
. Then on Mouse enter to the Panel draw a rectangle with a border around the button and change the text of the label to "Hover
". Like that Clicking on the Panel also you change the rectangle border according to you and make thelabel.Text="OnClick"
.