Textbox scroll to bottom in Avalonia - avaloniaui

I have a textbox that I write info to that automatically creates a scroll bar when the screen is filled, and I'd like to scroll to the bottom of it. It seems like what I need to do is set the scrollbar Offset to some vector, but my problem is finding the ScrollViewer.
I can't use FindControl because it's not named anywhere in the xaml, and I can only change a few values using textbox.SetValue

The only way to scroll a TextBox currently is to set the CaretPosition. For example to scroll to the end of the text you could use:
textbox.CaretIndex = int.MaxValue;

For me it works only when I set textbox.CaretIndex to the length of the text. Assuming that property Logs (string type) is binded to textbox I used this
textbox.CaretIndex = Logs.Length

Related

Scrolling Content to Show Current Cursor Position on NSTextView

I have an NSTextView control object wrapped with NSScrollView. What I want to do is to make the text string at the current position visible when it's hidden below the content view.
In reference to the picture above, with
NSUInteger cPosition = [[[textView1 selectedRanges] objectAtIndex:0] rangeValue].location;
[textView1 scrollRangeToVisible:NSMakeRange(0,cPosition)];
the scroll view will scroll itself to a position such that the selected string (document) will come at the bottom of the content view. (Line 11). That's not exactly what I want. I would like the scroll view to scroll itself to show the text string at the current cursor position when it's hidden below the content view (for example, at Line 14). How can I improve my code?
Muchos thankos.
One solution would be to use NSString's enumerateSubstringsInRange:options:usingBlock: method with the NSStringEnumerationByParagraphs option and passing the range that contains your cPosition to scrollRangeToVisible:. This would have the effect of making the paragraph that contains your cPosition visible.

How can I get the caret's position in xaml?

I have a few textboxs and I want to achieve this funcion: when tap into each textbox, that specific textbox will move to the top and when user type in some data it can auto scroll and keep the cursor|caret always on top of the screen. I know that I can useScrollViewer.ChangeView(null,offset,null); to set the view, however, how can I get the cursor's position (y or vertical offset) though. This is WP 8.1 app.
According to the documentation for the WPF TextBox class here, there is a property called CaretIndex which "Gets or sets the insertion position index of the caret."
You might also be able to use the value of the SelectionStart and SelectionLength properties to find where the caret is, but if the SelectionLength is larger than zero, that might not work. Try the CaretIndex property.
I did not fully understand your requirement. Currently there is no property/method to get the current caret position in the text. But if you want to move your caret at the start of the textbox than use below code.
txtbox.SelectionStart = 0;
txtbox.SelectionLength = 0;
Edit
By using txtbox SelectionStart and textbox selection length you can get caret position.
int caretIndex = txtbox.SelectionStart + txtbox.SelectionLength;

Moving label to fit according to length vb.net

Hi I have a button which will add a string in to a label. (this can be done multiple times.) As the user can add multiple strings with each one been a different length, is there anyway I can get it to find the length of the label and those around it so that it spaces out correctly?
Thanks
Label.Width will return the current width of the label control, but it sounds like you already know this. Since the label can be narrower than the text it is trying to display, you would need to measure the full text using the graphics object. This method will return the width of the text in a label:
Private Function getFullTextWidth(lbl As Label)
Using g As Graphics = Label1.CreateGraphics()
Return g.MeasureText(Label1.Text, Label1.Font).Width
End Using
End Function
Alternatively, you could just set the label's AutoSize property to true, and then just check the label's Width property after you set the Text.

WinForms TableLayoutPanel ComboBox not resizing properly

I'm trying to use a TableLayoutPanel to align a few controls on a form next to their labels like so:
Label1 [combobox ]
LongerLabel [longer combobox]
But when I run the project and grab the right hand side of the form and shrink the form, the combobox doesn't resize, it gets cut off... Now, I were to not use the TableLayoutPanel, but just anchor a combobox to a form's edges, it will resize properly. What am I doing wrong with the TableLayoutPanel?
I found the answer here:
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2006-12/msg00209.html
So I set the first column with the label to autosize (I have the label fill docked in the cell and the text alignment set to middle left). Then dock fill the combobox in the second column. Then, set the second column's size type to 100%, NOT autosize. I don't know why it works, but it does.

changing the position of textbox using code

In my form I have an AXVS Flex Grid and a Textbox. Firstly the textbox will not be visible.
When the focus is on a particular column of the flexgrid, the textbox will be visible and the Flex Grid will be disabled. The position of the text box will be at the bottom of the particular row at the first time.
But when another row is inserted, then I need to change the position of the textbox to the bottom of the new row and so on.
How can I do that? Thanks in advance.
Position of a control can be retrieved and set using the Top & Left properties of the control.
So you can get the Top,Left property of the inserted row and set the Top,Left property of TextBox accrodingly.
e.g.
TextBox1.Top = InsertedRow.Top +=10
TextBox1.Left = InsertedRow.Left
This will bring the textbox below inserted row.