Salut,
Quand on click dans une cellule d'un tableLayoutPanel. Comment on fait pour avoir la collonne et le row qu'on a clicker avec la souris.
Merci d'avance
TrollTop
Salut,
Quand on click dans une cellule d'un tableLayoutPanel. Comment on fait pour avoir la collonne et le row qu'on a clicker avec la souris.
Merci d'avance
TrollTop
J'ai trouvé ça sur le net mais je ne comprend pas comment faire. Est-ce que quelqu'un pourrait m'éclairer s.v.p
1. Call GetRowHeights() and GetColumnWidths() on the TLP and store off the values
2. Get the DisplayRectangle.Location from the TLP, and convert it to screen coordinates using PointToScreen. This is your starting point and will also handle the case where the TLP is scrolled.
3. Create your bounds as new Rectangle(startingPoint, TLP.DisplayRectangle.Size);
4. Now initialize a variable (say offset) to be the x coordinate of your bounds.
5. Now loop through the columns and identify where the mouse is by checking the mouse position's x coordinate against offset + columnwidthIdea. If x <= this value you know that your mouse is over this column and your loop counter will be the index. If it is not, you add columnwidthIdea to offset and repeat.
6. Finding the row is pretty much the same expect that you check the mouse positions's y coordinate against offset + rowheightIdea. Where offset is initialized to bounds.Y.
7. Remember to handle the case where the mouse is not over any cell.
8. If you want to handle the RightToLeft case (TLP.RightToLeft == RightToLeft.Yes), then you had to adjust your logic in step 4 and 5. I.e. offset should not be initialized to bounds.X but bounds.Right since column indices will grow from the right rather than the left. And you check if mouse position.x is >= offset - columnwidthIdea, and if not substract columnwidthIdea from offset.
Merci d'avance
TrollTop
il te dit de calculer les hauteurs et largeurs de chaque colonne/ligne afin de voir dans quelle colonne tu es
Je comprend de 1 a 4 mais le reste je ne comprend pas pour l'instant j'ai fait ça
Est ce que vous pouvez m'éclairer pour le reste s.v.p
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 array<int,1> ^RH; array<int,1> ^CW; Point startPoint; RH = tableLayoutPanel1->GetRowHeights; CW = tableLayoutPanel1->GetColumnWidths; startPoint = control->PointToScreen( Point(tableLayoutPanel1->DisplayRectangle.Location.X,tableLayoutPanel1->DisplayRectangle.Location.Y) ); Rectangle(startPoint,tableLayoutPanel1->DisplayRectangle.Size);
Merci D'avance
TrollTop
je sais pas trop pour ses histoires de PointToScreen, essaie voir un truc du genre, en surchargeant MouseDown:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 System::Void tableLayoutPanel1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { // colonnes int offset = 0; int i = 0; while (offset < e->X && i < widths->Length) { offset += widths[i]; i++; } label1->Text = String::Format("Cliqué dans la colonne numéro {0}", i - 1); // lignes offset = 0; i = 0; while (offset < e->Y && i < heights->Length) { offset += heights[i]; i++; } label2->Text = String::Format("Cliqué dans la ligne numéro {0}", i - 1); }
Voici comment faire pour ajouter un TextBox dans un TableLayoutPanel avec l'évènement MouseClick .
Mettre c'est variable après
#pragma endregion
private:static array<int ,1> ^RH;
private:static array<int ,1> ^CW;
et dans l'évènement mouseClick mettre ceci.
Voila. Un gros merci a nico-pyright(c) pour son aide très apprécié.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 private: System::Void TableLayoutPanelMouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { Point startPoint; RH = tableLayoutPanel1->GetRowHeights(); CW = tableLayoutPanel1->GetColumnWidths(); startPoint = Control::PointToScreen( Point(tableLayoutPanel1->DisplayRectangle.Location.X,tableLayoutPanel1->DisplayRectangle.Location.Y) ); Rectangle ^rect = gcnew Rectangle(startPoint,tableLayoutPanel1->DisplayRectangle.Size); // colonnes int offset = rect->X; int i = 0; while (offset < e->X && i < CW->Length) { offset += CW[i]; i++; } int Colonne = i-1; // lignes offset = rect->Y; i = 0; while (offset < e->Y && i < RH->Length) { offset += RH[i]; i++; } int Ligne = i; //Ajoute un TextBox dans la colonne et ligne clicker avec la souris TextBox ^tab = gcnew TextBox; tableLayoutPanel1->Controls->Add(tab,Colonne,Ligne); }
TrollTop
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager