Windows CE在表单顶部显示不存在的面板

时间:2015-04-21 13:20:20

标签: c# winforms windows-ce

我使用.NET 3.5创建了简单的窗体。该应用程序在Windows CE设备上运行。

当我在我的应用程序中显示此表单时,灰色线条覆盖表单的顶部cca 20像素。

屏幕截图,红色椭圆:

screenshot

代码:

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;
    }
}

表单上没有显示灰色面板的面板,标签,texbox或其他任何内容。它不是一个控件,它应该是隐形的或类似的东西 - 那里什么都没有。我想不出任何可能导致这种情况的事情。

1 个答案:

答案 0 :(得分:5)

表单自动添加System.Windows.Forms.MainMenu。在设计器中将其删除(您将在窗体设计器下方的灰色区域中找到它,其中所有不可见的控件,如定时器,串行端口等)。

您也可以在发布的设计师代码中看到它:

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