- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
实际上,我的问题是一年前在这个主题中提出的 - Why do I see a console window when I run a dynamically compiled EXE?
现在我遇到了同样的问题,只是我没有使用命令行编译器,所以这个解决方案不适合我。
请帮忙。非常感谢!
编辑
这是代码。它主要取自此处的 Microsoft 支持 http://support.microsoft.com/kb/304655/en-us .
既然是动态编译,我不知道从哪里传递我不需要控制台显示的概念。
抱歉,它太大了,因为字符串源是我的整个其他类。
using System.Windows.Forms;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System;
using System.Drawing;
using System.IO;
namespace compile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
string Output = "Out.exe";
Button ButtonObject = (Button)sender;
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
//Make sure we generate an EXE, not a DLL
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
parameters.ReferencedAssemblies.Add("System.dll");
parameters.ReferencedAssemblies.Add("System.Drawing.Dll");
parameters.ReferencedAssemblies.Add("System.Windows.Forms.Dll");
////////////////////////////////////////////////////////////////////////////////////
string text = @"using System;
using System.Windows.Forms;
using System.Drawing;
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
partial class TestForm
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
//System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
this.MainLabel = new System.Windows.Forms.Label();
this.MainLabel2 = new System.Windows.Forms.Label();
this.BackBtn = new System.Windows.Forms.Button();
this.NextBtn = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.elementPanel = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.elementPanel.SuspendLayout();
this.SuspendLayout();
//
// MainLabel
//
this.MainLabel.AutoSize = true;
this.MainLabel.Font = new System.Drawing.Font(""Microsoft Sans Serif"", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.MainLabel.Location = new System.Drawing.Point(10, 9);
this.MainLabel.Name = ""MainLabel"";
this.MainLabel.Size = new System.Drawing.Size(126, 18);
this.MainLabel.TabIndex = 0;
this.MainLabel.Text = ""Вопросы теста"";
//
// MainLabel2
//
this.MainLabel2.AutoSize = true;
this.MainLabel2.Font = new System.Drawing.Font(""Microsoft Sans Serif"", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.MainLabel2.Location = new System.Drawing.Point(10, 38);
this.MainLabel2.Name = ""MainLabel2"";
this.MainLabel2.Size = new System.Drawing.Size(479, 16);
this.MainLabel2.TabIndex = 1;
this.MainLabel2.Text = ""Выберите правильные ответы на вопросы из предложенных вариантов."";
//
// BackBtn
//
this.BackBtn.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Right)));
this.BackBtn.Font = new System.Drawing.Font(""Microsoft Sans Serif"",
9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.BackBtn.Location = new System.Drawing.Point(447, 401);
this.BackBtn.Name = ""BackBtn"";
this.BackBtn.Size = new System.Drawing.Size(88, 26);
this.BackBtn.TabIndex = 3;
this.BackBtn.Text = ""Назад"";
this.BackBtn.UseVisualStyleBackColor = true;
//
// NextBtn
//
this.NextBtn.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Right)));
this.NextBtn.Font = new System.Drawing.Font(""Microsoft Sans Serif"",
9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.NextBtn.Location = new System.Drawing.Point(541, 401);
this.NextBtn.Name = ""NextBtn"";
this.NextBtn.Size = new System.Drawing.Size(88, 26);
this.NextBtn.TabIndex = 4;
this.NextBtn.Text = ""Вперед"";
this.NextBtn.UseVisualStyleBackColor = true;
//
// groupBox1
//
this.groupBox1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
|
System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.elementPanel);
this.groupBox1.Controls.Add(this.MainLabel2);
this.groupBox1.Controls.Add(this.NextBtn);
this.groupBox1.Controls.Add(this.MainLabel);
this.groupBox1.Controls.Add(this.BackBtn);
this.groupBox1.Location = new System.Drawing.Point(2, 0);
this.groupBox1.Name = ""groupBox1"";
this.groupBox1.Size = new System.Drawing.Size(635, 433);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
//
// elementPanel
//
this.elementPanel.Anchor =
((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
|
System.Windows.Forms.AnchorStyles.Right)));
this.elementPanel.AutoScroll = true;
this.elementPanel.Controls.Add(this.label1);
this.elementPanel.Location = new System.Drawing.Point(6, 57);
this.elementPanel.Name = ""elementPanel"";
this.elementPanel.Size = new System.Drawing.Size(624, 338);
this.elementPanel.TabIndex = 5;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font(""Microsoft Sans Serif"",
9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.label1.Location = new System.Drawing.Point(4, 11);
this.label1.MaximumSize = new System.Drawing.Size(610, 0);
this.label1.Name = ""label1"";
this.label1.Size = new System.Drawing.Size(601, 30);
this.label1.TabIndex = 0;
this.label1.Text =
""mmmmmmmmmmmm\r\n"";
//
// TestForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(638, 433);
this.Controls.Add(this.groupBox1);
//this.Icon = ((System.Drawing.Icon)(resources.GetObject(""$this.Icon"")));
this.Name = ""TestForm"";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = ""Тест на знание английского языка"";
this.Load += new System.EventHandler(this.TestForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.elementPanel.ResumeLayout(false);
this.elementPanel.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label MainLabel;
private System.Windows.Forms.Label MainLabel2;
private System.Windows.Forms.Button BackBtn;
private System.Windows.Forms.Button NextBtn;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Panel elementPanel;
private System.Windows.Forms.Label label1;
}
public partial class TestForm : Form
{
public TestForm()
{
InitializeComponent();
}
private void TestForm_Load(object sender, EventArgs e)
{
BackBtn.Enabled = false;
this.MouseWheel += new MouseEventHandler(TestForm_MouseWheel);
int loc = 24 + label1.Height;
for (int i = 0; i < 20; i++)
{
RadioButton newR = new RadioButton();
newR.Text = ""test"";
newR.AutoSize = true;
newR.Location = new Point(4, loc);
loc += 24;
elementPanel.Controls.Add(newR);
}
}
void TestForm_MouseWheel(object sender, MouseEventArgs e)
{
elementPanel.Focus();
}
}
";
////////////////////////////////////////////////////////////////////////////////////
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, text);
if (results.Errors.Count > 0)
{
foreach (CompilerError CompErr in results.Errors)
{
textBox2.Text = textBox2.Text +
"Line number " + CompErr.Line +
", Error Number: " + CompErr.ErrorNumber +
", '" + CompErr.ErrorText + ";" +
Environment.NewLine + Environment.NewLine;
}
}
else
{
//Successful Compile
textBox2.ForeColor = Color.Blue;
textBox2.Text = "Success!";
Process.Start(Output);
}
}
}
}
最佳答案
添加 > paramters.CompilerOptions/t:winexe 似乎对我有用:
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
string output = "Out.exe";
var parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = output;
parameters.ReferencedAssemblies.Add("System.dll");
parameters.ReferencedAssemblies.Add("System.Drawing.Dll");
parameters.ReferencedAssemblies.Add("System.Windows.Forms.Dll");
parameters.CompilerOptions = "/t:winexe";
var results = codeProvider.CompileAssemblyFromSource(parameters, "namespace Bah { static class Program { static void Main() { System.Threading.Thread.Sleep(100000); } } }");
但我还添加了这个(为了更好的衡量):
var psi = new ProcessStartInfo(output) {CreateNoWindow = true};
Process.Start(output);
在没有/t:winexe 的情况下,我得到了一个命令窗口,如果按您的方式完成,它会显示,如果添加了 ProcessStartInfo,它会闪烁。使用/t:winexe 选项,窗口消失了,但我也将 ProcessStartInfo 设置为 NoWindow。
我想强调的是,编译这样的表格真的很僵化和脆弱,而且似乎没有任何理由去做。当我处理 CodeDom 时,我们编译了动态用户输入,表示用户创建的计算和公式。它很难管理,而且对于大型包裹来说速度很慢。嵌入式脚本引擎本来是更好的选择,但没有经济高效的方法来将其删除并替换它,因此我们在技术上致力于这种方法
关于c# - 如何在动态编译 Windows 应用程序时隐藏控制台窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5177446/
https://github.com/mattdiamond/Recorderjs/blob/master/recorder.js中的代码 我不明白 JavaScript 语法,比如 (functio
在 iOS 7 及更早版本中,如果我们想在应用程序中找到 topMostWindow,我们通常使用以下代码行 [[[UIApplication sharedApplication] windows]
我已经尝试解决这个问题很长一段时间了:我无法访问窗口的 url,因为它位于另一个域上..有一些解决方案吗? function login() { var cb = window.ope
是否可以将 FFMPEG 视频流传递到 C# 窗口?现在它在新窗口中作为新进程打开,我只是想将它传递给我自己的 SessionWindow。 此时我像这样执行ffplay: public void E
我有一个名为 x 的矩阵看起来像这样: pTime Close 1 1275087600 1.2268 2 1275264000 1.2264 3 1275264300 1.2
在编译时,发生搜索,grep搜索等,Emacs会在单独的窗口中创建一个新的缓冲区来显示结果,有没有自动跳转到那个窗口的方法?这很有用,因为我可以使用 n 和 p 而不是 M-g n 和 M-g p 移
我有一个启动 PowerShell 脚本的批处理文件。 批处理文件: START Powershell -executionpolicy RemoteSigned -noexit -file "MyS
我有一个基于菜单栏的应用程序,单击图标时会显示一个窗口。在 Mac OS X Lion 上一切正常,但由于某种原因,在 Snow Leopard 和早期版本的 Mac OS X 上会出现错误。任何时候
在 macOS 中,如何在 Xcode 和/或 Interface Builder 中创建带有“集成标题栏和工具栏”的窗口? 这是“宽标题栏”类型的窗口,已添加到 OS X 10.10 Yosemit
在浏览器 (Chrome) 中 JavaScript: var DataModler = { Data: { Something: 'value' }, Process: functi
我有 3 个 html 页面。第 1 页链接到第 2 页,第 2 页链接到第 3 页(为了简单起见)。 我希望页面 2 中的链接打开页面 3 并关闭页面 1(选项卡 1)。 据我了解,您无法使用 Ja
当点击“创建节点”按钮时,如何打开一个新的框架或窗口?我希望新框架包含一个文本字段和下拉菜单,以便用户可以选择一个选项。 Create node Search node
我有一个用户控件,用于编辑应用程序中的某些对象。 我最近遇到一个实例,我想弹出一个新的对话框(窗口)来托管此用户控件。 如何实例化新窗口并将需要设置的任何属性从窗口传递到用户控件? 感谢您的宝贵时间。
我有一个Observable,它发出许多对象,我想使用window或buffer操作对这些对象进行分组。但是,我不想指定count参数来确定窗口中应包含多少个对象,而是希望能够使用自定义条件。 例如,
我有以下代码,它打开一个新的 JavaFX 阶段(我们称之为窗口)。 openAlertBox.setOnAction(e -> { AlertBox alert = AlertBox
我要添加一个“在新窗口中打开”上下文菜单项,该菜单项将以新的UIScene打开我的应用程序文档之一。当然,我只想在实际上支持多个场景的设备上显示该菜单项。 目前,我只是在检查设备是否是使用旧设备的iP
我正在尝试创建一个 AIR 应用程序来记录应用程序的使用情况,使用 AIR 从系统获取信息的唯一简单方法是使用命令行工具和抓取 标准输出 . 我知道像 这样的工具顶部 和 ps 对于 OS X,但它们
所以我有这个简单的 turtle 螺旋制作器,我想知道是否有一种方法可以打印出由该程序创建的我的设计副本。 代码: import turtle x= float(input("Angle: ")) y
我正在编写一个 C# WPF 程序,它将文本消息发送到另一个程序的窗口。我有一个宏程序作为我的键盘驱动程序 (Logitech g15) 的一部分,它已经这样做了,尽管它不会将击键直接发送到进程,而是
我尝试使用以下代码通过 UDP 发送,但得到了奇怪的结果。 if((sendto(newSocket, sendBuf, totalLength, 0, (SOCKADDR *)&sendAd
我是一名优秀的程序员,十分优秀!