110,534
社区成员
发帖
与我相关
我的任务
分享
public partial class Form15 : Form
{
public Form15() {
InitializeComponent();
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.CenterScreen;
}
//调用 SetWindowLong 也可以
protected override CreateParams CreateParams {
get {
CreateParams cParms = base.CreateParams;
cParms.ExStyle |= 0x00080000; // WS_EX_LAYERED
return cParms;
}
}
private void Form15_Load(object sender, EventArgs e) {
Bitmap bmp = (Bitmap)Image.FromFile("./back.png");
this.ClientSize = bmp.Size;
IntPtr hScreenDC = Win32.GetDC(IntPtr.Zero);
IntPtr hMemDC = Win32.CreateCompatibleDC(hScreenDC);
IntPtr hBmpOld = Win32.SelectObject(hMemDC, bmp.GetHbitmap(Color.FromArgb(0)));
Win32.LPPOINT pt = new Win32.LPPOINT();
pt.X = this.Left;
pt.Y = this.Top;
Win32.LPPOINT sz = new Win32.LPPOINT();
sz.X = bmp.Width;
sz.Y = bmp.Height;
Win32.LPPOINT ptScreen = new Win32.LPPOINT();
Win32.BLENDFUNCTION bf = new Win32.BLENDFUNCTION();
bf.BlendOp = Win32.AC_SRC_OVER;
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = Win32.AC_SRC_ALPHA;
bf.BlendFlags = 0;
Win32.UpdateLayeredWindow(this.Handle, hScreenDC, ref pt, ref sz, hMemDC, ref ptScreen, 0, ref bf, Win32.ULW_ALPHA);
Win32.DeleteObject(hBmpOld);
Win32.DeleteDC(hScreenDC);
Win32.DeleteDC(hMemDC);
}
}
private void image_MouseDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
这样就能在windows 桌面拖动菊花了。<Window x:Class="你的窗体class类型"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestXQQClient"
mc:Ignorable="d"
Title="无边框窗体"
Height="300"
Width="300"
AllowsTransparency="True"
WindowStyle="None"
Background="Transparent">
<Grid>
<Calendar HorizontalAlignment="Left"
Margin="111,109,0,0"
VerticalAlignment="Top"/>
<Image x:Name="image"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Stretch="None"
Source="http://www.neoimaging.cn/png/ni_png_0271.png"
MouseDown="image_MouseDown"/>
<TextBlock HorizontalAlignment="Left"
Margin="52,152,0,0"
Text="拖动菊花"
VerticalAlignment="Top"/>
</Grid>
</Window>
当这个东西在你的 windows 桌面上拖动到各种背景前边去看,你能看到菊花周边有很多锯齿吗?