如何在图形界面下编写类似cmd.exe的用户交互界面,给个思路就好了 也可以使用下拉菜单啊也可以将两个TextBox叠加在一起哦,让感官上象是一个多行的TextBox 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以前用VC做过类似的事只用一个Textbox,把每行字符放在一个字符数组中,在控件的重画事件中,都重新赋值,就能解决只读问题。速度不慢,用户感觉不到。至于获得当前字符,记得是用GetWindowText()之类的函数。C#我是想一样的道理。 用textBox实现是很困难的(同时显示全部的内容)是否可以这样呢当一个命令输入完的时候,将它读出到设定的变量并清空这样的话,每次在它里头就只有一个命令了 问题是TextBox中的字符是用户输入的,GetWindowText函数只能获得整个TextBox的文本,可是其中还有以前的命令和命令结果阿。我就是不知道如何在文本框中取得最后一行的内容至于khpcg说的,与程序设计的本意不同,所以行不通阿 你用treewiew啊,这个也是不错的嘛 to werdcd: treeview好像不行把,用来作regedit挺合适的,可是不好作交互界面吧,首先不能接受输入to ffb: 能不能稍微详细一点的说,怎么新建控制台工程,windows窗体界面中可以添加终端控制台工程吗? 我有一个想法是这样的:你做一个缓冲区(可以考虑用堆栈来实现),然后用户的每次输入都进缓冲区。直到用户确认输入时候,把这些词语显示或者处理。显示的时候用gdi+的drawstring绘制(当然要留一块box上动态更新你的输入了,这个用gdi+是可以处理的。)也就是说你先用gid+画一块box出来,然后根据你的字体大小计算文字开始绘制的位置(x,y)然后等待用户输入,开一个缓冲区接受用户输入,并启一个背景线程动态更新你的gid+当前显示字符。当用户敲入回车时,获取所有输入,清缓存。并将gdi+的文字更新,修改光标位置...不知道我说明白没有,不好意思,表达能力不强,呵呵。另外,gid+处理这些已经比较简单了。 我的想法:用两个text,一个用来显示输出结果另一个用来输入命令[用一个实现这个需求,确实麻烦] to: noeye 怎样使用缓冲区,使的用户的每次输入都进缓冲区呢,不好意思我比较菜,能不能给个实例程序呢?谢谢啦。to:kissmett 谢谢,你的想法yuyeniao已经提过了 form部分:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace T01{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { public System.Windows.Forms.Button button1; public System.Windows.Forms.Button button2; public System.Windows.Forms.Button button3; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(24, 32); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "Continue"; // // button2 // this.button2.Location = new System.Drawing.Point(120, 32); this.button2.Name = "button2"; this.button2.TabIndex = 1; this.button2.Text = "Stop"; // // button3 // this.button3.Location = new System.Drawing.Point(24, 72); this.button3.Name = "button3"; this.button3.TabIndex = 2; this.button3.Text = "Exit"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion }} command部分:using System;using System.Threading;using System.IO;using System.Windows.Forms;namespace T01{ /// <summary> /// Class1 的摘要说明。 /// </summary> class Class1 { static ThreadStart RunThread; static Thread First; static bool RunOrNot; static ManualResetEvent mainUse; /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // RunOrNot = false; mainUse = new ManualResetEvent(false); RunThread = new ThreadStart(OPenWinForm); First = new Thread(RunThread); First.Name = "TestThread"; First.Start(); while (true) { if (!RunOrNot) { mainUse.WaitOne(); } Console.WriteLine("开始输出数据!"); } } static void OPenWinForm() { Form1 th = new Form1(); th.button1.Click += new EventHandler(button1_Click); th.button2.Click += new EventHandler(button2_Click); th.button3.Click += new EventHandler(button3_Click); Application.Run(th); } private static void button1_Click(object sender, EventArgs e) { RunOrNot = true; mainUse.Set(); } private static void button2_Click(object sender, EventArgs e) { RunOrNot = false; mainUse.Reset(); } private static void button3_Click(object sender, EventArgs e) { Application.ExitThread(); First.Abort(); mainUse.Close(); } }}这是我调试thread时的一个小程式,希望对你有用。 请问如何把xml1.0不支持的unicode字符替换为空格 js for 循环 判断 这个C#小程序的输出为什么是这样? 两种程序的整合 在手机上开发类似MSN的应用程序,选择c#还是MFC? 如何用C#编写一个可以被ASP调用的COM组件? 哪位好心人能提供C/S结构Socket的二次封装的类或资料 谁有版本比较高的MagicLibrary啊? 关于类似QQ功能的程序? 各位大侠帮忙,为什么我的登陆界面上左边的论坛选择没有出现?只有默认的C# 如何使得Hashtable对象的value是一个集合呢? 求控件
只用一个Textbox,
把每行字符放在一个字符数组中,在控件的重画事件中,都重新赋值,就能解决只读问题。
速度不慢,用户感觉不到。
至于获得当前字符,记得是用GetWindowText()之类的函数。
C#我是想一样的道理。
是否可以这样呢
当一个命令输入完的时候,将它读出到设定的变量并清空
这样的话,每次在它里头就只有一个命令了
我就是不知道如何在文本框中取得最后一行的内容至于khpcg说的,与程序设计的本意不同,所以行不通阿
to ffb: 能不能稍微详细一点的说,怎么新建控制台工程,windows窗体界面中可以添加终端控制台工程吗?
你做一个缓冲区(可以考虑用堆栈来实现),然后用户的每次输入都进缓冲区。
直到用户确认输入时候,把这些词语显示或者处理。
显示的时候用gdi+的drawstring绘制(当然要留一块box上动态更新你的输入了,这个用gdi+是可以处理的。)也就是说你先用gid+画一块box出来,然后根据你的字体大小计算文字开始绘制的位置(x,y)然后等待用户输入,开一个缓冲区接受用户输入,并启一个背景线程动态更新你的gid+当前显示字符。当用户敲入回车时,获取所有输入,清缓存。并将gdi+的文字更新,修改光标位置...
不知道我说明白没有,不好意思,表达能力不强,呵呵。另外,gid+处理这些已经比较简单了。
用两个text,
一个用来显示输出结果
另一个用来输入命令
[用一个实现这个需求,确实麻烦]
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace T01
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.Button button1;
public System.Windows.Forms.Button button2;
public System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Continue";
//
// button2
//
this.button2.Location = new System.Drawing.Point(120, 32);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "Stop";
//
// button3
//
this.button3.Location = new System.Drawing.Point(24, 72);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "Exit";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion }
}
command部分:
using System;
using System.Threading;
using System.IO;
using System.Windows.Forms;namespace T01
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
static ThreadStart RunThread;
static Thread First;
static bool RunOrNot;
static ManualResetEvent mainUse;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
// RunOrNot = false; mainUse = new ManualResetEvent(false); RunThread = new ThreadStart(OPenWinForm); First = new Thread(RunThread); First.Name = "TestThread"; First.Start(); while (true)
{
if (!RunOrNot)
{
mainUse.WaitOne();
}
Console.WriteLine("开始输出数据!");
}
}
static void OPenWinForm()
{
Form1 th = new Form1();
th.button1.Click += new EventHandler(button1_Click);
th.button2.Click += new EventHandler(button2_Click);
th.button3.Click += new EventHandler(button3_Click);
Application.Run(th);
} private static void button1_Click(object sender, EventArgs e)
{
RunOrNot = true;
mainUse.Set();
} private static void button2_Click(object sender, EventArgs e)
{
RunOrNot = false;
mainUse.Reset();
} private static void button3_Click(object sender, EventArgs e)
{
Application.ExitThread();
First.Abort();
mainUse.Close();
}
}
}
这是我调试thread时的一个小程式,希望对你有用。