Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

//---fired when the user clicks on the Signature pad---

void SigPad_MouseLeftButtonDown(

object sender, MouseButtonEventArgs e) {

//---record that the mouse left button is pressed---

MouseDown = true;

//---create a new instance of _points and _lines to

// record all the points drawn---

_points = new List();

//---save the current point for later use---

_previouspoint = e.GetPosition(SigPad);

//---add the point---

_points.Add(_previouspoint);

}

The MouseLeftButtonUpevent is fired when the user releases the left mouse button. You interpret that as the end of the signature signing process. Code the MouseLeftButtonUpevent handler of SigPadas follows:

//---fired when the user let go of the left mouse button---

void SigPad_MouseLeftButtonUp(

object sender, MouseButtonEventArgs e) {

//---user has let go of the left mouse button---

MouseDown = false;

//---add the list of points to the current line---

_lines.Add(_points);

}

The MouseMoveevent is fired continuously when the user moves the mouse. Here, you draw a line connecting the previous point with the current point. Code the MouseMoveevent handler of SigPadas follows:

//---fired when the left mouse button is moved---

void SigPad_MouseMove(object sender, MouseEventArgs e) {

//---if left mouse button is pressed...---

if (MouseDown) {

//---add the current point---

var currentPoint = e.GetPosition(SigPad);

_points.Add(currentPoint);

//---draws a line connecting the previous

// point and the current point---

Line line = new Line() {

X1 = _previouspoint.X,

Y1 = _previouspoint.Y,

X2 = currentPoint.X,

Y2 = currentPoint.Y,

StrokeThickness = 2,

Stroke = new SolidColorBrush(Colors.Black)

};

//---add the line to the signature pad---

SigPad.Children.Add(line);

//---saves the current point for later use---

_previouspoint = currentPoint;

}

}

Press F5 to test the application. Use your mouse to draw on the web page (see Figure 19-70).

Figure 1970 Saving the Signature to Isolated Storage This section explains how - фото 440

Figure 19-70

Saving the Signature to Isolated Storage

This section explains how to store the coordinates of the signature using isolated storage. This technique is useful if you need to persist information on the client side, such as backing up the signature that the user has signed.

Using the same project created in the previous section, add the following highlighted code to Page.xaml:

xmlns="http://schemas.microsoft.com/client/2007"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Width="400" Height="300">

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

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

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

Stroke="#FF000000" Fill="#FFE6EBFF"

RadiusX="3" RadiusY="3" StrokeThickness="3"/>

TextWrapping="Wrap" Canvas.Left="32"

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

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

Stroke="#FF000000" Fill="#FFE6EBFF"

RadiusX="3" RadiusY="3" StrokeThickness="3"/>

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

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

Fill="#FFE6EBFF" RadiusX="3" RadiusY="3"

StrokeThickness="3"/>

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

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

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

Page.xamlshould now look like Figure 19-71.

Figure 1971 In Pagexamlcs import the following namespaces using - фото 441

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("\n");

}

return sb.ToString();

}

Code the MouseLeftButtonDownevent 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());

txtStatus.Text = "Signature saved!";

writer.Close();

isoStream.Close();

}

Define the DrawSignature()subroutine so that the signature can be reproduced from a string representing a collection of lines:

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x