You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 regels
1.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace ProductionControl.UIExtend
  9. {
  10. public class TextBoxRemind
  11. {
  12. private string[] array = null;
  13. private static string workPath = Directory.GetCurrentDirectory();
  14. private static string textPath = Path.Combine(workPath, "TextRemind.txt");
  15. public void InitAutoCompleteCustomSource(TextBox text)
  16. {
  17. array = ReadText();
  18. if (array != null && array.Length > 0)
  19. {
  20. AutoCompleteStringCollection ACSC = new AutoCompleteStringCollection();
  21. for (int i = 0; i < array.Length; i++)
  22. ACSC.Add(array[i]);
  23. text.AutoCompleteCustomSource = ACSC;
  24. }
  25. }
  26. string[] ReadText()
  27. {
  28. try
  29. {
  30. if (!File.Exists(textPath))
  31. return null;
  32. return File.ReadAllLines(textPath);
  33. }
  34. catch
  35. {
  36. return null;
  37. }
  38. }
  39. public void Remind(string str)
  40. {
  41. try
  42. {
  43. if(array == null || !array.Contains(str))
  44. {
  45. File.AppendAllLines(textPath,new string[] { str });
  46. }
  47. }
  48. catch
  49. {
  50. }
  51. }
  52. }
  53. }