posts - 124,  comments - 29,  trackbacks - 0

//注意在工程上添加系统引用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 天书 阅读(2841) | 评论 (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 天书 阅读(5668) | 评论 (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 天书 阅读(2112) | 评论 (0)编辑 收藏
     摘要:   private void MQRecieve()   //MQ接收函数        {            try     &nbs...  阅读全文
posted @ 2010-02-08 09:04 天书 阅读(570) | 评论 (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 天书 阅读(454) | 评论 (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 天书 阅读(930) | 评论 (0)编辑 收藏

跨线程时 一定要用System.Timer,而不要用System.windows.Forms.Timer.

Timer 控件到点时,一定要先stop然后做其他工作,最后再messageBox.show() ;否则messageBox.show() 将线程阻塞在那块等待用户操作了,要是用户不在没有操作,则不能stop()

posted @ 2010-01-07 10:04 天书 阅读(591) | 评论 (0)编辑 收藏

1:网线或者网络的事,比如IP被占用,网线不好用。

查找方法: ping一下网关。

2:接收数据中有"\0",把后面数据截断了。

解决办法: string.replace("\0","")

posted @ 2010-01-07 10:03 天书 阅读(1213) | 评论 (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 天书 阅读(273) | 评论 (0)编辑 收藏
1:添加—新建项目—其它项目类型—安装和部署—安装项目
2:在视图—文件系统中,按照源程序bin目录下的结构,构建文件夹及文件(文件夹中套n多文件夹的可以同时开着两个,拖进去,不用一层一层建太麻烦了)
3:属性-系统必备里-.NETFrameWork2.0打上对勾
4:视图—文件系统—用户桌面添加上快捷方式,右键添加,同时属性中的alwayscreate 设为true
5:这样打包好后系统就自动提炼DotNetFrameWork放入到CMTSetup\Debug下面的自动创建的文件夹dotnetfx下面了。
posted @ 2009-09-24 17:07 天书 阅读(776) | 评论 (0)编辑 收藏
仅列出标题
共13页: 1 2 3 4 5 6 7 8 9 Last 

<2008年10月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(5)

随笔档案

文章分类

文章档案

好友的Bolg

搜索

  •  

最新评论

阅读排行榜

评论排行榜