如何在C#中没有窗口的情况下显示图像

时间:2011-12-01 22:28:35

标签: c# image

我想知道如何在没有打开窗口的情况下打开图像,因此它就像图像漂浮在桌面上而没有边框。感谢

3 个答案:

答案 0 :(得分:6)

您要做的是在屏幕上绘制图像,周围没有可见的窗口边框。是否创建窗口是一个完全不同的问题。事实证明,你必须有一个窗口。它只是不可见。所以:

创建一个窗口,确保在InitializeComponent()中设置以下内容:

this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowIcon = false;
this.ShowInTaskbar = false;

然后,覆盖该窗口的OnPaintBackground,如下所示:

protected override void OnPaintBackground( WinForms.PaintEventArgs e )
{
    e.Graphics.DrawImage( Image, 0, 0, Width, Height );
}

答案 1 :(得分:6)

如果你想要的只是splash screen,那么就有一个框架组件:http://msdn.microsoft.com/en-us/library/system.windows.splashscreen.aspx

答案 2 :(得分:3)

显示没有标题栏的窗口

如果是winforms -

FormBorderStyle = None
ControlBox = false

取自 - Windows Form with Resizing Frame and no Title Bar?

如果是XAML,请使用此选项显示没有标题栏的窗口 -

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="640" Height="480" 
    WindowStyle="None"
    AllowsTransparency="True"
    ResizeMode="CanResizeWithGrip">

    <!-- Content -->

</Window>

取自 - Is it possible to display a wpf window without an icon in the title bar?

相关问题