Guest User

Untitled

a guest
Aug 3rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. private void Button_Click(object sender, RoutedEventArgs e)
  2. {
  3. byte[] byteArray = BitConverter.GetBytes(float.Parse(Tb1.Text, CultureInfo.InvariantCulture.NumberFormat));
  4. byte[] byteArray2 = BitConverter.GetBytes(float.Parse(Tb2.Text, CultureInfo.InvariantCulture.NumberFormat));
  5. byte[] byteArray3 = BitConverter.GetBytes(float.Parse(Tb3.Text, CultureInfo.InvariantCulture.NumberFormat));
  6. byte[] byteArray4 = BitConverter.GetBytes(float.Parse(Tb4.Text, CultureInfo.InvariantCulture.NumberFormat));
  7. ReplaceData(@"C:Test.bin", 416, byteArray);
  8. ReplaceData(@"C:Test.bin", 443, byteArray2);
  9. ReplaceData(@"C:Test.bin", 447, byteArray3);
  10. ReplaceData(@"C:Test.bin", 474, byteArray4);
  11. }
  12.  
  13. public static void ReplaceData(string filename, int position, byte[] data)
  14. {
  15. using (Stream stream = File.Open(filename, FileMode.Open))
  16. {
  17. stream.Position = position;
  18. stream.Write(data, 0, data.Length);
  19. }
  20. }
  21.  
  22. private void Button_Click(object sender, RoutedEventArgs e)
  23. {
  24. ReplaceData(@"C:Test.bin", 416, Tb1);
  25. ReplaceData(@"C:Test.bin", 443, Tb2);
  26. ReplaceData(@"C:Test.bin", 447, Tb3);
  27. ReplaceData(@"C:Test.bin", 474, Tb4);
  28. }
  29.  
  30. public static void ReplaceData(string filename, int position, TextBox tb)
  31. {
  32. byte[] byteArray = BitConverter.GetBytes(float.Parse(tb.Text, CultureInfo.InvariantCulture.NumberFormat));
  33. using (Stream stream = File.Open(filename, FileMode.Open))
  34. {
  35. stream.Position = position;
  36. stream.Write(byteArray, 0, byteArray.Length);
  37. }
  38. }
Add Comment
Please, Sign In to add comment