我有一系列图像存储在目录中,并希望在全屏模式下在辅助监视器上连续显示它们。
我没有显示图像全屏模式的线索。 知道如何在C#中做到这一点吗?
答案 0 :(得分: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显示它。
答案 1 :(得分: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()方法再次删除图像。