如何在Visual C#中创建透明按钮? [英] How to make a transparent button in Visual C#?

查看:168
本文介绍了如何在Visual C#中创建透明按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序有问题。我在Windows窗体应用程序中选择了一张图片。并在其上创建一个按钮。但按钮隐藏了其区域的图片。我想让我的按钮透明。按钮的onle文本可以看到,但按钮的背景将反映表单的背景图像。

请帮助

解决方案

透明按钮在某种意义上很容易实现,但在大多数情况下,这是无稽之谈。这就是原因。任何屏幕上的对象只有在某些结构化背景上显示时才被认为是半透明的,并且它正在这个背景上移动,因此观众可以识别出这个背景的元素。你有图案背景吗?你想移动按钮吗?如果没有,透明和不透明的按钮是相同的,只有你可以用于按钮渲染的图像问题,正如CodeHawkz在本评论中提到的那样。您可以使用任何UI库来完成。您只需要为不同的按钮状态创建不同的图像。



-SA


嗯,目前,WinForms不支持这样的透明度。您可以使用的可能解决方案,



1.使用ButtonBase从Control中导出您的控件。

2.使用Parent的方法:DrawToBitmap()获取按钮下的背景,然后使用OnPaint()绘制该图像。


首先,为什么要创建一个图像,然后在其上创建按钮。 />


您只需按一下即可实现此目的。



首先,创建一个按钮并添加任何文本希望。

然后,要包含图像,请转到Buttonproperty的BackgroundImage并添加图像。这将引导您达到您的要求。这样你的文字就会出现在你的背景上。



看看这段代码,



 btnLogin.Text =  这将显示为; 
btnLogin.BackgroundImage =((System.Drawing.Image)(Properties.Resources.PTLY_logo));







如果您对此问题有任何疑问,请与我们联系。感谢。


I have a problem with my program.I have selected a picture in my windows form application. and the create a button over it. but the button hides the picture of its area. i want to make my button transparent. that is onle text of button can visible but the background of button will reflect the background image of the form.
Please help

解决方案

"Transparent button" is easy to implement, in certain sense, but in most cases this is nonsense. Here is why. Any on screen object can be considered semi-transparent only if it is shown on some structured background, and it is moving over this background, so the spectator can recognize the elements of this background showing through. Do you have a patterned background? Do you want to move the buttons? If not, transparent and not transparent buttons are the same, it's only the matter of the image you can use as for your button rendering, as CodeHawkz mentioned in this comment. You can do it using any UI library. You only need to create different images for different button states.

—SA


Well, At the moment WinForms don't support transparency like that. Possible solutions that you can make use of,

1. Derive your control from Control instead using the ButtonBase.
2. Use Parent's method: DrawToBitmap() to get background under your button and then draw that image using OnPaint().


First of all why do you want to create an image and then button on it.

You can simply achieve this with a button.

First, create a Button and add any text as you wish.
then,to include the image, go to BackgroundImage of the Buttonproperty and add an image. This will lead you to what you require. This way your text will appear on your background.

Look at this code,

btnLogin.Text = "This will appear";
            btnLogin.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.PTLY_logo));




Let me know if you have any questions regarding this issue. Thanks.


这篇关于如何在Visual C#中创建透明按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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