首页 > 解决方案 > WinCe 6 上的 Windows 窗体应用程序

问题描述

我正在构建一个简单的 Windows 窗体应用程序。

它非常简单,在我的 Windows PC 上运行没有任何问题。

如果我尝试在我的 Windows Ce 设备上复制 .exe 和 .pdb 文件并尝试启动它,我会收到以下错误:

File or assembly name
'System.windows.forms, Version= 2.0.0.0, Culture=neutral, PublickKeyToke= ..... or one of its dependecies, was not found.

我的应用程序有两个简单的文本框,并在 .txt 文件中写入文本。这是 Form1.cs 的代码:

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

namespace EasyManagementOrdine
{
    public partial class Form1 : Form
    {
        private const string FILE_NAME = "ESPORTAZIONE.txt";

        public List<string> listaString = new List<string>();

        public StreamWriter sw;

        public Form1()
        {
            try
            {
                InitializeComponent();
                if (File.Exists("ESPORTAZIONE.txt"))
                {
                    File.Delete("ESPORTAZIONE.txt");
                }
                this.sw = File.CreateText("ESPORTAZIONE.txt");
                //this.textQuantita.KeyPress.(new KeyPressEventHandler(this, CheckEnter));
                this.textCodiceBarre.Focus();
            }
            catch(Exception e)
            {

            }

        }

        private void codiceBarreEnter(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (e.KeyChar == '\r')
                {
                    if ((!this.textCodiceBarre.Focused ? false : this.textCodiceBarre.Text.Length > 0))
                    {
                        this.textQuantita.Focus();
                    }
                }
            }
            catch (Exception exception)
            {
                Exception ex = exception;
                MessageBox.Show(string.Concat("Errore: ", ex.Message));
            }
        }

        private void quantitaEnter(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (e.KeyChar == '\r')
                {
                    if ((!this.textQuantita.Focused ? false : this.textQuantita.Text.Length > 0))
                    {
                        this.salvaQuantita();
                    }
                }
            }
            catch (Exception exception)
            {
                Exception ex = exception;
                MessageBox.Show(string.Concat("Errore: ", ex.Message));
            }
        }

        private void salvaQuantita()
        {
            try
            {
                int numeroQuantita = int.Parse(this.textQuantita.Text);
                string nuovaStringa = string.Concat(this.textCodiceBarre.Text, " && ", numeroQuantita);
                this.sw.WriteLine(nuovaStringa);
                this.textCodiceBarre.Text = "";
                this.textQuantita.Text = "";
                this.textCodiceBarre.Focus();
            }
            catch (Exception exception)
            {
                Exception e = exception;
                MessageBox.Show(string.Concat("Errore: ", e.Message));
            }
        }

        private void buttonOrdine_Click(object sender, EventArgs e)
        {
            try
            {
                this.sw.Close();
                MessageBox.Show("Il file ESPORTAZIONE.txt è statp creato.", "Complimenti");
            }
            catch (Exception exception)
            {
                Exception ex = exception;
                MessageBox.Show(string.Concat("Errore: ", ex.Message));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Environment.Exit(0);
            }
            catch (Exception exception)
            {
                String process = Process.GetCurrentProcess().ProcessName;
                Process.Start("cmd.exe", "/c taskkill /F /IM " + process + ".exe /T");
                Exception ex = exception;
                MessageBox.Show(string.Concat("Errore: ", ex.Message));
            }
        }
    }
}

问题是什么 ?

标签: c#windows-ce

解决方案


看完评论后......

您使用的是 VS2017,但 Visual Studio 从 2010 版本开始,不支持 Windows Phone OS 7.0 之前的 Windows Phone 版本的移动应用程序> 开发。

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/sa69he4t(v=vs.100)

您可能正在创建一个普通的 Windows 应用程序并试图将其复制到 Windows CE,它不会那样工作

您需要使用 Visual Studio 2008

在那里,您将能够找到合适的模板来创建 Windows CE 项目...

现在这无关紧要,但请记住..

紧凑框架不支持 MessageBox 类,因为.Show(String...)它的重载

Show(IWin32Window, String, ...)

适用于

.NET Core 3.0 预览版 3

.NET 框架 4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox?view=netframework-4.7.2

您需要使用命名空间中的MessageWindowMicrosoft.WindowsCE.Forms


推荐阅读