【请问】如何实现没有窗体的.exe应用程序?不是Consol模式的!在线等待!谢谢!

hawkeyes_yq 2004-04-22 03:34:22
小弟现在有个棘手的问题,想请大家帮帮忙!
我希望实现一个应用程序,它运行起来,没有窗体(而不是将窗体隐藏),另外也不是Consol模式那种,有一个像Dos那样的控制台窗口。而我希望能够在这个应用运行时,通过调用一个类实例的某个方法来Show出一个窗体。也就是说,
static void Main()
{
//Application.Run(new DesignerMain());---->不显示窗体
OtherClass Myform = new OtherClass;
Myform.ShowForm(....);
}
大致是这个意思,现在我用Consol模式,但是会有控制台窗口在我要显示的Form后,不知道各位有何高见?
...全文
53 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangsaokui 2004-04-30
  • 打赏
  • 举报
回复
看你的目的是什么
Windows Service也可以
marvelstack 2004-04-29
  • 打赏
  • 举报
回复
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments,ProcessWindowStyle style)
{
bool blnRst = false;
Process p = new Process();
p.StartInfo.FileName = appName;//exe,bat and so on
p.StartInfo.WindowStyle = style;
p.StartInfo.Arguments = arguments;
try
{
p.Start();
p.WaitForExit();
p.Close();
blnRst = true;
}
catch
{
}
return blnRst;
}
jn_sly 2004-04-29
  • 打赏
  • 举报
回复
using System;
using System.Windows.Forms ;
using System.IO;

namespace ServerLoader
{
public class watch
{
public watch()
{

}
static void Main ( )
{
new watch();
  Application.Run () ;
}

}
}
marvelstack 2004-04-25
  • 打赏
  • 举报
回复
你把窗体隐藏就行了,下面是我自己经常用的代码,贴出来希望对楼主有所帮助。
/// <summary>
/// 显示隐藏窗口
/// </summary>
/// <param name="isShow"></param>
private void ShowHideWindow(bool isShow)
{
if(isShow)
{
if(this.ShowInTaskbar==false)
{
this.ShowInTaskbar = true;
this.Show();
this.WindowState = FormWindowState.Normal;
}
else
{
if(this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
}
this.Activate();
}
else
{
if(this.ShowInTaskbar == true)
{
this.Hide();
this.ShowInTaskbar = false;
}

}
}
DTWUJP 2004-04-24
  • 打赏
  • 举报
回复
你可以做成WINDOWS服务程序吗。
潜水员2099 2004-04-24
  • 打赏
  • 举报
回复

ProcessStartInfo psi = new ProcessStartInfo(osqlpath.ToString(), arguments);
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;//没有窗体
huguguhu 2004-04-24
  • 打赏
  • 举报
回复
可以动态创建一个,Form Form1=new Form();
huguguhu 2004-04-24
  • 打赏
  • 举报
回复
当然可以,using System;
using System.Net ;
using System.Net.Sockets;
using System.Text ;
using System.Threading;
using System.Windows.Forms;
using System.Web.Services;

public class StateObject
{
public Socket workSocket=null;
public const int BufferSize=1024;
public byte[] buffer=new byte[BufferSize];
public StringBuilder sb=new StringBuilder();
}

public class AsynchronousClient
{
//端口号
private const int port=26;
//ManualResetEvent完成信号
private static ManualResetEvent connectDone=new ManualResetEvent(false);
private static ManualResetEvent SendDone=new ManualResetEvent(false);
private static ManualResetEvent receiveDone=new ManualResetEvent(false);
private static ManualResetEvent SendDone1=new ManualResetEvent(false);
//从远方的接收
private static string response=string.Empty;
public static void StartClient()
{
try
{
//建立远程套接口
IPHostEntry ipHostInfo=Dns.Resolve ("fly-and-fly");
IPAddress ipAddress=ipHostInfo.AddressList[0];
IPEndPoint remoteEP=new IPEndPoint (ipAddress,port);
//创建tcp socket
Socket client=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
client.BeginConnect(remoteEP,new AsyncCallback(ConnectCallback),client);
connectDone.WaitOne();
//发送数据到服务端
// Send(client,"This is a test<EOF>");
Send(client,"This is a test");
Send(client,ipAddress.ToString());
SendDone.WaitOne();
//接收信息

Receive(client);
receiveDone.WaitOne();
Console.WriteLine("Response received :{0}",response);
client.Shutdown(SocketShutdown.Both);
client.Close();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
//异步连接中的回调
private static void ConnectCallback(IAsyncResult ar)
{
try
{
Socket client=(Socket) ar.AsyncState;
client.EndConnect(ar);
Console.WriteLine("Socket connected to {0}",client.RemoteEndPoint.ToString());
//发送连接成功信号
connectDone.Set();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
private static void Receive(Socket client)
{
int i;
try
{
StateObject state=new StateObject();
state.workSocket=client;
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,new AsyncCallback(ReceiveCallback),state);
for(i=0;i<state.buffer.Length;i++)
{
Console.WriteLine(state.sb.ToString());
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}

}
private static void ReceiveCallback(IAsyncResult ar)
{
int i;

try
{
StateObject state=(StateObject) ar.AsyncState;
Socket client=state.workSocket;
//读取数据
int bytesRead=client.EndReceive(ar);
if(bytesRead>0)
{
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
client.BeginReceive (state.buffer,0,StateObject.BufferSize,0,new AsyncCallback(ReceiveCallback),state);

}
else
{
if(state.sb.Length>1)
{
response=state.sb.ToString();
}
//发出所有信息接受完成信号
receiveDone.Set();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private static void Send(Socket client,string data)
{
byte[] byteData=Encoding.ASCII.GetBytes(data);
client.BeginSend(byteData,0,byteData.Length,0,new AsyncCallback(SendCallback),client);

}
private static void SendCallback(IAsyncResult ar)
{
try
{
Socket client=(Socket) ar.AsyncState;
int bytesSent=client.EndSend(ar);

Console.WriteLine("Sent {0} bytes to server.",bytesSent);
//发出数据已经发送信号
SendDone.Set();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static int Main(string[] args)
{

StartClient();
return 0;
}
}

hawkeyes_yq 2004-04-22
  • 打赏
  • 举报
回复
控制台程序会有控制台窗口啊
BearRui 2004-04-22
  • 打赏
  • 举报
回复
解决方案资源管理器——右键项目——属性。

在通用属性——常规——输出类型,选控制台应用程序

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧