How to select all textbox text and textbox opacity in WP application - c#

I use a textbox as an address bar for a WP browser application. I want to select all text when a user selects the textbox and also to modify the opacity.
I tried using GotFocus method to do that. I see that the whole text is selected for 1 second or so and then it is deselected. I also need to modify the opacity once the focus is on textbox and when the textbox loses focus. Using GotFocus method I can modify the opacity but when the focus is lost, when I set again the opacity percent nothing happens.
Can you give me a hint regarding the events that determine the text to be selected for a short period of time and for the opacity problem?
private void URLTextBox_GotFocus(object sender, RoutedEventArgs e)
{
URLTextBox.Opacity = 50;
URLTextbOX.SelectAll();
}
private void URLTextBox_LostFocus(object sender, RoutedEventArgs e)
{
URLTextBox.Opacity = 10;
}

You can try subscribing to one of the tunnelling events (PreviewGotKeyboardFocus and PreviewLostKeyboardFocus) instead of the GotFocus event.

Related

Copy text from one control to another whilst typing?

I have 2 controls on a Form, and I want that whilst I'm entering text in 1 control, the same text is entered in the 2 control immediately.
I've tried the following events:
KeyDown,
KeyPress,
KeyUp,
PreviewKeyDown
But they all have the same effect, ie. the second control is one character behind. These controls are bound to a bindingsource.
Is there any other event that I can use or is there any other way to do this?
EDIT:
I just saw the TextChanged event.
You can use TextChanged event. Define this event for your first control say text box, and in this event, set the text of your second control.
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.textBox2.Text = ((TextBox)sender).Text;
}

WPF TextBox's IsInactiveSelectionHighlightEnabled property is not work?

WPF's TextBox has a property named IsInactiveSelectionHighlightEnabled. I set this property to true in order to make a TextBox always show selection. However, it doesn't work in this case:
private void button_Click(object sender, RoutedEventArgs e) {
textBox.Select(0, 10);
}
I just want to see the selection after clicking the button. But selection will not appear until I right click the TextBox. Why? Am I miss something?
You should have the Keyboard focus on your textbox to select the text in it.
Add this code to your button click event before the selection.
Keyboard.Focus(textBox);
Hope it helps.

Hide keyboard Windows Phone 8.1

When I try to add a text in the TextBox from a canvas using handwriting, the cursor go to the TextBox and the keyboard shows, and I try to add some code like make the TextBox isReadonly or trying to hide the keyboard and doesn't work.
I want every time select an item from the ListBox the item add to the TextBox without showing the keyboard. the action on RecognizedListBox_SelectionChanged a ListBox
private void RecognizedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (RecognizedListBox.SelectedItem == null)
return;
//gte the selected item from listbox
string inputTextWritePad = RecognizedListBox.SelectedItem.ToString();
//add the item to RichEditBox
MyTextNote.Text += inputTextWritePad + " ";
//clear the canvas return the listbox to vide
ClearAllClick(sender, e);
}
If I add isReadonly for TextBox, it will permanent disable to edit it, and I can't add any text using keyboard. I don't know where I will put my code, or verify when I need the keyboard to use it.
I see if I need to hide the keyboard, I must have an event for the keyboard button or something like this
private void TextBox_KeyUp(object sender, KeyRoutedEventArgs e)
{
if(e.Key==Windows.System.VirtualKey.Enter)
{
Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryHide();
}
}
but nothing to figure out!!
update 1:
I add this code
private void MyTextNote_GotFocus(object sender, RoutedEventArgs e)
{
InputPane.GetForCurrentView().TryHide();
}
and help me to not show the keyboard, but I need to show it when I clicked the textbox, I try whit tapped but nothing help.
Here's a property to avoid displaying Keyboard if your TextBox receives focus programmatically :
<TextBox PreventKeyboardDisplayOnProgrammaticFocus="true"/>
Set this property to true to prevent the onscreen touch keyboard from
showing when focus is programmatically set on a text box. By default,
the onscreen touch keyboard is displayed whenever focus moves to an
editable text box and the most recent input was generated by touch.
Official Doc

focus to text box

I created a form with a label, textbox and a button. In the form load event I called the focus() function for the textbox. But when I run my code the cursor is not coming to textbox. I need the cursor to go to text box as soon as the form is loaded. How to do it?
If you simply need to make sure a certain control gets focus when you first load a form, then change the TabOrder properties of all your controls (in the Designer) so that the control in question is '0', and the other elements are going up from there, '1', '2', etc.
If you need to dynamically select a different control when you show a form depending on some condition, then use the following code:
private void Form1_Load(object sender, EventArgs e) {
// You need to show the form otherwise setting focus does nothing
// (there are no controls to set focus to yet!)
this.Show()
if (someCondition == true)
control.Focus();
else
control2.Focus();
}
Handle the Shown event instead. This code should work.
private void Form1_Shown(object sender, EventArgs e)
{
textBox2.Focus();
}
Don't call Focus in the Load event. Call it in the Activate event. That would work
You can set the TabIndex property of textbox to 0 if you always want the focus on textbox when form loads. (This property is always eventually set in the form.designer.cs. And you won't have to write any extra code in your form.cs.)

Tooltip not displaying, flashes when control is clicked

I have a check box that is disabled that should be showing a tooltip when hovered over, but instead nothing happens. Once the checkbox is clicked on the tooltip shows momentarily then flashes on and off very fast. What could be causing this?
The tooltip should also be showing for every control involved, but shows for some and not others eventhough the tooltip is explicitly set for all controls. What could be causing this behavior?
Here is the event handler:
this.MouseHover += new EventHandler(OrderSummaryDetails_MouseHover);
void EventHandler_MouseHover(object sender, EventArgs e)
{
if (someCondition)
{
this.mFormTips.Show("Please open order form to manually modify this order", this);
}
}
I can't be positive, but if using WinForms, and you have your checkbox disabled (as in not enabled), then the checkbox will not receive events. This will cause tooltips not to show up properly.
I had the exact same problem before with a image button and what I ended up having to do was to create a gray scale of the image and swap it out when I wanted the button to be "disabled". I had to add the tooltip to the button and the image (two separate UI elements) and swap out the UI elements.
I added a MouseMove event and applied it to all the controls.
void OrderSummaryDetails_MouseMove(object sender, MouseEventArgs e)
{
Control control = GetChildAtPoint(e.Location);
if (control != null)
{
string toolTipString = mFormTips.GetToolTip(control);
this.mFormTips.ShowAlways = true;
// trigger the tooltip with no delay and some basic positioning just to give you an idea
mFormTips.Show(toolTipString, control, control.Width / 2, control.Height / 2);
}
}

Categories

Resources