c# - Windows CE 在窗体顶部显示不存在的面板

标签 c# winforms windows-ce

我使用 .NET 3.5 创建了简单的 Windows 窗体。该应用程序在 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;
    }
}

没有显示灰色面板的面板、标签、文本框或表单上的任何其他内容。它不是一个控件,它应该是不可见的或类似的东西——那里什么也没有。我想不出任何可能导致这种情况的原因。

最佳答案

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

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

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

关于c# - Windows CE 在窗体顶部显示不存在的面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29773405/

相关文章:

c# - 将大数据集加载到 GridView 中的最快方法是什么?

c# - 通过 C# 获取应用程序运行的根目录的普遍方法

visual-studio - Windows Mobile 设备模拟器 - 创建具有自定义分辨率的设备

c++ - GetDiskFreeSpaceEx 报告错误的可用字节数

c# - 在包含许多对象的大 Canvas 中拖动性能

c# - .NET 版本号(安装程序版本)

c# - 如何在 Xamarin.Forms 中强制使用灯光模式?

c# - 可以修改 Linq To SQL 生成的 C# 吗?

c# - 将复杂文本作为字符串获取

testing - 网络带宽评估工具