コード例 #1
0
 public void ListBoxAddItem(string data)
 {
     if (listBoxObject.InvokeRequired)
     {
         ListBoxDelegate d = new ListBoxDelegate(ListBoxAddItem);
         listBoxObject.Invoke(d, new object[] { data });
     }
     else
     {
         listBoxObject.Items.Add(data);
     }
 }
コード例 #2
0
 /// <summary>在listbox中追加信息<</summary>
 /// <param name="str">要追加的信息</param>
 public void AddItemToListBox(string str)
 {
     if (listbox.InvokeRequired)
     {
         ListBoxDelegate d = AddItemToListBox;
         listbox.Invoke(d, str);
     }
     else
     {
         listbox.Items.Add(str);
         listbox.SelectedIndex = listbox.Items.Count - 1;
         listbox.ClearSelected();
     }
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: mdmellor/serts_lab
        private void PC_comm_method()
        {
            ListBoxDelegate FileListDel = ListBoxDelMethod;
            string          serialData  = "";

            while (true)
            {
                if (serialPort.IsOpen)
                {
                    try
                    {
                        serialData = serialPort.ReadLine();
                    }
                    catch
                    {
                        Debug.WriteLine("Failed to open serial port");
                    }
                    if (serialData.Equals(StartFileList.ToString()))
                    {
                        File_List.Invoke(FileListDel, StartFileList, "");
                        try
                        {
                            serialData = serialPort.ReadLine();
                        }
                        catch
                        {
                            Debug.WriteLine("Failed to read from serial port");
                        }
                        while (!serialData.Equals(EndFileList.ToString()))
                        {
                            File_List.Invoke(FileListDel, EndFileList, serialData);
                            try
                            {
                                serialData = serialPort.ReadLine();
                            }
                            catch
                            {
                                Debug.WriteLine("Failed to read from serial port");
                            }
                        }
                    }
                }
                else
                {
                    Thread.Sleep(500);
                }
            }
        }