How to simulate text selection by mouse in TextBox, but outside of TextBox control - winforms

Normally, in TextBox (WinForms) after hovering text by mouse cursor, keeping left button down and moving the mouse to the right or left, we can selected any text fragment (even if we move cursor take out of textbox area).
My question is how to simulate/trigger mouse text selection, but begining outside of TextBox control.
For example, let's say I have a TextBox with any text. Under this TextBox we place Panel control with this same Width and X location like textbox. Then, after left mouse button down on Panel area, it start highlighting of a piece of text in the TextBox (just like as if I did it directly over the TextBox).
So I assume that by clicking on the Panel area, special message should be sent to the TextBox, so that it starts selecting the text according to X cursor position (point Y is of course below the textbox).
Hope I was able to explain the question properly.

Related

ComboBox selects item when clicking on most bottom pixel

Clicking on the first pixel below a WPF combobox leads to an unwanted item selection, because the mouseup directly selects the item which is currently animated under the mouse cursor.
It depends on the height of the combobox, whether the pixel below is clickable or not (on my machine it was clickable if the comboboxes height is 20, not clickable if its height is 21).
Its very easy to reproduce: click multiple times on the bottom pixel and release the mouse button while the popup is animating (maybe animations must be turned on in windows performance settings...).
Does anyone know if this is a WPF bug or how I can prevent the combobox from doing this ?

Wpf Animate label text movement

I have a statusbar with three labels in it. At times the labels have to much text to fit on screen. I'd like the text of the individual labels to scroll when you mouse over them.
How would I set up the animation for this?
I can use any uneditable control that presents text instead of a label.

How to grow TextBox in WinForm?

In the WinForm I am working on, I have two TextBox widgets and one button between the text boxes. When the form starts, and the winform is at its minimum size, the TextBoxes look as expected. No gaps between the items where they come close to the button there in the center. This is as seen in the top graphic.
However, when the user maximizes the winform, the TextBoxes move to the correct position but do not expand to keep close to the button in the center. Textbox A is anchored to the left and Textbox B is anchored to the right. So the alignment is correct. This is as seen in the bottom graphic.
Now, the question is how to make text box A grow to the right so that it comes close to the button in the middle and text box B grow to the left so that it also comes close to the button?
Thanks! Eric
Use TablelayoutPanel control. From MSDN
Create TableLayoutPanel with one row and three columns
First column: SizeType: percent, 50%
Second column: SizeType: absolute, 75(button width)
Third column: SizeType: percent, 50%
Then put textboxes and button in the columns.
Set for textboxes and button property .Dock = Fill
Size of the textboxes will be automatically changed with size of the columns in the TableLayoutPanel
Set Dock property of the TableLayouPanel to Fill or Bottom or Top. Then TableLayoutPanel will change width when width of the form is changed.
With simple anchors you cannot achieve this.
But you can use a TableLayoutPanel:
Place a TableLayoutPanel on the form and set Dock to Fill (or Top/Bottom)
Make 3 columns.
Column 1: Percent, 50%
Column 2: Absolute, set the desired size of the Button (eg. 100px)
Column 3: Percent, 50%
Drop TextBoxA into Column1, and set Anchor Left and Right
Drop the Button into Column2, and clear the Anchors
Drop TextBoxB into Column3, and set Anchor Left and Right
Without a TableLayoutPanel, you can make the following:
TextBoxA: Anchored Left and Right
Button and TextBoxB: Anchored Right
So only TextBoxA will grow.
you can use the Anchor Property for Button and textbox -
Button A - Anchor - left and Right
Button B - Anchor - left and Right
you can also, set textbox anchor property as per your needs and control the location of all these three controls.

WPF Hidden ScrollViewer's Bars

I need a ScrollViewer for WPF application which like on some web pages (like Facebook), scroll bars are hidden even if content is long, but when mouse is over bars become visible. Anyone have idea how to do that?
Tnx.
MVVM focused answer:
I'm sure there is a property which allows you to hide or show the scroll bars.
Bind this property to your ViewModel.
Create a MouseOver event which fires when the mouse moves into a certain part of the screen. To do this, you could overlay an invisible grid over the screen, with the right hand 10% as the target area.
Now when the mouse enters the region, show the scrollbar, and when it exits the region, hide the scrollbar.
Ensure that you set the MinWidth on the invisible region, so that if the window gets narrow, the scrollbar trigger area is still wide enough to be usable.

How to scroll on Textbox(multiline) in C# WPF, by mouse-dragging, not by mouse-wheel?

My TextBox is read-only. and contents is increased more...
Vertical scroll bar of textbox is showed(auto), then user can scroll it by mouse-wheel. it's ok now.
But if i'm going to scroll by mouse-drag on scroll-bar's seek, it's impossible and instead of it, form is moved.
(i used metro-form using mahapp.dll)
How i can scroll the textbox contents by mouse-dragging the seek of textbox scroll-bar?

Resources