Fullscreen Form
Hello
Working with .net cf 2.0
The Problem:
I start an Application with a Mainform.
Inside the Mainform i start another form which should work as
a "Welcome Screen".
I want it to be fullscreen with a background picture.
So i derived my own form,
overrides the onpaint and onpainbackground method
set the WindowStyle to Maximized, disable the Minimize and Control Buttons
Set TopMost to true.
But when I show it, it displays the taskbar/start button
After clicking inside the form, it finaly redraws itself in fullscreen mode as wanted!
I tried differnt approaches
- using the SHFullScreen funktion
- Overriding OnLoad and OnActivated
but nothing works
Is this probably a bug in the .net cf 2.0 (its still beta)
Norbert
here is the Code
First the "StartScreen" Form:
| |
namespace MY_APP { public partial class Form_StartScreen : Form { Configurator cfg; // a helper class for storing configuration Data public IRemoteServer theServer; // the Server Object public Form_StartScreen() { theServer = null; cfg = Configurator.GetInstance(); InitializeComponent(); // Set the address text label_address.Text = cfg.ServerIPAddr[0] + ":" + (string)cfg.GetGenericValue("ServerPort"); } protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); Rectangle sourceRect = new Rectangle(0, 0, Properties.Resources.myapp_startscreen.Width, Properties.Resources.myapp_startscreen.Height); e.Graphics.DrawImage(Properties.Resources.myapp_startscreen, ClientRectangle, sourceRect, GraphicsUnit.Pixel); } protected override void OnPaint(PaintEventArgs e) { Brush br; StringFormat sf = new StringFormat(); sf.Alignment= StringAlignment.Center; foreach (Control c in Controls) { if (c is Label) { Label theLabel = (Label)c; br = new SolidBrush(theLabel.ForeColor); e.Graphics.DrawString(theLabel.Text, theLabel.Font, br, theLabel.Bounds, sf); } } base.OnPaint(e); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); TopMost = true; this.WindowState = FormWindowState.Maximized; //Form_StartScreen.SHFullScreen(this.Handle, SHFS_HIDESTARTICON); } protected override void OnActivated(EventArgs e) { TopMost = true; this.WindowState = FormWindowState.Maximized; //Form_StartScreen.SHFullScreen(this.Handle, SHFS_HIDESTARTICON); Invalidate(); } private void button_Cancel_Click(object sender, EventArgs e) { this.Close(); } protected override void OnClick(EventArgs e) { //This code handles the problem, that sometimes the Button doesn't get the event if (Control.MousePosition.Y > button_Cancel.Top && Control.MousePosition.Y < button_Cancel.Bottom) if (Control.MousePosition.X > button_Cancel.Left && Control.MousePosition.X < button_Cancel.Right) { button_Cancel_Click(this, e); return; } Cursor.Current = Cursors.WaitCursor; // When the User tap on the form I "start the Apllication" connected // when cancel the User get the "Config Screen" of the MainForm. int port = Convert.ToInt32((string)cfg.GetGenericValue("ServerPort")); try { theServer = new RemoteTCPServer(cfg.id, cfg.ServerIPAddr[0], port, 0); } catch (Exception ex) { string errortext = Properties.Resources.Con_Error_Text1 + "\r\n" + ex.Message + "\r\n"; errortext += "\r\n" + Properties.Resources.Con_Error_Text2; MessageBox.Show(errortext, Properties.Resources.Con_Error_Header, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); if (theServer != null) theServer.Dispose(); theServer = null; } Cursor.Current = Cursors.Default; base.OnClick(e); } } } // This is an extract from the Initalizecomponents Method /* this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(240, 320); this.ControlBox = false; this.Controls.Add(this.button_Cancel); this.Controls.Add(this.label_info); this.Controls.Add(this.label_address); this.Controls.Add(this.label2); this.Controls.Add(this.label_header); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Location = new System.Drawing.Point(0, 0); this.MinimizeBox = false; this.Name = "Form_StartScreen"; this.TopMost = true; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.ResumeLayout(false); */ |
####################################################
and here how i call it in the main form:
| |
//In the constructor I create the form public MainForm() { startscreen = new Form_StartScreen(); startscreen.Click += new EventHandler(startscreen_Click); // This method handles some connecting stuff /// lots of other configuration } // in the onLoad function i "show" the startscreen // I tried OnActivate , but it also doesnt worked protected override void OnLoad(EventArgs e) { base.OnLoad(e); startscreen.Show(); } |