c# - 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));
}
}
}
}
问题是什么 ?
解决方案
看完评论后......
您使用的是 VS2017,但 Visual Studio 从 2010 版本开始,不支持 Windows Phone OS 7.0 之前的 Windows Phone 版本的移动应用程序> 开发。
您可能正在创建一个普通的 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
您需要使用命名空间中的MessageWindow
类Microsoft.WindowsCE.Forms
推荐阅读
- batch-file - 随机数生成器在批处理文件中不是随机的
- export - 如果行相同,OpenRefine 会覆盖数据库中的唯一 ID
- angular - 在 Angular 中设置与默认值不同的 queryParams
- css - 覆盖 Vuetify Icon 组件
- javascript - `nuxt-axios` 自定义插件的标头
- java - 查找并打印 x1+x2+x3=num 的解数
- email - 表格仍然是设计电子邮件模板的首选方法吗?
- sql - T-SQL - 员工年平均
- javascript - 如何存储和返回来自 HTTP 响应的数据?
- java - 在 Spring 中测试 RestController 时 HttpServletRequest 为空