将Windows窗体与控制台应用程序一起使用 [英] Using Windows Forms with Console Application
问题描述
大家好,
我已经弄清楚了如何制作我的编程语言并使之适用于Windows窗体和控制台应用程序(我只是在项目中添加了Windows窗体和少量代码),但是问题是,当您单击调试时按钮并键入新表格"(仅用于测试目的),它会生成一个新表格并显示它,但是当您将鼠标悬停在它上面时,它就会有加载圆圈,您可以不能做任何事情.我该如何解决?
代码:
控制台应用程序
hey guys,
i have figured out how to make my programming language and make it work for both windows forms and console application programs(i just added a windows forms to my project and a little bit of code), but the problem is, when you click the debug button and type in ''new form''(it''s just for testing purposes) it makes a new form and it shows it, but when you hover your mouse over it, it just has the loading circle and you can''t do anything with it. how do i fix this?
code:
Console Application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
Console.WriteLine(" ");
begin:
string code = Console.ReadLine();
if (code == "new form")
{
Form1 form = new Form1();
form.Activate();
form.Show();
form.Enabled = true;
form.Focus();
form.Visible = true;
goto begin;
}
}
}
}
Windows窗体
Windows Forms
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
请帮助
please help
推荐答案
hiii,
使用以下代码
hiii,
use following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication3
{
class Program : System.Windows.Forms.Form
{
static void Main(string[] args)
{
Console.WriteLine("hello");
Console.WriteLine(" ");
begin:
string code = Console.ReadLine();
if (code == "new form")
{
//Form form = new Form();
//form.Activate();
//form.Show();
//form.Enabled = true;
//form.Focus();
//form.Visible = true;
Application.EnableVisualStyles();
Application.Run(new Program());
goto begin;
}
}
private void InitializeComponent() // DESIGNER WILL ADD THIS FUNCTION
{
this.SuspendLayout();
this.ClientSize = new System.Drawing.Size(367, 188);
this.Name = "Program";
this.ResumeLayout(false);
}
}
}
还添加了两个引用
1)system.windows.forms
2)system.drawing
also add two references
1) system.windows.forms
2) system.drawing
这篇关于将Windows窗体与控制台应用程序一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!