How to Set Background Image in Windows Form in C#
小编典典
C# Windows Form Transparent Background Image
c#
When I tried from with transparent background, it's not completely
transparent. I tried two code blocks for this issue. First i tried like this
code:
public Form1() { InitializeComponent(); SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; this.FormBorderStyle = FormBorderStyle.None; //this.WindowState = System.Windows.Forms.FormWindowState.Maximized; }
it look like this picture;
Then i found some different codes and tried ike this;
public Form1() { InitializeComponent(); this.TransparencyKey = Color.White; this.BackColor = Color.White; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; }
And this looks like this picture;
You can see logo with a white border. I want to show only .png Logo completely
transparent. What should i do? How can do this?
Here is my Logo image as .png;
阅读 682
收藏
2020-05-19
小编典典
You can use Layered Windows
Using a layered window can significantly improve performance and visual
effects for a window that has a complex shape, animates its shape, or wishes
to use alpha blending effects. The system automatically composes and repaints
layered windows and the windows of underlying applications. As a result,
layered windows are rendered smoothly, without the flickering typical of
complex window regions. In addition, layered windows can be partially
translucent, that is, alpha-blended.
Create layered window in Windows Forms
Here is some code from msdn code
gallery
which demonstrates creating Layered Windows in Windows Forms. It allows you to
create a shaped splash screen and let you to move it by mouse.
Add PerPixelAlphaForm
to the project and then it's enough to inherit from
this form and call its SelectBitmap
and pass your png to the method to
create a layered window.
PerPixelAlphaForm.cs
#region Using directives using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; using System.Runtime.InteropServices;