Because the New year home, home no net, for several months did not write. Just went back to the lab last night and wrote today.
First analyze the effect of the search box and the Personality signature column:
1, the search box in the normal Time box has a line of text to indicate the content of the search, when the left mouse button will make the text in the box empty, and have the cursor flashing;
2, Personality signature column usually also has a line of text, the content is your personality signature, when the mouse click, will make the entire box text content selection, at this time you can arbitrarily change your personality signature.
3, the two also have a common feature: when the mouse moved to the search box and the Personality signature box, the mouse will appear in the bottom of a line of prompt text.
First paste the search box code:
Front desk:
<textbox x:name="Txtbox2"Background="Gray"opacity="0.7"height=" -"Width="342"Borderbrush="Transparent"Text="Search: Contacts, discussion groups, groups, enterprises"Fontsize=" -"gotfocus="Txtbox2_gotfocus"lostfocus="Txtbox2_lostfocus"verticalcontentalignment="Center"> <TextBox.ToolTip> <ToolTip> <stac Kpanel> <TextBlock> Enter QQ number, name/nickname, pinyin, email search </TextBlock> <TextBlock> Contact person can also find strangers </TextBlock> <TextBlock> people </te through the full QQ number Xtblock> </StackPanel> </ToolTip> < /textbox.tooltip> </TextBox>
Background:
Private voidTxtbox2_gotfocus (Objectsender, RoutedEventArgs e)//gets the event that the focus executes{TextBox Txtbox2= Sender asTextBox; TempTxt2=Txtbox2. Text; Txtbox2. Text=string. Empty; Txtbox2. Background=brushes.white;//when you get the focus, change the background color of the text box to whiteTxtbox2. BorderBrush =brushes.transparent; Pic_search. Visibility= Visibility.hidden;//hide the search icon after getting focusPic_offline3. Visibility = visibility.visible;//when the focus is taken, the close icon is displayed } Private voidTxtbox2_lostfocus (Objectsender, RoutedEventArgs e)//when the focus is lost, the processed event { if(Txtbox2. text==string. Empty) {Txtbox2. Text=tempTxt2; } pic_search. Visibility= visibility.visible;//recreate the hidden icon after losing focusPic_offline3. Visibility = Visibility.hidden;//hide the close icon after losing focus}
I use the focus and lose focus to handle the effect of the search box, when the mouse click the search box, that is, to get the focus, the background box color changes to white is equivalent to emptying the search box, when the mouse click Elsewhere, the search box will lose focus, the event is the original text and search icon to restore.
Here is the code for the personalized signature box:
Front desk:
<textbox name="Txtbox1"text="working hard and living free."FontSize=" -"fontfamily="Kaiti"Background="Transparent"Borderbrush="Transparent"verticalcontentalignment="Center"previewmousedown="Txtbox1_previewmousedown"GotFocus="Txtbox1_gotfocus"lostfocus="Txtbox1_lostfocus"/>
Background:
Private voidTxtbox1_gotfocus (Objectsender, RoutedEventArgs e)//implementation: text box get focus, select text content{TextBox Txtbox1= E.source asTextBox; Txtbox1. SelectAll (); //use SelectAll Select All in the GotFocus eventTxtbox1. PreviewMouseDown-=NewMousebuttoneventhandler (Txtbox1_previewmousedown);//implementation: When you click the second time, the text is no longer selected, but the cursor is displayedTxtbox1. Background =Brushes.white; } Private voidTxtbox1_lostfocus (Objectsender, RoutedEventArgs e)//when the text box loses focus, deselect all, and the background color reverts to transparent{TextBox Txtbox1= Sender asTextBox; if(Txtbox1! =NULL) {Txtbox1. PreviewMouseDown+=NewMousebuttoneventhandler (Txtbox1_previewmousedown); } txtbox1. Background=brushes.transparent; }
The Personality signature box and the search box implement the effect of the same method, but also take focus and lost focus to deal with. When the mouse clicks on the personality signature, gets the focus, using the TextBox's SelectAll method to select all the text in the box, and to restore the original when the focus is lost.
For the two common characteristics, that is, when the mouse moved to the text box when the text can be automatically suspended under the text box, the effect is very simple, with a Tooltip on the line, you can refer to the above code, it is not detailed.
Wpf-qq Interface (iii): Contact search box and personalized signature column of the effect of the implementation