开发者

getting current line text is on

开发者 https://www.devze.com 2023-04-11 10:27 出处:网络
I have a list of lines that looks like this: textbox.text += \"p\"+b+\" the rest\\r\\np\"+b+\" more text\";

I have a list of lines that looks like this:

textbox.text += "p"+b+" the rest\r\np"+b+" more text";

b is supposed to represent the current line number in the te开发者_开发问答xtbox that the line is on. I have tried using textbox.lines.count() but it only changes i into the last line number.

Is there any other way about going with this, or do I have to switch to another method?


If you are assigning, I think you can do it manually (calculate the line number). There is no function that could "guess" on which line the tex will appear. You can create a integer variable and increment it when appending a line/s and use the variable when you need to display the current line number.


I split the lines by the line breaks ("\r\n") and used a for loop to replace "b" (I changed it to string rather than a variable)

for (int i = 0; i < da.Length; i++)
                {
                    //replace char with number
                    string f = da[i].Replace("n", (i + 1).ToString());
                    disp.Text += f + "v";
                }

I added "v" so that I can replace it outside of the loop with "\r\n" again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号