这是(测试的)解决方案。此代码可以用于WinForm或WPF应用程序。 根本不需要XAML。
#region WPF
// include following references:
// PresentationCore
// PresentationFramework
// WindowsBase
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
#endregion
public class WPFWindow : Window
{
private Canvas canvas = new Canvas();
public WPFWindow()
{
this.AllowsTransparency = true;
this.WindowStyle = WindowStyle.None;
this.Background = Brushes.Black;
this.Topmost = true;
this.Width = 400;
this.Height = 300;
canvas.Width = this.Width;
canvas.Height = this.Height;
canvas.Background = Brushes.Black;
this.Content = canvas;
}
}
窗口背景是完全透明的。 您可以在画布上绘图,并且每个元素都可以具有自己的透明度(您可以通过设置用于绘制画笔的画笔的Alpha通道来确定)。 简单的东西调用的窗前,仿佛
WPFWindow w = new WPFWindow();
w.Show();
,看一下我的回答是:http://stackoverflow.com/questions/8311956/open-wpf-window-in-windowsform-app/32691690#32691690 – 2015-09-21 10:00:55