C
C#2y 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
Grin2y ago
would it be fair to assume that it is not possible? regardless as to rather it makes sense?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y 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
TheBoxyBear2y ago
TextAlign is only for the placement of the text to be centered or anchored to the dide RightToLeft to invert the characters
Grin
Grin2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y ago
That crashed my program lol
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y ago
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y ago
ty
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y ago
So it is an event to the blank line of code?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y ago
will do thank you
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Grin
Grin2y 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
Grin2y ago
Apparently there is a right to left setting for text boxes but it only works with rtl languages, not numbers.
Grin
Grin2y 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
Grin2y ago
Grin
Grin2y ago
How is it out of bounds when the index is 0?
Grin
Grin2y ago
Every time I have a lead it drops me back to the start
Grin
Grin2y 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
Grin2y ago
There is an option in the properties of the text box called events
Grin
Grin2y ago
Where you can find a keyup event to set
Grin
Grin2y ago
Which fixes this problem
Grin
Grin2y 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
Accord2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts
❔ Something wrong with my codeSo the problem I have right now is when Yoda wins a game his message saying "Yoda wins the game" won❔ parse a single json property differentlySo i have an existing json model that i cannot retire because some users already use it. I want to bWhat am I doing wrong in Clean Architecture?I got this .sln with seperation of concerns and i have an API that is supposed to fetch string data ❔ Release mode garbage collection is much longer than debug modeI built a WPF app, and to test the lag, i'm just selecting a ListBoxItem and moving my mouse up and ❔ Getting the cookies and current Url from Webview [MAUI]I'm making a simple app where the user needs to log in the first time they're using it in WebView anWhat is the difference between these two methods? Using params or just doing everything in one class```cs public static void Main(string[] args) { int a = 2, b = 3; int sum = Add(a, b) } public s❔ How do I pull information out of a function with alot of information?**I'm getting an error in the below statement SPECIFICALLY at keySet with the error "the name 'keySe❔ Single UDP Broadcaster to Multiple ClientsI'm trying to have a single UDP Broadcast to many clients. This is what I have working so far. Idea❔ how to logout specific user with identityserverI am trying to logout an specific user from previous identity user sessions, so what could I do to ❔ The type 'Attribute' is defined in an assembly that is not referenced.On a dotnet 7 xunit template, I added specflow and the title error pops up