public void SetListBoxText(System.Windows.Forms.ListBox listBox, string text)
 {
     try
     {
         // InvokeRequired required compares the thread ID of the
         // calling thread to the thread ID of the creating thread.
         // If these threads are different, it returns true.
         if (listBox.InvokeRequired)
         {
             SetListBoxCallback d = new SetListBoxCallback(SetListBoxText);
             Parent.Invoke(d, new object[] { listBox, text });
         }
         else
         {
             listBox.Items.Add(text);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
     finally
     {
     }
 }
Beispiel #2
0
 public FormClient()
 {
     InitializeComponent();
     listBoxStatus.HorizontalScrollbar = true;
     setListBoxCallback            = new SetListBoxCallback(SetListBox);
     setRichTextBoxReceiveCallback = new SetRichTextBoxReceiveCallback(SetRichTextBoxReceive);
 }
Beispiel #3
0
 //&&&&&&&&&&&&&&SDK&&&&&&&&&&&&&&
 public FormRemote()
 {
     InitializeComponent();
     //****************SDK*********
     m_bInitSDK = CHCNetSDK.NET_DVR_Init();
     if (m_bInitSDK == false)
     {
         MessageBox.Show("NET_DVR_Init error!");
         return;
     }
     else
     {
         //保存SDK日志 To save the SDK log
         CHCNetSDK.NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true);
     }
     //&&&&&&&&&&&&&&SDK&&&&&&&&&&&&&&
     Control.CheckForIllegalCrossThreadCalls = false;
     setListBoxCallback         = new SetListBoxCallback(SetListBox);
     displayControlDataCallback = new DisplayControlDataCallback(DisplayControlData);
     getRemoteDataCallback      = new GetRemoteDataCallback(GetRemoteData);
     aTimer.Elapsed            += new ElapsedEventHandler(aTimer_Elapsed);
     aTimer.Interval            = 500; //设置时间间隔
     aTimer.Enabled             = false;
     controldata     = new ControlData();
     remotedata      = new RemoteData();
     button1.Enabled = false;
 }
 public void InsertListBox(string info)
 {
     try
     {
         if (listBox1.InvokeRequired)  //控件是否跨线程?如果是,则执行括号里代码
         {
             if (this.IsDisposed == false || this.IsHandleCreated)
             {
                 SetListBoxCallback setListCallback = new SetListBoxCallback(InsertListBox); //实例化委托对象
                 listBox1.Invoke(setListCallback, info);                                     //重新调用SetListBox函数
             }
         }
         else  //否则,即是本线程的控件,控件直接操作
         {
             if (listBox1.Items.Count > 100)
             {
                 listBox1.Items.Clear();
             }
             listBox1.Items.Insert(0, string.Format("{0} {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), info));
         }
     }
     catch
     {
         ;
     }
 }
Beispiel #5
0
 public FormServer()
 {
     InitializeComponent();
     listBoxStatus.HorizontalScrollbar = true;
     setListBoxCallback          = new SetListBoxCallback(SetListBox);
     setRichTextBoxCallback      = new SetRichTextBoxCallback(SetReceiveText);
     setComboBoxCallback         = new SetComboBoxCallback(setComboBox);
     removeComboBoxItemsCallback = new RemoveComboBoxItemsCallback(RemoveComboBoxItems);
 }
Beispiel #6
0
 public FormServer()
 {
     InitializeComponent();
     listBoxStatus.HorizontalScrollbar = true;
     setListBoxCallback  = new SetListBoxCallback(SetListBox);
     setComboBoxCallback = new SetComboBoxCallback(AddComboBoxitem);
     IPAddress[] addrIP = Dns.GetHostAddresses(Dns.GetHostName());
     localAddress       = addrIP[0];
     buttonStop.Enabled = false;
 }
Beispiel #7
0
 private void SetListBoxText(string v)
 {
     if (listBoxOk.InvokeRequired)
     {
         SetListBoxCallback del = new SetListBoxCallback(SetListBoxText);
         this.Invoke(del, new object[] { Text });
     }
     else
     {
         listBoxOk.Items.Add("Test");
     }
 }
Beispiel #8
0
        public delegate void SetListBoxCallback(ListBox listbox, string text); //定义委托

        public static void add_info(ListBox listbox, string text)
        {
            if (listbox.InvokeRequired)
            {
                SetListBoxCallback s = new SetListBoxCallback(add_info);
                listbox.Invoke(s, listbox, text);
            }
            else
            {
                listbox.Items.Add(text);
            }
        }
Beispiel #9
0
 private void SetListBoxOK(string v)
 {
     if (listBoxOk.InvokeRequired)
     {
         SetListBoxCallback del = new SetListBoxCallback(SetListBoxOK);
         this.Invoke(del, new object[] { v });
     }
     else
     {
         listBoxOk.Items.Add(v);
     }
 }
Beispiel #10
0
 private void SetListBoxTextNotOK(string v)
 {
     if (listBox_NichtOK.InvokeRequired)
     {
         SetListBoxCallback del2 = new SetListBoxCallback(SetListBoxTextNotOK);
         this.Invoke(del2, new object[] { v });
     }
     else
     {
         listBox_NichtOK.Items.Add(v);
     }
 }
Beispiel #11
0
 private void SetListBoxPorts(string text)
 {
     if (this.listBoxPorts.InvokeRequired)
     {
         SetListBoxCallback d2 = new SetListBoxCallback(SetListBoxPorts);
         this.Invoke(d2, new object[] { text });
     }
     else
     {
         listBoxPorts.Items.Add(text);
     }
 }
Beispiel #12
0
 private void SetListBoxStatus(string text)
 {
     if (this.listBoxStatus.InvokeRequired)
     {
         SetListBoxCallback d1 = new SetListBoxCallback(SetListBoxStatus);
         this.Invoke(d1, new object[] { text });
     }
     else
     {
         listBoxStatus.Items.Add(text);
         int countNum = listBoxStatus.Items.Count;
         listBoxStatus.SetSelected(countNum - 1, true);
     }
 }
Beispiel #13
0
        public Form1()
        {
            InitializeComponent();
            setListBoxCallback        = new SetListBoxCallback(SetListBox);
            displayRemoteDataCallback = new DisplayRemoteDataCallback(DisplayRemoteData);
            aTimer.Elapsed           += new ElapsedEventHandler(aTimer_Elapsed);
            aTimer.Interval           = 500; //设置时间间隔
            aTimer.Enabled            = false;
            controldata = new ControlData();
            remotedata  = new RemoteData();
            int count = localIP.ToString().LastIndexOf('.');

            controldata.data.controlID = Convert.ToUInt16(localIP.ToString().Substring(count + 1));
        }
Beispiel #14
0
 public FormRemote()
 {
     InitializeComponent();
     Control.CheckForIllegalCrossThreadCalls = false;
     setListBoxCallback         = new SetListBoxCallback(SetListBox);
     displayControlDataCallback = new DisplayControlDataCallback(DisplayControlData);
     getRemoteDataCallback      = new GetRemoteDataCallback(GetRemoteData);
     aTimer.Elapsed            += new ElapsedEventHandler(aTimer_Elapsed);
     aTimer.Interval            = 500; //设置时间间隔
     aTimer.Enabled             = false;
     controldata     = new ControlData();
     remotedata      = new RemoteData();
     button1.Enabled = false;
 }
Beispiel #15
0
 /// <summary>
 /// Writes messages to the <see cref="StatusListBox"/>
 /// </summary>
 /// <param name="message"></param>
 private void Log(string message)
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (InvokeRequired)
     {
         var callback = new SetListBoxCallback(Log);
         Invoke(callback, new object[] { message });
     }
     else
     {
         StatusListBox.Items.Add(message);
         StatusListBox.SelectedIndex = StatusListBox.Items.Count - 1;
     }
 }
Beispiel #16
0
 public FormServer()
 {
     InitializeComponent();
     //****************SDK*********
     m_bInitSDK = CHCNetSDK.NET_DVR_Init();
     if (m_bInitSDK == false)
     {
         MessageBox.Show("NET_DVR_Init error!");
         return;
     }
     else
     {
         //保存SDK日志 To save the SDK log
         CHCNetSDK.NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true);
     }
     //&&&&&&&&&&&&&&SDK&&&&&&&&&&&&&&
     setListBoxCallback = new SetListBoxCallback(SetListBox);
     exit = new Exit(ToExit);
 }
Beispiel #17
0
        public FormServer()
        {
            InitializeComponent();
            listBox_Status.HorizontalScrollbar = true;
            setListBoxCallback          = new SetListBoxCallback(SetListBox);
            setRichTextBoxCallback      = new SetRichTextBoxCallback(SetReceiveText);
            setComboBoxCallback         = new SetComboBoxCallback(SetComboBox);
            removeComboBoxItemsCallback = new RemoveComboBoxItemsCallback(RemoveComboBoxItems);
            button_Start_Listen.Enabled = true;
            button_Stop_Listen.Enabled  = false;

            //获取本机所有IP地址
            IPAddress[] ipAdress = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress i in ipAdress)
            {
                comboBox_IpAdress.Items.Add(i.ToString());
            }
            comboBox_IpAdress.SelectedIndex = 0;
        }
Beispiel #18
0
 private void SetListBox(ListBox ctl, int idx)
 {
     if(ctl.InvokeRequired)
       {
     SetListBoxCallback d = new SetListBoxCallback(SetListBox);
     this.Invoke(d, new object[] { ctl, idx });
       }
       else
       {
     ctl.SelectedIndex = idx;
       }
 }
Beispiel #19
0
 private void SetListBoxStatus(string text)
 {
     if (this.listBoxStatus.InvokeRequired)
     {
         SetListBoxCallback d1 = new SetListBoxCallback(SetListBoxStatus);
         this.Invoke(d1, new object[] { text });
     }
     else
     {
         listBoxStatus.Items.Add(text);
         int countNum = listBoxStatus.Items.Count;
         listBoxStatus.SetSelected(countNum - 1, true);
     }
 }
Beispiel #20
0
 public Service(ListBox listbox)
 {
     this.listbox       = listbox;
     setListBoxCallback = new SetListBoxCallback(SetListBox);
 }
Beispiel #21
0
 private void SetListBoxPorts(string text)
 {
     if (this.listBoxPorts.InvokeRequired)
     {
         SetListBoxCallback d2 = new SetListBoxCallback(SetListBoxPorts);
         this.Invoke(d2, new object[] { text });
     }
     else
     {
         listBoxPorts.Items.Add(text);
     }
 }
Beispiel #22
0
 private SetListBoxCallback setListBoxCallback;//创建委托的实例
 public Service(ListBox listbox, StreamWriter sw)
 {
     this.listbox       = listbox;
     this.sw            = sw;
     setListBoxCallback = new SetListBoxCallback(SetListBox);//指向某函数。
 }
Beispiel #23
0
 public MainForm()
 {
     InitializeComponent();
     listBoxStatus.HorizontalScrollbar = true;
     setListBoxCallback = new SetListBoxCallback(SetListBox);
 }
Beispiel #24
0
 public FormServer()
 {
     InitializeComponent();
     setListBoxCallback = new SetListBoxCallback(SetListBox);
     exit = new Exit(ToExit);
 }
Beispiel #25
0
 /// <summary>
 /// Writes messages to the <see cref="StatusListBox"/>
 /// </summary>
 /// <param name="message"></param>
 private void Log(string message)
 {
     // InvokeRequired required compares the thread ID of the 
     // calling thread to the thread ID of the creating thread. 
     // If these threads are different, it returns true. 
     if (InvokeRequired)
     {
         var callback = new SetListBoxCallback(Log);
         Invoke(callback, new object[] {message});
     }
     else
     {
         StatusListBox.Items.Add(message);
         StatusListBox.SelectedIndex = StatusListBox.Items.Count - 1;
     }
 }
 // Thread-safe method for updating clientList
 public void updateClientList(List<String> clientList)
 {
     if (this.clientListBox.InvokeRequired)
     {
         // It's on a different thread, so use Invoke.
         SetListBoxCallback d = new SetListBoxCallback(AddClientList);
         this.Invoke
             (d, new object[] { clientList });
     }
     else
     {
         // It's on the same thread, no need for Invoke
         this.clientListBox.DataSource = clientList;
     }
 }