Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. private double[,] CreateArray(int m, int n)
  15. {
  16. double[,] drr = new double[m, n];
  17. for (int i = 0; i < m; i++)
  18. {
  19. for (int j = 0; j < n; j++)
  20. {
  21. drr[i, j] = i * j - j / 42;
  22. }
  23. } return drr;
  24. }
  25. public Form1()
  26. {
  27. InitializeComponent();
  28. }
  29.  
  30. private void Form1_Load(object sender, EventArgs e)
  31. {
  32.  
  33. }
  34.  
  35. int m;
  36. int n;
  37. private void button1_Click(object sender, EventArgs e)
  38. {
  39. if (!int.TryParse(textBox1.Text, out m) || m < 1)
  40. {
  41. MessageBox.Show("Ошибка!!", "Некорректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  42. textBox1.Focus();
  43. return;
  44. }
  45.  
  46. if (!int.TryParse(textBox2.Text, out n) || n < 1)
  47. {
  48. MessageBox.Show("Ошибка!!", "Некорректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  49. textBox1.Focus();
  50. return;
  51. }
  52.  
  53. dataGridView1.ColumnCount = n;
  54. dataGridView1.RowCount = m;
  55. double[,] drr = CreateArray(m, n);
  56. for (int i = 0; i < m; i++)
  57. {
  58. for (int j = 0; j < n; j++)
  59. {
  60. dataGridView1[j, i].Value = drr[i, j].ToString("F3");
  61. }
  62. }
  63. }
  64.  
  65. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  66. {
  67.  
  68.  
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement