0

I am doing a graduation project on Machine Translation to translate from any language into English language.

My software accepts a string in the source language (SL) and then under each source language word it displays all the meanings ordered according to their probabilities.. something looks like this

Word1      Word2     Word3
hit        bell      man
multiply             leg

The issue is that I have to display the meanings of the first word then I have to go back to the first line to display the meanings of the second word and so on... in the same TextBox!

Is there a way in c# by which I can go back to the first line and write next to existing words?

8
  • 1
    That sounds like it'd going to be very awkward. Why are you doing your work against a string array rather then in memory structures that can be transformed into a string for presentation ? Commented Feb 28, 2012 at 21:24
  • I think you're going to have to be a little more specific. First of all: what type of application is this? I'm guessing it's not a console application, since you mention a "textbox." Is that actually a requirement or does it just need to look a certain way when all is said and done? Also, to clarify, do you mean that you need to display columns for each word and then populate those columns with meanings as the application runs? Commented Feb 28, 2012 at 21:27
  • @asawyer actually I'am using array of array to store the results. Each array inside the jagged array stores the meanings of each word in order. but I also find it difficult to display it in the way I need. Commented Feb 28, 2012 at 21:31
  • You might want to create a new control that just creates textboxes with 0 border. That way each column is simply a borderless multiline textbox. And when you add a new column, your control simply adds a new textbox. You can also use the FlowLayoutPanel to automate your layout additions. If you have the freedom to do this, it would be easier than hacking around in a textbox. Commented Feb 28, 2012 at 21:33
  • @StevenOxley It is a windows based application.it just need to look a certain way when all is said and done.."do you mean that you need to display columns for each word and then populate those columns with meanings as the application runs?" No the displaying part is the done lastly after finishing calculations. Commented Feb 28, 2012 at 21:39

1 Answer 1

1

You can control cursor position (and selection) by TextBox.SelectionStart and TextBox.SelectionLength properties.

Example if you want move cursor to before 3th character set SelectionStart = 2 and SelectionLength = 0.

So, as a - assuming Windows Forms Application - solution to your issue

public class TextBoxEx : TextBox
{
    public TextBoxEx()
    { }

    public void GoTo(int line, int column)
    {
        if (line < 1 || column < 1 || this.Lines.Length < line)
            return;

        this.SelectionStart = this.GetFirstCharIndexFromLine(line - 1) + column - 1;
        this.SelectionLength = 0;
    }

    public int CurrentColumn
    {
        get { return this.SelectionStart - this.GetFirstCharIndexOfCurrentLine() + 1; }
    }

    public int CurrentLine
    {
        get { return this.GetLineFromCharIndex(this.SelectionStart) + 1; }
    }
}

OR

Just add this class to your project,

public static class Extentions
{
    public static void GoTo ( this TextBox Key , int Line , int Character )
    {
        if ( Line < 1 || Character < 1 || Key . Lines . Length < Line )
            return;

        Key . SelectionStart = Key . GetFirstCharIndexFromLine ( Line - 1 ) + Character - 1;
        Key . SelectionLength = 0;
        Key . Focus ( );
    }
} 

After adding this class to your project, you can easily navigate your TextBox by

TextBox . GoTo ( 1 , 1 ); // Navigate to the 1st line and the 1st character :)

Hope this help.

Sign up to request clarification or add additional context in comments.

10 Comments

sounds helpful.. I'll try it and let you know.. Thanks
Edit I : Adding go to line and column support :)
@asawyer what do you main by Winforms?? do you mean windows forms?
@asawyer ops :( so, is there a way to solve my issue for asp.net texbox because I will use asp.net to connect the services of my sofware( Iam planning to devlop it as a web service)
@Noha That is far beyond the scope of these comments.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.