Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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
Posted
Comments
CodeHawkz 19-Sep-12 1:49am    
What's stopping you from using the image itself as a button? :) If you are using WPF, this is achievable easily
Sergey Alexandrovich Kryukov 19-Sep-12 3:13am    
You are absolutely right, but WPF or not -- does not matter much. In certain sense, "transparent button" is nonsense. The object is transparent if it can be moved, and the background elements are showing. If background is uniform or there is no motion, it does not matter is the top element transparent or not. So many developers miss this simple thing.

Please see my answer.
--SA
Sergey Alexandrovich Kryukov 19-Sep-12 3:05am    
Add a tag: "Forms".
--SA

"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
 
Share this answer
 
Comments
CodeHawkz 19-Sep-12 4:35am    
Rather than a concrete implementation, teach the principals/theory behind of a solution, which he/she can reuse << This is something I strongly believe :) And you have done it exactly. My 5
Sergey Alexandrovich Kryukov 19-Sep-12 17:07pm    
Thank you very much.
--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().
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Sep-12 3:15am    
Not as simple: a button has unique behavior: when a mouse goes out, it looks pressed (and visa versa), but the Click event is generated only if a mouse released in the button. This is not so easy to achieve if you derive it from Control. I've done it, but it took considerable effort.
--SA
Sergey Alexandrovich Kryukov 19-Sep-12 3:16am    
Besides: "don't support transparency" is correct, but... unrelated to button, because, in certain sense, "transparent button" is nonsense. The object is transparent if it can be moved, and the background elements are showing. If background is uniform or there is no motion, it does not matter is the top element transparent or not. So many developers miss this simple thing.

Please see my answer.
--SA
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,

C#
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.
 
Share this answer
 
follow this steps
(1)select button than go to properties ;
(2)write button name in text;
(3)select background image than ok;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900