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;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Net.Sockets;namespace RemoteControl
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void niInfo_MouseClick(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Right)
Menu.Show(Cursor.Position);
} private void Main_Load(object sender, EventArgs e)
{
StartListener();
}
private void StartListener()
{
TcpListener listener;
try
{
listener = new TcpListener(60000);
}
catch
{
Console.WriteLine("Falt to Creat Listener Port");
return;
}
listener.Start();
bool loop = true;
while (loop)
{
Socket s = listener.AcceptSocket();
NetworkStream ns = new NetworkStream(s);
StreamReader r = new StreamReader(ns);
string command = r.ReadLine();
StreamWriter sw = new StreamWriter(command);
sw.WriteLine();
s.Close();
}
} private void Exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}这里ContextMenuStrip菜单的鼠标右击事件没有动作.谢谢!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Net.Sockets;namespace RemoteControl
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void niInfo_MouseClick(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Right)
Menu.Show(Cursor.Position);
} private void Main_Load(object sender, EventArgs e)
{
StartListener();
}
private void StartListener()
{
TcpListener listener;
try
{
listener = new TcpListener(60000);
}
catch
{
Console.WriteLine("Falt to Creat Listener Port");
return;
}
listener.Start();
bool loop = true;
while (loop)
{
Socket s = listener.AcceptSocket();
NetworkStream ns = new NetworkStream(s);
StreamReader r = new StreamReader(ns);
string command = r.ReadLine();
StreamWriter sw = new StreamWriter(command);
sw.WriteLine();
s.Close();
}
} private void Exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}这里ContextMenuStrip菜单的鼠标右击事件没有动作.谢谢!
解决方案 »
- C# ZipOutputStream 压缩时加密 没有Password
- C#中怎样构建模MySql的传参数模糊查询语句啊,老提示语法不对!急
- C#打印问题。
- 新手求助-关于VS2005 连接数据库和查询的问题
- 如何把 '2005-05-01' 这个字符串转成 'May.1,2005'
- *.ocx 控件重新封装后,如何在打包时不把原来的*.ocx控件打进去.
- 这个问题问了好多人了,都不见解决...(跟贴者有分)
- 为什么我的C#不能新建一个项目?
- 基类和派生类一定要在同一个cs文件里面么,是不是在同一个名字空间下面就可以了啊?
- 为什么C#在菜单编辑器里没有加入图标功能?
- C# 判断数组元素都为X的方法
- C#线程创建时参数怎么传入,线程创建完成可以返回参数吗
是什么打断点查
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.niInfo = new System.Windows.Forms.NotifyIcon(this.components);
this.Stop = new System.Windows.Forms.ToolStripMenuItem();
this.Restart = new System.Windows.Forms.ToolStripMenuItem();
this.Exit = new System.Windows.Forms.ToolStripMenuItem();
this.Menu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.Menu.SuspendLayout();
this.SuspendLayout();
//
// niInfo
//
this.niInfo.ContextMenuStrip = this.Menu;
this.niInfo.Icon = ((System.Drawing.Icon)(resources.GetObject("niInfo.Icon")));
this.niInfo.Text = "notifyIcon1";
this.niInfo.Visible = true;
//
// Stop
//
this.Stop.Name = "Stop";
this.Stop.Size = new System.Drawing.Size(152, 22);
this.Stop.Text = "停止";
//
// Restart
//
this.Restart.Name = "Restart";
this.Restart.Size = new System.Drawing.Size(152, 22);
this.Restart.Text = "重启";
//
// Exit
//
this.Exit.Name = "Exit";
this.Exit.Size = new System.Drawing.Size(152, 22);
this.Exit.Text = "退出";
this.Exit.Click += new System.EventHandler(this.Exit_Click);
//
// Menu
//
this.Menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.Stop,
this.Restart,
this.Exit});
this.Menu.Name = "Menu";
this.Menu.Size = new System.Drawing.Size(153, 92);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(305, 254);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Main";
this.Load += new System.EventHandler(this.Form1_Load);
this.VisibleChanged += new System.EventHandler(this.Form1_VisibleChanged);
this.Menu.ResumeLayout(false);
this.ResumeLayout(false); } #endregion private System.Windows.Forms.NotifyIcon niInfo;
private System.Windows.Forms.ContextMenuStrip Menu;
private System.Windows.Forms.ToolStripMenuItem Stop;
private System.Windows.Forms.ToolStripMenuItem Restart;
private System.Windows.Forms.ToolStripMenuItem Exit;
}
}我试过了注释掉Main_Load事件里的StartListener()方法就没有问题.
{
StartListener();
}
private void StartListener()
{
TcpListener listener;
try
{
listener = new TcpListener(60000);
}
catch
{
Console.WriteLine("Falt to Creat Listener Port");
return;
}
listener.Start();
bool loop = true;
while (loop)
{
Socket s = listener.AcceptSocket();
NetworkStream ns = new NetworkStream(s);
StreamReader r = new StreamReader(ns);
string command = r.ReadLine();
StreamWriter sw = new StreamWriter(command);
sw.WriteLine();
s.Close();
}
} while (loop)
你的窗体一启动就进入了死循环。。窗体一直在做事~!!!你给这个StartListener()加一个线程吧。 private void Main_Load(object sender, EventArgs e)
{
System.Threading.Thread thread = new System.Threading.Thread(StartListener);
thread.IsBackground = true;
thread.Start();
}