✅ Can you make labels scroll alongside input?
Hey, so I'm rather new to C# in general, we've been learning it in a course to play around with things like OpenGL or Unity eventually, but for now there's the classic programming assignment of making a calculator;
I've more or less got the logic of it down.. What i've currently done is that i've made all the buttons add certain characters to the label_display.text property, and i've made some validation that the user does not enter dumb stuff like "9*+-25", then i parse this string and turn it into tokens of values and operators, turn the normally infix expression to postfix and then evaluate that expression and overwrite label_display.text with the result.
-- intro ends here
So i've made this label scroll from right to left, though what happens if i make an expression too long, the text just goes outside of the label and you can't see new input :( I wanna know if i could possibly make the text follow the end of the string, but i'm not sure how since i'm still very unfamiliar with winforms
Some of the results can also get too long and get cut off by the label size. I wonder if i can truncate a number to scientific notation?
30 Replies
for example in this image, there is a number (65) after that multiplication, while it is saved in the text property, the issue is just that i cant display it properly
im unfamiliar with winforms, but woudnt it be enough to align the text to the right?
so the text overflows to the left
but tbh overflowing in general is ugly.. either reduce fontsize if text gets to big or make the textfield scrollable
I agree that smaller font would be best, and/or a scroll bar for it.
Otherwise, if you don't like those ideas, you mention it's a label, so it might help if the text goes into a text box component instead of a label, then right align might do it automatically. Users could also type in the numbers directly, but be careful they don't type in random C# code that you execute If it is a label, autosize, text align right, and anchor right, should let it extend to the left as it gets longer, and then it would end up under the gray area if z-ordered correctly and 'cut off' the left side
Otherwise, if you don't like those ideas, you mention it's a label, so it might help if the text goes into a text box component instead of a label, then right align might do it automatically. Users could also type in the numbers directly, but be careful they don't type in random C# code that you execute If it is a label, autosize, text align right, and anchor right, should let it extend to the left as it gets longer, and then it would end up under the gray area if z-ordered correctly and 'cut off' the left side
Ah crud, i didn't get any notifications at all so i couldn't even read this yesterday..
i was trying to avoid textboxes because i wanted to completely prevent user input and do some validation with the buttons seperately, but it might be possible to just make a textbox that is scrollable so you can read over the entire expression
So currently i've followed the advice of setting the label to autosize, having the text align MiddleRight, and anchoring it to the right..
i dont think this is what was supposed to happen
values after 8 are just gone
i've done all the fancy notation conversion stuff and it's the labels that catch me out >.>
the part i currently don't understand from D.Mentia's answer is the z-ordering and "cutting off the left side", gonna have to look into how that works
Ah, they're basically layers, from what i understand, but i'm not exactly sure what i gotta change in the code or in the design to get this to work
@D.Mentia bloop, sorry for the ping, really wish i could've just answered immediately :(
i was following the thread, what is wrong with my phone notifications? that's an issue to be solved later
Oh my god i am stupid, i've figured it out
why was i using right to left false?.. yeah now that its back to being left to right and is just (aligned) right, it actually works
alright then, issue solved, i was just being a brainlet
Thanks for the help :)
or not, i spoke way too soon, having RTL enabled while doing text alignment to the right does some wacky stuff to the way its displayed
ah, i guess i can make a new thread, i kinda mishandled this one
what exactly are you setting for RTL?
RTL is for languages where you read text from right to left.. if you are really changing the floworientation that will cause the whacky behavior..
if you dont want to create a textbox, fine, use a lable, set the dimensions/anchors and then set textalign to right.. more shouldnt be necessary
There's a property to set leftToRight to false, the issue i ran into is that if i set it to true, it would behave strangely with textAlign right
because in a rtl context right textalign is left
ah, i assumed that right meant right..
though the thing is
if i do set it to left, the value will go, well, left
i wanted it to be on the right, since that's usually how calculators display numbers
so i did something like RTL = false, textAlign = right, but that doesn't really scroll well
first picture is in the winforms designer with the settings (2nd pic)
3rd pic is when running you can see that its on the right side automatically
maybe its just the designer throwing you off?
or are you messing with the control through code?
discord's kinda thrown me off here, i'm not really sure what the order of the images is
big one 1 topright 2 bottom right 3
ah i see
what my issue was is something like this, i have text aligned to right so the number is to the right, but when the string is too long, you just cant see any new characters
i wanted it to "focus" on the last character so the user can see what they're typing for longer expressions
start the applicatiuon
same issue, there's characters after to the right
weird
can you put the project on github or so?
lets see if its small enough for me to just chuck through discord with a zip
iiiiiih.. i really dont wanna open files send through discord
yeah that's fair
i am a bit hesitant to share it too, just in case i put something personally identifiable in there
aight, since you seem like a nice guy, you can send it via dm
what i'm doing for this in terms of input is that i take the textBox's text property and += a character to it depending on the button
could that be causing issues?
dunno, thats what i want to find out
as written in the beginning, im not oo familiar with winforms but i know enough to play around
in case someone reads this in the future the solution wasto set the selectionstart property to the end of text
Stack Overflow
TextBox.TextAlign right-side alignment has no effect in certain con...
I have a path selector in my Visual C# Express 2010 form application.
I do it using a FolderBrowserDialog and a (single line) TextBox, to show the selected path. Using the following line in my UI
Personally i did it by putting textbox.selectionstart to be the same as textbox.text.length in a textbox_textChanged method