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