<Canvas>

  <Canvas x:Name='SigPad' Width='404' Height='152'

   Canvas.Left='8' Canvas.Top='9' Background='#FFF4F60C'>

   <Rectangle Width='404' Height='152' Fill='#FFF1F8DB'

    Stroke='#FF000000' StrokeThickness='3'/>

  </Canvas>

  <Canvas>

   <Canvas x:Name='btnSave' Width='97' Height='26'

    Canvas.Left='315' Canvas.Top='168'>

    <Rectangle Width='96' Height = '25'

     Stroke='#FF000000' Fill='#FFE6EBFF'

     RadiusX='3' RadiusY='3' StrokeThickness='3'/>

    <TextBlock Width='34' Height='20'

     TextWrapping='Wrap' Canvas.Left='32'

     Canvas.Top='1' Text ='Save'/>

   </Canvas>

   <Canvas x:Name='btnLoad' Width='97' Height='26'

    Canvas.Left='214' Canvas.Top='168'>

    <Rectangle Width='96' Height='25'

     Stroke='#FF000000' Fill='#FFE6EBFF'

     RadiusX='3' RadiusY='3' StrokeThickness='3'/>

    <TextBlock Width='37' Height='20' TextWrapping='Wrap'

     Canvas.Left='30' Canvas.Top='1' Text='Load'/>

   </Canvas>

   <Canvas x:Name='btnClear' Width='97' Height='26'

    Canvas.Left='113' Canvas.Top='168'>

    <Rectangle Width='96' Height='25' Stroke='#FF000000'

     Fill='#FFE6EBFF' RadiusX='3' RadiusY='3'

     StrokeThickness='3'/>

    <TextBlock Width='37' Height='20' TextWrapping='Wrap'

     Canvas.Left='30' Canvas.Top='1' Text='Clear'/>

   </Canvas>

   <TextBlock Width='404' Height='20' Text='[Status]'

    TextWrapping='Wrap' Canvas.Left='8' Canvas.Top='198'

    OpacityMask='#FF000000' x:Name='txtStatus'/>

  </Canvas>

 </Canvas>

</UserControl>

Page.xaml should now look like Figure 19-71.

Figure 19-71

In Page.xaml.cs, import the following namespaces:

using System.IO.IsolatedStorage;

using System.IO;

Add the following lines to the Page() constructor:

public Page() {

 InitializeComponent();

 //---wire up the event handlers---

 SigPad.MouseLeftButtonDown += new

  MouseButtonEventHandler(SigPad_MouseLeftButtonDown);

 SigPad.MouseLeftButtonUp += new

  MouseButtonEventHandler(SigPad_MouseLeftButtonUp);

 SigPad.MouseMove += new

  MouseEventHandler(SigPad_MouseMove);

 //---wire up the event handlers---

 btnSave.MouseLeftButtonDown += new

  MouseButtonEventHandler (btnSave_MouseLeftButtonDown);

 btnLoad.MouseLeftButtonDown += new

  MouseButtonEventHandler (btnLoad_MouseLeftButtonDown);

 btnClear.MouseLeftButtonDown += new

  MouseButtonEventHandler (btnClear_MouseLeftButtonDown);

}

Define the GetSignatureLines() function so that the coordinates of the signature can be converted from a List object to a string:

//---returns the signature as a series of lines---

private string GetSignatureLines() {

 System.Text.StringBuilder sb = new

  System.Text.StringBuilder();

 //---for each line---

 for (int i = 0; i <= _lines.Count - 1; i++) {

  //---for each point---

  foreach (Point pt in _lines[i]) {

   sb.Append(pt.X + ',' + pt.Y + '|');

  }

  sb.Append(' ');

 }

 return sb.ToString();

}

Code the MouseLeftButtonDown event handler for the Save button so that the signature can be saved to isolated storage:

//---Save button---

void btnSave_MouseLeftButtonDown(

 object sender, MouseButtonEventArgs e) {

 //---save into isolated storage---

 IsolatedStorageFile isoStore =

  IsolatedStorageFile.GetUserStoreForApplication();

 IsolatedStorageFileStream isoStream =

  new IsolatedStorageFileStream('IsoStoreFile.txt',

  FileMode.Create, isoStore);

 StreamWriter writer = new StreamWriter(isoStream);

 //---writes the lines to file---

 writer.Write(GetSignatureLines());

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату