2010-12-18 82 views

回答

1

您可以使用其BackgroundImage创建无边框窗体来显示图像。使其与次屏幕一样大。像这样:

public static Form ShowImage(Image image) { 
     Form frm = new Form(); 
     frm.ControlBox = false; 
     frm.FormBorderStyle = FormBorderStyle.None; 
     frm.BackgroundImage = image; 
     frm.BackgroundImageLayout = ImageLayout.Zoom; 
     Screen scr = Screen.AllScreens.Length > 1 ? Screen.AllScreens[1] : Screen.PrimaryScreen; 
     frm.Location = new Point(scr.Bounds.Left, scr.Bounds.Top); 
     frm.Size = scr.Bounds.Size; 
     frm.BackColor = Color.Black; 
     frm.Show(); 
     return frm; 
    } 

请注意,它返回一个Form对象,调用它的Close()方法来再次摆脱该图像。

+0

其实我想要显示图像的实际分辨率,所以如果它的800×600图像应该显示为没有缩放和缩放。 – 2010-12-18 18:32:24

+0

更改BackkgroundImageLayout。如果您有其他要求,请使用表单的Paint事件。 – 2010-12-18 18:34:40

2

使用WinAPI中的SetWindowPos。

实施例:

[DllImport("user32.dll")] 
public static extern void SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int X, int Y, int width, int height, uint flags); 
public Form1() 
{ 
    InitializeComponent(); 
    this.FormBorderStyle = FormBorderStyle.None; 
    SetWindowPos(this.Handle, IntPtr.Zero, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, 64); 
}

替换PrimaryScreen与已选定的屏幕。

我不知道图像可以做什么。你可以使用一个Picturebox或者创建你的控制器并用GDI显示它。

+0

你的意思是,我应该添加一个图片框到窗体中,然后设置图片框大小与窗体相同,对不对? – 2010-12-18 15:15:12

相关问题