Zbynek
Zbynek

Reputation: 5955

Windows CE shows non-existing panel on top of form

I have created simple windows form using .NET 3.5. The application runs on Windows CE device.

When i show this form in my application, there is grey line covering top cca 20 pixels of the form.

Screenshot, in red ellipse:

screenshot

Code:

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace eInventorymobile
{
    public partial class frmCustomMessageBox : Form
    {
        #region --- fields ---

        MessageBoxButtons btns;

        #endregion

        #region --- form methods ---

        /// <summary>
        /// Inicializace
        /// </summary>
        /// <param name="btns"></param>
        /// <param name="sTitle"></param>
        /// <param name="sMessage"></param>
        public frmCustomMessageBox(MessageBoxButtons btn, string sTitle, string sMessage)
        {
            InitializeComponent();

            this.btns = btn;
            lblTitle.Text = sTitle;
            lblMessage.Text = sMessage;

        }

        private void frmCustomMessageBox_Load(object sender, EventArgs e)
        {
            switch (this.btns)
            {
                case MessageBoxButtons.OK:
                    btnOk.Visible = true;
                    btnNo.Visible = false;
                    btnYes.Visible = false;
                    btnOk.Focus();
                    break;
                case MessageBoxButtons.YesNo:
                    btnOk.Visible = false;
                    btnNo.Visible = true;
                    btnYes.Visible = true;
                    btnYes.Focus();
                    break;
                default:
                    btnOk.Visible = false;
                    btnNo.Visible = true;
                    btnYes.Visible = true;
                    btnYes.Focus();
                    break;
            }
        }

        #endregion

        #region --- events ---

        /// <summary>
        /// Kliknuti na ANO nastavi dialog result na Yes a ukonci formular
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnYes_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        /// <summary>
        /// Kliknuti na NE nastavi dialog result na Ne a ukonci formular
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNo_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        /// <summary>
        /// Kliknuti na OK nastavi dialog result na OK a ukonci formular
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        #endregion

    }
}

namespace eInventorymobile
{
    partial class frmCustomMessageBox
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        private System.Windows.Forms.MainMenu mainMenu1;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.lblMessage = new System.Windows.Forms.Label();
            this.btnYes = new System.Windows.Forms.Button();
            this.btnNo = new System.Windows.Forms.Button();
            this.btnOk = new System.Windows.Forms.Button();
            this.panel1 = new System.Windows.Forms.Panel();
            this.lblTitle = new System.Windows.Forms.Label();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // lblMessage
            // 
            this.lblMessage.Font = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Bold);
            this.lblMessage.ForeColor = System.Drawing.Color.White;
            this.lblMessage.Location = new System.Drawing.Point(12, 44);
            this.lblMessage.Name = "lblMessage";
            this.lblMessage.Size = new System.Drawing.Size(170, 63);
            this.lblMessage.Text = "Message";
            // 
            // btnYes
            // 
            this.btnYes.BackColor = System.Drawing.Color.Gray;
            this.btnYes.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold);
            this.btnYes.ForeColor = System.Drawing.Color.White;
            this.btnYes.Location = new System.Drawing.Point(5, 110);
            this.btnYes.Name = "btnYes";
            this.btnYes.Size = new System.Drawing.Size(91, 35);
            this.btnYes.TabIndex = 1;
            this.btnYes.Text = "ANO";
            this.btnYes.Click += new System.EventHandler(this.btnYes_Click);
            // 
            // btnNo
            // 
            this.btnNo.BackColor = System.Drawing.Color.Gray;
            this.btnNo.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold);
            this.btnNo.ForeColor = System.Drawing.Color.White;
            this.btnNo.Location = new System.Drawing.Point(103, 110);
            this.btnNo.Name = "btnNo";
            this.btnNo.Size = new System.Drawing.Size(91, 35);
            this.btnNo.TabIndex = 2;
            this.btnNo.Text = "NE";
            this.btnNo.Click += new System.EventHandler(this.btnNo_Click);
            // 
            // btnOk
            // 
            this.btnOk.BackColor = System.Drawing.Color.Gray;
            this.btnOk.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold);
            this.btnOk.ForeColor = System.Drawing.Color.White;
            this.btnOk.Location = new System.Drawing.Point(53, 110);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(91, 35);
            this.btnOk.TabIndex = 3;
            this.btnOk.Text = "OK";
            this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
            // 
            // panel1
            // 
            this.panel1.BackColor = System.Drawing.Color.RoyalBlue;
            this.panel1.Controls.Add(this.lblTitle);
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(198, 33);
            // 
            // lblTitle
            // 
            this.lblTitle.BackColor = System.Drawing.Color.Transparent;
            this.lblTitle.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
            this.lblTitle.ForeColor = System.Drawing.Color.White;
            this.lblTitle.Location = new System.Drawing.Point(5, 7);
            this.lblTitle.Name = "lblTitle";
            this.lblTitle.Size = new System.Drawing.Size(189, 25);
            this.lblTitle.Text = "Title";
            // 
            // frmCustomMessageBox
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            this.AutoScroll = true;
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(57)))), ((int)(((byte)(60)))), ((int)(((byte)(69)))));
            this.ClientSize = new System.Drawing.Size(198, 150);
            this.ControlBox = false;
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.lblMessage);
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.btnNo);
            this.Controls.Add(this.btnYes);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Location = new System.Drawing.Point(20, 60);
            this.MaximizeBox = false;
            this.Menu = this.mainMenu1;
            this.MinimizeBox = false;
            this.Name = "frmCustomMessageBox";
            this.Text = "frmCustomMessageBox";
            this.TopMost = true;
            this.Load += new System.EventHandler(this.frmCustomMessageBox_Load);
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Label lblMessage;
        private System.Windows.Forms.Button btnYes;
        private System.Windows.Forms.Button btnNo;
        private System.Windows.Forms.Button btnOk;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label lblTitle;
    }
}

There is no panel, or label, or texbox, or anything else on the form, where the grey panel is displayed. It is not a control, which should be invisible or anything similar - there is just nothing there. I can not think of anything, which could cause this.

Upvotes: 1

Views: 674

Answers (1)

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56717

It is the automatically added System.Windows.Forms.MainMenu for the form. Remove it in the designer (you'll find it in the gray area below the forms designer, where all the non-visible controls like timers, serial ports etc. go).

You can also see it in the designer code you posted:

private void InitializeComponent()
{
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    ...

Upvotes: 5

Related Questions