C
C#3y ago
Grin

Is it possible to create a text box that receives data from right to left? [Answered]

Imagine if you had to solve a problem like 57281 * 38268 Don't use a calculator, when you start writing down the answer do you start from the right and go left, or start from the left and go right? Whenever you enter information into a textbox for winforms the text always goes left to right, is there a way to change this?
37 Replies
WhiteBlackGoose
it doesn't make any sense to change it if you want to calculate character by character, you can do it starting from the last character
Grin
GrinOP3y ago
would it be fair to assume that it is not possible? regardless as to rather it makes sense?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
ty, I did try txtBox_Calculation.TextAlign = HorizontalAlignment.Right; but that didn't seem to work for some reason. neither one seems to work
TheBoxyBear
TheBoxyBear3y ago
TextAlign is only for the placement of the text to be centered or anchored to the dide RightToLeft to invert the characters
Grin
GrinOP3y ago
I'd like to invert the characters I suppose very close to what I needed, but not quite I guess the best way for me to put what I'm trying to explain is imagine if you were writing in Arabic or Hebrew, you write right to left. I don't think it's possible with studio though.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
That crashed my program lol
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
how do you put code in here like that that looks clean private void txtBox_Calculation_TextChanged(object sender, EventArgs e) { if (txtBox_Calculation.Text.Length <= 1) return; var allWithoutLastChar = txtBox_Calculation.Text[..^1]; var lastChar = txtBox_Calculation.Text[txtBox_Calculation.Text.Length - 1]; txtBox_Calculation.Text = lastChar + allWithoutLastChar; } mine is different, what is the KeyUp?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
private void txtBox_Calculation_KeyUP(object sender, EventArgs e)
{
if (txtBox_Calculation.Text.Length <= 1) return;
var allWithoutLastChar = txtBox_Calculation.Text[..^1];
var lastChar = txtBox_Calculation.Text[txtBox_Calculation.Text.Length - 1];

txtBox_Calculation.Text = lastChar + allWithoutLastChar;
}
private void txtBox_Calculation_KeyUP(object sender, EventArgs e)
{
if (txtBox_Calculation.Text.Length <= 1) return;
var allWithoutLastChar = txtBox_Calculation.Text[..^1];
var lastChar = txtBox_Calculation.Text[txtBox_Calculation.Text.Length - 1];

txtBox_Calculation.Text = lastChar + allWithoutLastChar;
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
ty
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
That screenshot I took the function txtBox_Calculation_KeyUP doesn't do anything Like I'm typing into the box after building it and same problem except I'm not crashing
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
I'm not sure what you mean by subscribed did I write characters into the text box that is associated to keyups?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
So it is an event to the blank line of code?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
will do thank you
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grin
GrinOP3y ago
I should've asked you what that line means var allWithoutLastChar = txtBox_Calculation.Text[..^1]; I've never seen an array with ..^1 inside of it
Grin
GrinOP3y ago
Apparently there is a right to left setting for text boxes but it only works with rtl languages, not numbers.
Grin
GrinOP3y ago
private void txtBox_Calculation_TextChanged(object sender, EventArgs e)
{
//will enter the values 0, 1, 2, 3; should see 3210
string number = txtBox_Calculation.Text;
string tempNumber = "";
if (txtBox_Calculation.Text.Length <= 1) return;
else
{
lastNumber++; //last number will initialize at 0 globally, will add 1 when entering the else statement
tempNumber = number[lastNumber] + number; //error is here? 1 + 0 + 1, 3 elements
number = ""; //resetting number to nothing so we can resubmit the new values
txtBox_Calculation.Text = ""; //resetting the textbox to nothing so we can get the correct values
//starting at element 0, fill in the text box and number with the value at that element going foward
for(int tempCounter = 0; tempCounter <= lastNumber; tempCounter++)
{
txtBox_Calculation.Text += tempNumber[tempCounter];
number += tempNumber[tempCounter];
}
}
}
private void txtBox_Calculation_TextChanged(object sender, EventArgs e)
{
//will enter the values 0, 1, 2, 3; should see 3210
string number = txtBox_Calculation.Text;
string tempNumber = "";
if (txtBox_Calculation.Text.Length <= 1) return;
else
{
lastNumber++; //last number will initialize at 0 globally, will add 1 when entering the else statement
tempNumber = number[lastNumber] + number; //error is here? 1 + 0 + 1, 3 elements
number = ""; //resetting number to nothing so we can resubmit the new values
txtBox_Calculation.Text = ""; //resetting the textbox to nothing so we can get the correct values
//starting at element 0, fill in the text box and number with the value at that element going foward
for(int tempCounter = 0; tempCounter <= lastNumber; tempCounter++)
{
txtBox_Calculation.Text += tempNumber[tempCounter];
number += tempNumber[tempCounter];
}
}
}
I ended up doing this, but am getting a bad error Been trying to figure this out for the past 2 hours, at what point does coding become easier?
Grin
GrinOP3y ago
Grin
GrinOP3y ago
How is it out of bounds when the index is 0?
Grin
GrinOP3y ago
Every time I have a lead it drops me back to the start
Grin
GrinOP3y ago
The only other thing I can think of is when I enter a value into the box have the program somehow activate my left arrow key button. Which also is not on the internet anywhere https://github.com/RobGreen490/Ch5-AdditionTutor.git The time I'm looking for is dextrosinistral How can I make it where my textbox accepts any and all input as dextrosinistral
Grin
GrinOP3y ago
There is an option in the properties of the text box called events
Grin
GrinOP3y ago
Where you can find a keyup event to set
Grin
GrinOP3y ago
Which fixes this problem
Grin
GrinOP3y ago
Now how do i make this post solved /solved solved @Hisme I ended up inserting this code into my txtBox txtBox_Calculation.SelectionStart = 0; This code somehow always kept my cursor to the left when entering anything, which was exactly what I needed. I figured out what you meant by that other code, but it was kind of faulty. It would leave me off at the 2nd selectionStart point
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server