IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++/CLI Discussion :

tableLayoutPanel position mouseclick


Sujet :

C++/CLI

  1. #1
    Membre régulier
    Inscrit en
    Juillet 2007
    Messages
    124
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Points : 71
    Points
    71
    Par défaut tableLayoutPanel position mouseclick
    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

  2. #2
    Membre régulier
    Inscrit en
    Juillet 2007
    Messages
    124
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Points : 71
    Points
    71
    Par défaut
    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

  3. #3
    Rédacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Points : 16 075
    Points
    16 075
    Par défaut
    il te dit de calculer les hauteurs et largeurs de chaque colonne/ligne afin de voir dans quelle colonne tu es

  4. #4
    Membre régulier
    Inscrit en
    Juillet 2007
    Messages
    124
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Points : 71
    Points
    71
    Par défaut
    Je comprend de 1 a 4 mais le reste je ne comprend pas pour l'instant j'ai fait ça
    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);
    Est ce que vous pouvez m'éclairer pour le reste s.v.p

    Merci D'avance

    TrollTop

  5. #5
    Rédacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Points : 16 075
    Points
    16 075
    Par défaut
    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);
    }

  6. #6
    Membre régulier
    Inscrit en
    Juillet 2007
    Messages
    124
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Points : 71
    Points
    71
    Par défaut
    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.
    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);
    		 }
    Voila. Un gros merci a nico-pyright(c) pour son aide très apprécié.

    TrollTop

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Position du curseur
    Par gimlithedwarf dans le forum Composants VCL
    Réponses: 2
    Dernier message: 22/08/2002, 23h45
  2. [XSLT]position d'un element de valeur specifique
    Par squat dans le forum XSL/XSLT/XPATH
    Réponses: 6
    Dernier message: 25/07/2002, 16h42
  3. Position du curseur dans Edit
    Par MrJéjé dans le forum C++Builder
    Réponses: 3
    Dernier message: 20/06/2002, 17h09
  4. Réponses: 2
    Dernier message: 17/05/2002, 20h37
  5. FOnction api specifiant la position de la souris
    Par florent dans le forum C++Builder
    Réponses: 4
    Dernier message: 15/05/2002, 20h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo