Server.cs 883 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace SocketChat.Server
  8. {
  9. public class Server
  10. {
  11. private static ListBox _listbox;
  12. public delegate void ListBoxCallBack(string str);
  13. public Server(ListBox v_listbox)
  14. {
  15. _listbox = v_listbox;
  16. }
  17. public static void SetListBox(string str)
  18. {
  19. if (_listbox.InvokeRequired)
  20. {
  21. ListBoxCallBack __listCallBack = new ListBoxCallBack(SetListBox);
  22. _listbox.Invoke(__listCallBack, str);
  23. }
  24. else
  25. {
  26. _listbox.Items.Add(str);
  27. _listbox.SelectedIndex = _listbox.Items.Count - 1;
  28. _listbox.ClearSelected();
  29. }
  30. }
  31. }
  32. }