WPF-21: WPF Implementation of imitation Android pattern password keyboard (improved)

Source: Internet
Author: User
I wrote a simple implementation (http://blog.csdn.net/yysyangyangyangshan/article/details/9280439), but the effect is not very good, there is no connection between each point. The connection buttons are added here.
The other code remains unchanged. Only the patternpasswordkeyboard class is modified.
/// <Summary> /// patternpasswordkeyboard. interaction logic of XAML // </Summary> Public partial class patternpasswordkeyboard: usercontrol {Public String Password = string. empty; // The final password private bool ismousedonw = false; // The private list <keybutton> keybuttons = new list <keybutton> () is valid only when the mouse is clicked (); // control private list <point> points = new list <point> (); Public patternpasswordkeyboard () {initializecomponent (); th Is. mouseup + = new mousebuttoneventhandler (mainwindow_mouseup); this. mousedown + = new mousebuttoneventhandler (mainwindow_mousedown);} // <summary> // reset /// </Summary> internal void patternpasswordkeyboard_resetpassword () {This. points. clear (); this. password = string. empty; foreach (keybutton item in keybuttons) {item. selfbacground = new solidcolorbrush (colors. transparent);} This. invalidatevis Ual ();} void mainwindow_mousedown (Object sender, mousebuttoneventargs e) {points. clear (); expose (); ismousedonw = true;} void mainwindow_mouseup (Object sender, mousebuttoneventargs e) {ismousedonw = false;} private void bordermousemove (Object sender, mouseeventargs E) {If (! Ismousedonw) {return;} keybutton border = sender as keybutton; If (border = NULL) {return;} string key = border. tag. tostring (); If (string. isnullorempty (key) {return;} border. selfbacground = new solidcolorbrush (colors. blue); keybuttons. add (Border); // Save the slide point if (! Password. contains (key) {password + = key; generaltransform = border. ellipseborder. transformtoancestor (this); point = generaltransform. transform (this. translatepoint (new point (0, 0), this); points. add (point); this. invalidatevisual () ;}} protected override void onrender (drawingcontext) {base. onrender (drawingcontext); If (points. count <2) {return;} // draw with a composite image Saved vertex pen P = new pen (New solidcolorbrush (colors. red), 10); geometrygroup group = new geometrygroup (); group. fillrule = fillrule. evenodd; linegeometry mylinegeometry = NULL; For (INT I = 0; I <points. count; I ++) {if (I % 2 = 0) {If (mylinegeometry! = NULL) {mylinegeometry. endpoint = points [I];} mylinegeometry = new linegeometry (); mylinegeometry. startpoint = points [I];} else {mylinegeometry. endpoint = points [I]; group. children. add (mylinegeometry); if (I + 1 <points. count) {mylinegeometry = new linegeometry (); mylinegeometry. startpoint = points [I]; group. children. add (mylinegeometry);} else {mylinegeometry = NULL ;}} solidcolorbrush mysolidcolorbrush = new solidcolorbrush (); drawingcontext. drawgeometry (mysolidcolorbrush, new pen (brushes. green, 10), group );}}

:

Code download: http://download.csdn.net/detail/yysyangyangyangshan/5727105

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.