-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixInput.xaml.cs
More file actions
136 lines (120 loc) · 5.29 KB
/
MatrixInput.xaml.cs
File metadata and controls
136 lines (120 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace CalMat
{
/// <summary>
/// Logique d'interaction pour MatrixInput.xaml
/// </summary>
public partial class MatrixInput : Window
{
Matrix matrix; // on crée une matrice générale pour que toutes les méthodes de la classe puisse y accéder
List<TextBox> inputs = new List<TextBox>(); // liste pour les textBox
public MatrixInput(Matrix m, bool load) // création de la fenêtre
{
InitializeComponent();
// ne pas insérer dans les boucles imbriquées, ne gère pas les hauteurs de rows
//on crée le nombre de colonnes qu'il faut
for (int c = 0; c < m.Columns ; c++ )
{
ColumnDefinition ColDefc = new ColumnDefinition();
ColDefc.Name = "ColDef" + c;
Grid_Tabeau.ColumnDefinitions.Add(ColDefc);
}
//on crée le nombre de lignes qu'il faut
for (int l = 0; l < m.Lines; l++ )
{
RowDefinition RowDef = new RowDefinition();
RowDef.Name = "RowDef" + l;
Grid_Tabeau.RowDefinitions.Add(RowDef);
}
// on definie les paramettres de la fenêtre
Grid_Tabeau.Margin = new Thickness(20);
this.Width = 30 * m.Columns + 40;
this.Height = 30 * m.Lines + this.Btn_matrix.Height + 70;
matrix = m;
if(load) // si on doit modifier les valeurs de la matrice
{
//on crée les textBox avec les valeurs correspondantes
for (int c = 0; c < m.Columns; c++)
{
for (int l = 0; l < m.Lines; l++)
{
// on definie les paramètres de chaque textBox
TextBox txt = new TextBox();
txt.Background = Brushes.Transparent;
txt.Foreground = Brushes.White;
txt.TextAlignment = TextAlignment.Center;
txt.VerticalContentAlignment = System.Windows.VerticalAlignment.Top;
txt.SetValue(Grid.ColumnProperty, c);
txt.SetValue(Grid.RowProperty, l);
txt.Text = m.Elements[c, l].ToString();
txt.PreviewTextInput += Txt_PreviewTextInput;
Grid_Tabeau.Children.Add(txt);
inputs.Add(txt);
}
}
}
else // sinon on crée les textBox avec rien à l'interieur
{
for (int c = 0; c < m.Columns; c++)
{
for (int l = 0; l < m.Lines; l++)
{
TextBox txt = new TextBox();
txt.Background = Brushes.Transparent;
txt.Foreground = Brushes.White;
txt.TextAlignment = TextAlignment.Center;
txt.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
txt.SetValue(Grid.ColumnProperty, c);
txt.SetValue(Grid.RowProperty, l);
txt.PreviewTextInput += Txt_PreviewTextInput;
Grid_Tabeau.Children.Add(txt);
inputs.Add(txt);
}
}
}
}
#region"event"
private void Txt_PreviewTextInput(object sender, TextCompositionEventArgs e) //événement pour obliger l'utilisateur à écrire des chiffres
{
Regex reg = new Regex("[^0-9,\\.]+");
e.Handled = reg.IsMatch(e.Text);
}
private void Btn_matrix_Click(object sender, RoutedEventArgs e) //évenement quand on clique sur le bouton "OK"
{
int j = 0;
for (int c = 0 ; c < matrix.Columns; c++ )
{
for (int l = 0 ; l < matrix.Lines; l++)
{
double.TryParse(inputs [j].Text, out matrix.Elements[c, l]); //pour chaque textBox, on les convertis en double et on les place dans la matrice
j++;
}
}
CalMat.Calculatrice.mainWindow.TxtBox_console.AppendText(matrix.name + "=\n");
CalMat.Calculatrice.mainWindow.TxtBox_console.AppendText(matrix.ToString()); // on affiche la matrice sur la console en guise de confirmation
CalMat.Calculatrice.mainWindow.ListBox_display.Items.Refresh(); // on rafraichie l'affichage des matrices
this.Close(); // on ferme la fenêtre
}
private void Creation_Matrice_SizeChanged(object sender, SizeChangedEventArgs e) // évenement pour déterminer la taille des chiffres
{
foreach (TextBox txt in inputs)
{
txt.FontSize = this.Height/15 ;
}
}
#endregion
}
}