dohtem
09-06-2004, 02:33 AM
Hi guys, I was following a tutorial on the Drunken Hyena website and I decided to do things differently (make my own mistakes and learn). Well I have hit a brick wall.
All this code does is create a window, It askes the user whether they want fullscreen or windowed, then makes it. They can also hit 'f' or 'w' to toggle between windowed and fullscreen after the window has been created. My problem is that when you choose windowed first, then hit 'f' to move to fullscreen mode, it makes a fullscreen sized window but it doesnt fill the screen with it. Hard to explain, please take a look. Any ideas?
using System;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
public class WindowsPrimer : System.Windows.Forms.Form
{
// full screen or windowed
protected bool m_fullscreen = false;
// window size
protected const int m_width = 800;
protected const int m_height = 600;
// used for window title and other prompts
protected const string m_name = "Windows Primer";
public WindowsPrimer()
{
// ask user fullscreen or windowed mode
//m_fullscreen = Utility.AskFullscreen(m_name);
if (MessageBox.Show("Do you want to run in fullscreen mode?", m_name,
MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk)
== System.Windows.Forms.DialogResult.Yes)
{
m_fullscreen = true;
}
//Set the window up based on the user's choice above
ConfigureWindow();
}
protected void ConfigureWindow()
{
AutoScale = false;
Name = m_name;
Text = m_name;
BackColor = System.Drawing.Color.Black;
// we dont want to see the minimize or maximize buttons
MaximizeBox = false;
MinimizeBox = false;
// center the form
StartPosition = FormStartPosition.CenterScreen;
// necessary for the first time
FullScreen(m_fullscreen);
}
private void FullScreen(bool status)
{
System.Drawing.Rectangle rect;
if (status)
{
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
rect = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
// ClientSize (member of Form) is just the drawable area
ClientSize = rect.Size;
Cursor.Hide();
}
else
{
ClientSize = new System.Drawing.Size(m_width,m_height);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
//Fixed3D means we cant resize the window
}
}
protected override void Dispose(bool disposing)
{
if(disposing)
{
//If we had stuff to dispose, we'd do it here
}
base.Dispose(disposing);
}
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case Keys.F:
m_fullscreen = true;
FullScreen(m_fullscreen);
break;
case Keys.W:
m_fullscreen = false;
FullScreen(m_fullscreen);
break;
case Keys.Escape:
this.Close();
break;
default:
base.OnKeyDown(e);
break;
}
}
protected override void OnClick(System.EventArgs e)
{
this.Close();
}
static int Main()
{
Application.Run(new WindowsPrimer());
return 0;
}
}
Any help would be appreciated. Thanks.
edit: Same code is posted here (http://muer.njoerdba.com/paste/view.aspx?id=7a93921d-2644-4ad8-ba84-8589534108ce) with syntax highlighting and better formatting.
All this code does is create a window, It askes the user whether they want fullscreen or windowed, then makes it. They can also hit 'f' or 'w' to toggle between windowed and fullscreen after the window has been created. My problem is that when you choose windowed first, then hit 'f' to move to fullscreen mode, it makes a fullscreen sized window but it doesnt fill the screen with it. Hard to explain, please take a look. Any ideas?
using System;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
public class WindowsPrimer : System.Windows.Forms.Form
{
// full screen or windowed
protected bool m_fullscreen = false;
// window size
protected const int m_width = 800;
protected const int m_height = 600;
// used for window title and other prompts
protected const string m_name = "Windows Primer";
public WindowsPrimer()
{
// ask user fullscreen or windowed mode
//m_fullscreen = Utility.AskFullscreen(m_name);
if (MessageBox.Show("Do you want to run in fullscreen mode?", m_name,
MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk)
== System.Windows.Forms.DialogResult.Yes)
{
m_fullscreen = true;
}
//Set the window up based on the user's choice above
ConfigureWindow();
}
protected void ConfigureWindow()
{
AutoScale = false;
Name = m_name;
Text = m_name;
BackColor = System.Drawing.Color.Black;
// we dont want to see the minimize or maximize buttons
MaximizeBox = false;
MinimizeBox = false;
// center the form
StartPosition = FormStartPosition.CenterScreen;
// necessary for the first time
FullScreen(m_fullscreen);
}
private void FullScreen(bool status)
{
System.Drawing.Rectangle rect;
if (status)
{
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
rect = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
// ClientSize (member of Form) is just the drawable area
ClientSize = rect.Size;
Cursor.Hide();
}
else
{
ClientSize = new System.Drawing.Size(m_width,m_height);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
//Fixed3D means we cant resize the window
}
}
protected override void Dispose(bool disposing)
{
if(disposing)
{
//If we had stuff to dispose, we'd do it here
}
base.Dispose(disposing);
}
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case Keys.F:
m_fullscreen = true;
FullScreen(m_fullscreen);
break;
case Keys.W:
m_fullscreen = false;
FullScreen(m_fullscreen);
break;
case Keys.Escape:
this.Close();
break;
default:
base.OnKeyDown(e);
break;
}
}
protected override void OnClick(System.EventArgs e)
{
this.Close();
}
static int Main()
{
Application.Run(new WindowsPrimer());
return 0;
}
}
Any help would be appreciated. Thanks.
edit: Same code is posted here (http://muer.njoerdba.com/paste/view.aspx?id=7a93921d-2644-4ad8-ba84-8589534108ce) with syntax highlighting and better formatting.