0

In the code that follows,was trying get the border that was clicked the name or the text of the child that's a textblock my problem is that without "eaclick.Handled = true;" in the code it starts showing me all the Names of the border that the mouse has entered before the click and not not only the oned that was clicked by adding "eaclick.Handled = true;" shows me alls the first border that the mouse has entered,it seems to me that's saving in a stack all the mouseenters and when Click in leftmousedown it goes get that stack instand of getting me the last mouseenter that I want can anyone explain me how to fix or what I am doing wrong?

for (int i = 0; i < NumPages; i++)
{

    Border borderaux = new Border();
    borderaux.Name = Convert.ToString(i);
    //borderaux.MouseEnter += borderaux_MouseEnter;
    Border clicked;
    borderaux.MouseEnter += (smouse, eamouse) =>
    {
        clicked = (Border)smouse;
        clicked.Cursor = Cursors.Hand;

        MouseLeftButtonDown += (sclick, eaclick) =>
        {
            if (eaclick.ClickCount == 1)
            {
                TextBlock opcao = (TextBlock)(clicked).Child;

                //string opcao="";
                MessageBox.Show("Pressed-->" + opcao.Text);
                //MessageBox.Show("Pressed-->" + clicked.Name);
                eaclick.Handled = true;
            }
        };
H.C
  • 565
  • 7
  • 28
  • 2
    Please take the time to structure your question to be easily readable / comprehensible. – Martin Apr 15 '14 at 13:53
  • +1 @Martin comment. also this seems to be getting overcomplicated but first I'd like to know the question is being interpreted correctly. – Chris W. Apr 15 '14 at 15:38
  • resume: there are two border that represent page 0 and 1,when I clicked border that represents page 1 instead of the Messagebox show 1 it shows 0 because the mouse passed first/hovered the border that represents 0,sorry if still didn't express well,I think that my mistake is using the MouseEnter event,should only use MouseLeftButtonDown event if its that,will comment later. – H.C Apr 15 '14 at 16:44
  • the problem was using the MouseLeftButtonDown event inside MouseEnter event... – H.C Apr 15 '14 at 16:56

1 Answers1

0

the problem was that using the MouseLeftButtonDown event inside MouseEnter event that was giving the problem,that when was clicked it would show me x MessageBox showing all the number of borders that the mouse had hovered until the click,with the fix it show me the border that was actualy clicked.

    for (int i = 0; i < NumPages; i++)
    {

        Border borderaux = new Border();
        borderaux.Name = Convert.ToString(i);
        //borderaux.MouseEnter += borderaux_MouseEnter;
        Border clicked;
        borderaux.MouseLeftButtonDown += (sclick, eaclick) =>
        {

            if (eaclick.ClickCount == 1)
            {
                TextBlock opcao = (TextBlock)((Border)sclick).Child;

                //string opcao="";
                MessageBox.Show("Pressed-->" + opcao.Text);
                //eaclick.Handled = true;
            }
        };

        borderaux.MouseEnter += (smouse, eamouse) =>
        {
            clicked = (Border)smouse;
            clicked.Cursor = Cursors.Hand;

        };
H.C
  • 565
  • 7
  • 28
  • Ok tried to explain about the problem that was giving,about giving the answer in my own question was because only today stackoverflow alowed me to put a replay to my own question but thanks for the information. – H.C Apr 16 '14 at 11:07