[.net] C# Fullscreen video problem

Started by
3 comments, last by gharen2 17 years, 1 month ago
Hi! I have a problem with my managed game engine in that pressing Esc when in fullscreen mode the render window gets minimized for no apparent reason. When in windowed mode this does not happen, and I certainly have not hooked the Esc-keystroke to any event or function that would cause the window to minimize. Other keys do not minimize the window, just Esc and only in fullscreen mode. I use C# and Managed DirectX 1.1. The window is shown with ShowDialog(). Any ideas? //chinc
Advertisement
Try using just "Show" instead of "ShowDialog", and see if that makes a difference.

ShowDialog may be performing some default action (ie, closing the window), when you hit escape, since the window is treated as a dialog box. There's no reason to use ShowDialog for full screen rendering anyways.

[Edited by - gharen2 on March 8, 2007 1:08:37 AM]
When using Show() instead of ShowDialog() the render window just flashes and closes. I know I should be using Application.Run() with the window as a parameter but then I cannot close the window and show it again during the same program run. Anyone know why?

However, I solved the problem in a very easy but wierd way. It seems that I just have to call this.Focus() in the keydown event handler of the window and everything works fine. Don't know why, but it works :)
because the Focus event restores a minimized window... so you're really minimizing and restoring it back very quickly.

Jared "EagleEye" Mark
The reason your window immediately closes with "show" is that the function returns after showing the window, and your program ends. This is different from ShowDialog, which doesn't return until an action is performed (hitting escape in your case). You need to setup a loop so it stays open.

I don't recommend using Application.Run in a game. You can have full control over the rendering loop this way:

public static void Main{    Form form = new Form();    form.Show();    // initialise directx    while(form.Created)    {        if(form.Active)        {           // render        }        Application.DoEvents();     }}

This topic is closed to new replies.

Advertisement