//注意在工程上添加系統引用System.Drawing 否則System點不出Drawing來。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
namespace TaskBarFloatWnd
{
public partial class Form1 : Office2007Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TaskBarWnd taskWnd = new TaskBarWnd();
System.Drawing.Rectangle r = System.Windows.Forms.Screen.GetWorkingArea(taskWnd);
taskWnd.Location = new System.Drawing.Point(r.Right - taskWnd.Width, r.Bottom - taskWnd.Height);
taskWnd.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace TaskBarFloatWnd


{
public partial class TaskBarWnd : Office2007Form

{
public TaskBarWnd()

{
InitializeComponent();
actform = GetActiveWindow();
}
private bool isFristShow = true;//標識是否是首次加載
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetActiveWindow();//獲得當前活動窗體
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr SetActiveWindow(IntPtr hwnd);//設置活動窗體

private IntPtr actform = IntPtr.Zero;//保存自己得到焦點前擁有活動窗體的柄
private void TaskBarWnd_Load(object sender, EventArgs e)

{
textBox1.Text = DateTime.Now + "——";
textBox1.Text = textBox1.Text + "目前正對網元1進行做單操作,10分鐘內請大家避讓";

}
protected override void OnActivated(EventArgs e)

{
base.OnActivated(e);
if (isFristShow == true)

{
SetActiveWindow(actform);
isFristShow = false;
}
}


private void TaskBarWnd_FormClosing(object sender, FormClosingEventArgs e)

{
}
}
}
posted @
2010-02-26 16:14 天書 閱讀(2865) |
評論 (1) |
編輯 收藏
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Net.Sockets;
using System.Net;

namespace SocketConnTimeOut


{
class TimeOutSocket

{
private static bool IsConnectionSuccessful = false;
private static Exception socketexception;
private static ManualResetEvent TimeoutObject = new ManualResetEvent(false);

public static TcpClient Connect(IPEndPoint remoteEndPoint, int timeoutMSec)

{
TimeoutObject.Reset();
socketexception = null;

string serverip = Convert.ToString(remoteEndPoint.Address);
int serverport = remoteEndPoint.Port;
TcpClient tcpclient = new TcpClient();

tcpclient.BeginConnect(serverip, serverport, new AsyncCallback(CallBackMethod), tcpclient);

if (TimeoutObject.WaitOne(timeoutMSec, false))

{
if (IsConnectionSuccessful)

{

return tcpclient;
}
else

{
throw socketexception;
}
}
else

{
tcpclient.Close();
throw new TimeoutException("TimeOut Exception");
}
}
private static void CallBackMethod(IAsyncResult asyncresult)

{
try

{
IsConnectionSuccessful = false;
TcpClient tcpclient = asyncresult.AsyncState as TcpClient;

if (tcpclient.Client != null)

{
tcpclient.EndConnect(asyncresult);
IsConnectionSuccessful = true;
}
}
catch (Exception ex)

{
IsConnectionSuccessful = false;
socketexception = ex;
}
finally

{
TimeoutObject.Set();
}
}

}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.IO;
using System.Windows.Forms;
namespace SocketConnTimeOut
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
string strIP = "";
int strPort = 8000;
int timeout = 1000;
private void btnConn_Click(object sender, EventArgs e)
{
try
{
strIP = txtIP.Text;
strPort = Convert.ToInt32(txtPort.Text);
IPAddress localAddr = IPAddress.Parse(strIP);
IPEndPoint remoteEndPoint = new IPEndPoint(localAddr, strPort);
TcpClient NetworkClient = TimeOutSocket.Connect(remoteEndPoint, timeout);
}
catch (Exception ex)
{
MessageBox.Show("連接失敗");
}
}
}
}
posted @
2010-02-25 14:57 天書 閱讀(5697) |
評論 (1) |
編輯 收藏
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
namespace PingIpAddress
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private Ping pingSender = new Ping();
private string strIP = "";
private void button1_Click(object sender, EventArgs e)
{
strIP = txtIP.Text;
PingOptions pingOption = new PingOptions();
pingOption.DontFragment = true;
string data = "sendData:goodgoodgoodgoodgoodgood";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(strIP, timeout, buffer);
if (reply.Status == IPStatus.Success)
{
MessageBox.Show("能ping通 ");
}
else
{
MessageBox.Show("ping不通");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using OSSDOM.CMT.ConfigData;
using System.Net;
using System.Net.NetworkInformation;

namespace OSSDOM.CMT.CommonUse


{
public class PingServer

{
private IPEndPoint EPServer = null;
public PingServer()

{
try

{
EPServer = new IPEndPoint(IPAddress.Parse(MakeOptionDatas.MakeOptionDataInstance.proxy.strProxyIP), int.Parse(MakeOptionDatas.MakeOptionDataInstance.proxy.strProxyPort));
}
catch (Exception ex)

{
MessageBox.Show(ex.Message + " " + ex.StackTrace);
}
}
//連接
private Ping pingSender = new Ping();
public bool ServerConnected()

{
try

{
PingOptions pingOption = new PingOptions();
pingOption.DontFragment = true;

string data = "sendData";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(EPServer.Address, timeout, buffer);
if (reply.Status == IPStatus.Success)

{
//MessageBox.Show("能ping通 ");
return true;
}
else

{
//MessageBox.Show("ping不通");
return false;
}
}
catch

{
return false;
}
}
//斷開
public void Disconnect()

{
}
}
}

posted @
2010-02-25 14:47 天書 閱讀(2126) |
評論 (0) |
編輯 收藏
摘要: private void MQRecieve() //MQ接收函數 { try &nbs...
閱讀全文
posted @
2010-02-08 09:04 天書 閱讀(573) |
評論 (0) |
編輯 收藏
using System.Text.RegularExpressions;
private bool isContainCh(string s)

{
Regex r4 = new Regex(@"^[\u4e00-\u9fa5]+$");
int len = s.Length;
for (int i = 0; i < len - 1; i++)

{
string str = s.Substring(i, 1);
if (r4.IsMatch(str))

{
return true;
}
}
return false;
}
posted @
2010-01-12 09:29 天書 閱讀(458) |
評論 (0) |
編輯 收藏
首先:服務端要發四個字節過來,代表接下來他發了多少數據過來,然后每次客戶端就讀這個長度的數據即可。這樣收發就同步了哈哈!
然后:客戶端就按照這個長度來讀服務端一次發過來的信息。
還要解決一個問題就是 socket接收信息由字節轉換成整型:
Byte[] RecNum = new byte[4];
int iRevNum = netstream.Read(RecNum, 0, RecNum.Length);//讀取客戶發送來的字節信息。
int i = BitConverter.ToInt32(RecNum, 0);
i = System.Net.IPAddress.NetworkToHostOrder(i);
接下來就按i這么大來讀信息就能同步了。具體代碼見下:(網元監控中使用)
private void Read()
{
try
{
Byte[] Recp = new byte[1024];
if (ClientSocket == null)
{
return;
}
NetworkStream netstream = new NetworkStream(ClientSocket);
int iRevp = netstream.Read(Recp, 0, Recp.Length);//讀取客戶發送來的信息。
string strRevp = System.Text.Encoding.GetEncoding("gb2312").GetString(Recp, 0, iRevp);
if (strRevp.IndexOf("請輸入指令") != -1)
{
string sendMsg = "";
if (curPort.Equals("ALL"))
{
sendMsg = "track " + curNet.NeENName + "\r\n";
}
else
{
sendMsg = "track " + curNet.NeENName + "#" + curPort + "\r\n";
}
DispatchMessage(sendMsg);
}
while (true)
{
try
{
Byte[] RecNum = new byte[4];
int iRevNum = netstream.Read(RecNum, 0, RecNum.Length);//讀取客戶發送來的字節信息。
int i = BitConverter.ToInt32(RecNum, 0);
i = System.Net.IPAddress.NetworkToHostOrder(i);
Byte[] Rec = new byte[i];
int iRev = netstream.Read(Rec, 0, Rec.Length);//讀取客戶發送來的信息。
string strRev = System.Text.Encoding.GetEncoding("gb2312").GetString(Rec, 0, iRev);
strRev = strRev.Replace("\0", "");
ProcessReceiveData(strRev);
}
catch (Exception ex)
{
;
}
Thread.Sleep(1000);
}
}
catch (Exception ex)
{
;
}
}
posted @
2010-01-07 11:34 天書 閱讀(947) |
評論 (0) |
編輯 收藏
跨線程時 一定要用System.Timer,而不要用System.windows.Forms.Timer.
Timer 控件到點時,一定要先stop然后做其他工作,最后再messageBox.show() ;否則messageBox.show() 將線程阻塞在那塊等待用戶操作了,要是用戶不在沒有操作,則不能stop()。
posted @
2010-01-07 10:04 天書 閱讀(597) |
評論 (0) |
編輯 收藏
1:網線或者網絡的事,比如IP被占用,網線不好用。
查找方法: ping一下網關。
2:接收數據中有"\0",把后面數據截斷了。
解決辦法: string.replace("\0","")。
posted @
2010-01-07 10:03 天書 閱讀(1244) |
評論 (0) |
編輯 收藏
colorFont.myFont.fontStyle :int 類型(存在數據庫中讀出來的)
FontStyle fs = (FontStyle)colorFont.myFont.fontStyle;
Font ft = new Font(colorFont.myFont.fontName, colorFont.myFont.fontSize,fs);
int ifontStyle = (int)ft.fontStyle;
posted @
2009-11-09 20:09 天書 閱讀(284) |
評論 (0) |
編輯 收藏
1:添加—新建項目—其它項目類型—安裝和部署—安裝項目
2:在視圖—文件系統中,按照源程序bin目錄下的結構,構建文件夾及文件(文件夾中套n多文件夾的可以同時開著兩個,拖進去,不用一層一層建太麻煩了)
3:屬性-系統必備里-.NETFrameWork2.0打上對勾
4:視圖—文件系統—用戶桌面添加上快捷方式,右鍵添加,同時屬性中的alwayscreate 設為true
5:這樣打包好后系統就自動提煉DotNetFrameWork放入到CMTSetup\Debug下面的自動創建的文件夾dotnetfx下面了。
posted @
2009-09-24 17:07 天書 閱讀(811) |
評論 (0) |
編輯 收藏