Search code examples
c#formslabelmouseclick-event

Is it possible to get which character of text is clicked on C# form?


I am trying to get which of the * is clicked in text of label as in picture. Pic

NOTE : Number of * is not known at first.User inputs it.So the position of mouse click is not useful.


Solution

  • Answer is :

    X of first *'s location is known, equals = 10 .The asterisks are spaced equally,distance between two * is ~15 pixel .

    When user clicks on one of asterisks , index of asterisks can be calculated as the code below

    private void label4_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                double t = (e.X - 10) / 15.0;
                int indexOfClickedAsterisk=(int)Math.Round(t) + 1;
            }