当发生MouseLeave事件时,再次调用ApplyNewImprintColor方法,还原当前选择的水印颜色。
拖拉操作
不同的字体有不同的度量标准,当用户改变字体时,水印信息的布局不会总是那么理想,为了弥补这个缺陷,我们添加了一个功能,允许用户自行对浮动TextBlock进行拖拉操作,使其布局趋于美观,在Silverlight 1.0下要实现拖拉操作非常麻烦,但在Silverlight 2下就显得轻松多了,因为我们要做的就是从Silverlight帮助文件中拷贝粘贴代码就行了。
Silverlight 2文本拖拉操作
public void TextBlock_MouseDown(object sender, MouseEventArgs args)
{
TextBlock item = sender as TextBlock;
mouseVerticalPosition = args.GetPosition(null).Y;
mouseHorizontalPosition = args.GetPosition(null).X;
isMouseCaptured = true;
item.CaptureMouse();
}
public void TextBlock_MouseMove(object
sender, MouseEventArgs args)
{
TextBlock item = sender as TextBlock;
if (isMouseCaptured)
{
// Calculate the current position of the object.
double deltaV = args.GetPosition(null).Y
- mouseVerticalPosition;
double deltaH = args.GetPosition(null).X
- mouseHorizontalPosition;
double newTop = deltaV + (double)item.GetValue
(Canvas.TopProperty);
double MaxTop = cnvImprintArea.ActualHeight - item.ActualHeight;
double MaxLeft = cnvImprintArea.ActualWidth - item.ActualWidth;
//Put in some limitations to prevent a user from
//dragging a TextBlock outside the imprint area
if (newTop > MaxTop)
{
newTop = MaxTop;
}
if (newTop < 0)
{
newTop = 0;
}
double newLeft = deltaH +
(double)item.GetValue(Canvas.LeftProperty);
if (newLeft > MaxLeft)
{
newLeft = MaxLeft;
}
if (newLeft < 0)
{
newLeft = 0;
}
// Set new position of object.
item.SetValue(Canvas.TopProperty, newTop);
item.SetValue(Canvas.LeftProperty, newLeft);
// Update position global variables.
mouseVerticalPosition = args.GetPosition(null).Y;
mouseHorizontalPosition = args.GetPosition(null).X;
}
}
public void
TextBlock_MouseUp(object sender, MouseEventArgs args)
{
TextBlock item = sender as TextBlock;
isMouseCaptured = false;
item.ReleaseMouseCapture();
mouseVerticalPosition = -1;
mouseHorizontalPosition = -1;
}
|
自定义字体
婚礼策划师通常喜欢在打印时使用script-type字体,虽然Silverlight 2包括了大量的具有吸引力的字体,但它们都不太适合婚礼设计使用,幸运的是,在你的Silverlight 应用程序中可以包括自定义的字体,只需要简单的两步就可以完成:
将自定义字体拷贝到Web应用程序的Client Bin文件夹下注意:不是Silverlight项目的Client Bin文件夹)
使用[FileName]#[FontName]格式引用你的字体,如:brushscn.ttf#BrushScript BT
Silverlight 2中使用自定义字体
//Using a custom font in Silverlight requires a combination of the filename
//along with the technical font name
string m_strAlexiCopperplate = @"alcoppln.ttf#Alexei Copperplate";
string m_strBrushScript = @"brushscn.ttf#BrushScript BT";
string m_strFlemishScript = @"flemscrn.ttf#FlemishScript BT";
string m_strFreestyle = @"frestysn.ttf#FreestyleScrD";
string m_strLinus = @"linusn.ttf#Linus";
string m_strParkAvenue = @"parkaven.ttf#ParkAvenue BT";
string m_strShelleyAllegro = @"shlyalln.ttf#ShelleyAllegro BT";
string m_strWeddingText = @"wedtxtn.ttf#WeddingText BT";
public void setFontFamilyProperty(string strFontFamily)
{
try
{
string strSelectedFontFamily;
switch (strFontFamily)
{//When a given case contains two entries,
the upper entry come from a selection in the combo box
//Lower entries come from saved designs
(some are identical, in which case only a
single entry is required)
case "Alexei Copperplate":
strSelectedFontFamily = m_strAlexiCopperplate;
break;
case "Brush Script":
case "BrushScript BT":
strSelectedFontFamily = m_strBrushScript;
break;
case "Flemish Script":
case "FlemishScript BT":
strSelectedFontFamily = m_strFlemishScript;
break;
case "Freestyle":
case "FreestyleScrD":
strSelectedFontFamily = m_strFreestyle;
break;
case "Linus":
strSelectedFontFamily = m_strLinus;
break;
case "Park Avenue":
case "ParkAvenue BT":
strSelectedFontFamily = m_strParkAvenue;
break;
case "Shelley Allegro":
case "ShelleyAllegro BT":
strSelectedFontFamily = m_strShelleyAllegro;
break;
case "Wedding Text":
case "WeddingText BT":
strSelectedFontFamily = m_strWeddingText;
break;
default:
strSelectedFontFamily = m_strAlexiCopperplate;
break;
}
txbFirstName.FontFamily = new FontFamily(strSelectedFontFamily);
txbAndCharacter.FontFamily = new FontFamily(strSelectedFontFamily);
txbSecondName.FontFamily = new FontFamily(strSelectedFontFamily);
txbEventDate.FontFamily = new FontFamily(strSelectedFontFamily);
//Display the message about Drag and Drop capability
bdrTooltips.Visibility = Visibility.Visible;
txbTooltips.Text = "Imprints can be repositioned by dragging.";
//Set a timer to hide the message about Drag and Drop
m_dtDragAndDropMessageTimer.Interval =
new
TimeSpan(0, 0, 0, 10, 0);
// 10 Seconds
m_dtDragAndDropMessageTimer.Tick += new
EventHandler(dtDragAndDropMessageTimer_Tick);
m_dtDragAndDropMessageTimer.Start();
}
Catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
}
|
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。