-1

I have this code:

private void scrollLabel1_MouseDown(object sender, MouseEventArgs e)
        {
            for (int i = 0; i <  ScrollLabel._lines.Length; i++)
            {

            }
        }

_lines is type of string[]

_lines format is like this:

First index 0 contain some text: "hello" Index 1 contain a line of date and time: Fri, 31 Jan 2014 18:31:12 +0200

Then index 2 is empty line space: ""

Then index 3 again a text: "hi" Index 4 is again date and time: Fri, 31 Jan 2014 18:31:30 +0200

And os on there are 151 lines.

What i want to do is that when i click(down) on any line that is part of two lines text + date and time it will color this both lines.

For example i clicked on line in index 0 anywhere on this line it will color index 0 and index 1 if i clicked on line in index 2 that is empty do nothing.

If i click on line in index 3 or 4 then color lines 3 and 4. If i clicked on line 3 or 4 color both lines 3 and 4.

If i clicked on line for example 123 or 124 color both 123 and 124.

How can i do it ?

ScrollLabel is a UserControl type Label i dragged to the form1 designer. And it dosent have index selected event or something like that.

2
  • 2
    i reread this 3 times and can't make any sense of it Jan 31, 2014 at 16:42
  • Use a RichTextBox control instead of a UserControl and a Label.
    – LarsTech
    Jan 31, 2014 at 16:47

1 Answer 1

1

If i is the index of the clicked line then do this:

int j = ((int)(i / 3)) * 3;
colorLine(j);
colorLine(j + 1);
// colorLine(j + 2); // not needed, that line is an empty string

The colorLine() method should take care of coloring the line of the given index. It should do something like this:

private void colorLine(int j)
{
    ScrollLabel._lines[j] // put here code to color the line
}

How to actually color the line totally depends on what a line actually is. press . (dot) behind an instance to open Intellisense and see which methods and properties are available. One will allow coloring the line. If not, coloring is impossible and the whole attempt is impossible.

2
  • pid the variable (i) is from the FOR loop i did but what is J ? Not exist. Jan 31, 2014 at 17:04
  • And how do i color the variable j since it should be int ? Can you show me the complete code ? thanks. Jan 31, 2014 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.