transparent background for Rad ShapedForm

13 posts, 0 answers
  1. mdanh
    mdanh avatar
    17 posts
    Member since:
    Jul 2012

    Posted 12 Jan 2010 Link to this post

    How do I set make my ShapedForm's background color transparent? Setting in in the Visual Studio designer throws exception "Control does not support transparency". I am using an image with rounded corner as the background for the form, so unless the background color is transparent, there will be a small area at the form's corners having the same color as the form's background color, which doesn't look nice.

    Thanks
  2. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 14 Jan 2010 Link to this post

    Hi mdanh,

    In .NET Windows Forms, the top-level windows do not support transparent colors. Since our ShapedForm is a top-level window (or simply a form), it does not support transparent colors as well.

    However, you can set the TransparencyKey property to the value of the BackColor. This will make the background of ShapedForm transparent. You may also need to set the color of the border - it can be set to Transparent:
    this.TransparencyKey = this.BackColor;
    this.BorderColor = Color.Transparent;

    If you have additional questions, feel free to contact me.

    All the best,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. mdanh
    mdanh avatar
    17 posts
    Member since:
    Jul 2012

    Posted 14 Jan 2010 Link to this post

    Thanks, that really helps :)
  5. Afraei
    Afraei avatar
    18 posts
    Member since:
    Jun 2012

    Posted 02 Jun 2012 Link to this post

    Hello Nikolay

    Could you please give us a sample project that show a transparent background ShapedForm? I have recently checked your tip by Telerik 2012 Q1 and VS 2010 but unfortunately it didn't work as well as is expected. I created a ShapedForm and set (this.TransparencyKey = this.BackColor) then put a PNG transparent image as the form's background image but the form's background didn't appear in transparent manner.

    Your kindly help is very appreciated in advance.
    Best Regards
  6. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 06 Jun 2012 Link to this post

    Hi Afraei,

    Thank you for writing.

    I am not quite sure what your image is, but if it has a color that is supposed to become transparent and this color is the same as the BackColor of the ShapedForm, both the ShapedForm and the color of the image should become transparent. I am attaching a sample project which covers this scenario. Note there, that one of the colors of the image is the same as the color of the ShapedForm and when this color is set as a TransparencyKey, the appropriate regions of the form become fully transparent.

    I hope this helps.

    Kind regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  7. Afraei
    Afraei avatar
    18 posts
    Member since:
    Jun 2012

    Posted 07 Jun 2012 Link to this post

    Hello Dear Nikolay

    Actually, I want to create a Splash form with a partly transparent PNG image. How can I do this. my PNG image and a sample of desired Splash form are attached.

    Thank you again
    Regards
  8. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 07 Jun 2012 Link to this post

    Hello Afraei,

    You should follow the approach that I demonstrated in the attached sample project. It seems that you want the white color to become transparent, so you should set the White color as a BackColor of the ShapedForm and you should also set the TransparencyKey to White.

    Regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  9. Afraei
    Afraei avatar
    18 posts
    Member since:
    Jun 2012

    Posted 07 Jun 2012 Link to this post

    Thank you for your kindly reply.

    I changed backcolor = white and transparencykey = white but as you see in the new attachment it is not like the above JPG attachment.
  10. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 08 Jun 2012 Link to this post

    Hello Afraei,

    I investigated your PNG image carefully and now I understand that it has a transparent color, but not a white color as I initially thought. So, you do not need to set white colors anywhere. Still, with or without setting a white color, I was not able to reproduce the issue that you have. I even tried the sample application with your image on WindowsXP (based on your desktop background image), but the image was transparent there as well as you can see in the screenshot attached to my response.

    Please note that ShapedForm does not do anything special in the context of transparency and the issue should be a general case to the machine where you are trying my sample project. I would suggest that you try your scenario with the standard Microsoft Form and if you succeed in achieving transparency there, please write back so that we can apply the same approach to our ShapedForm.

    Kind regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  11. Afraei
    Afraei avatar
    18 posts
    Member since:
    Jun 2012

    Posted 08 Jun 2012 Link to this post

    Hello Nikolay

    Did you create the form that is in opacity.png by telerik? If so, Actually, I need exactly something like that but i don't know how to set the Telerik's form's property to show transparent parts of image. Could you share us your last sample aplication that creates the form in the Opacity.png?

    Regards
  12. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 08 Jun 2012 Link to this post

    Hello Afraei,

    As I implied in my previous reply, the form that you see is the ShapedForm from my sample project with your image and there is nothing additional to it. Therefore, it seems like the issue where you do not get transparent colors is specific to your system and not to our suite. Once again, I would kindly ask you to try experimenting with the standard Microsoft Form which would act the same as ShapedForm. If you manage to achieve transparency with the standard form, you should have no issues to do the same with our ShapedForm.

    For your reference, I am attaching my sample project with your image used in it. I hope this helps.

    Greetings,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  13. Afraei
    Afraei avatar
    18 posts
    Member since:
    Jun 2012

    Posted 08 Jun 2012 Link to this post

    Hello Dear Nikolay

    Thank you again for your great help.

    Now I can see the image as a transparent image. As I understood, when I set BackgroundImageLayout by values other than None or Tile or set DoubleBuffered by True then the transparent form will be appeared non-transparent.

    Thank you for your appreciated help.
    Regards
  14. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 12 Jun 2012 Link to this post

    Hi Afraei,

    Thank you for sharing your findings with the community.

    I am glad to heat that transparency is achieved on your side as well.

    Regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready