Задать вопрос
Ответы пользователя по тегу C#
  • Как проверить данные из ListBox в C#?

    @leobatura Автор вопроса
    network engineer
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO;
    using System.Net.NetworkInformation;
    
    namespace AOConfig
    {
        public partial class MassScript : Form
        {
            
            public MassScript()
            {
                InitializeComponent();
            }
    
            private void OpenFileBtn_Click(object sender, EventArgs e)
            {
                SourceList.Items.Clear();
                using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Text Documents(*.txt)|*.txt", ValidateNames = true, Multiselect = false })
                {
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        string[] switchList = System.IO.File.ReadAllLines(ofd.FileName,Encoding.UTF8);
                        SourceList.Items.AddRange(switchList);
                        TotalCount_label.Text = SourceList.Items.Count.ToString();
                    }
                }
            }
    
            private void StartPingBtn_Click(object sender, EventArgs e)
            {
                Ping switchPing = new Ping();
                PingReply pingReply = null;
                PingOptions options = new PingOptions();
                options.DontFragment = true;
                // options.Ttl = 64;
                int timeout = 1000;
                foreach (var Item in SourceList.Items)
                {
                    string Host = SourceList.GetItemText(Item);
                    byte[] buffer = Encoding.ASCII.GetBytes(Host);
                    pingReply = switchPing.Send(Host, timeout, buffer, options);
    
                    if (pingReply.Status == IPStatus.Success)
                    {
                        LiveList.Items.Add(Host);
                        LiveCount_label.Text = LiveList.Items.Count.ToString();
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
    }
    Ответ написан
    Комментировать
  • Как в С# прочитанные данные с COM порта вывести в textBox?

    @leobatura Автор вопроса
    network engineer
    private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
            {
                dataIN = serialPort1.ReadExisting();
                this.Invoke(new EventHandler(ShowData));
            }
    
            private void ShowData(object sender, EventArgs e)
            {
                richTextBox1.Text += dataIN;
            }
        }
    }
    Ответ написан
    Комментировать