发布于 2016-05-26 04:05:20 | 69 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


silverlight Beta 2.0 中TetBox输入汉字,除MS自己的输入法,其它所有输入法都会出现输入的东西会在TextBox中重复一次的现像,google ,Baidu了一下,大家说好像是silverlight自己的一个BUG,可能会在Repleass的时候修改。
新写一个TextBoxEx控件,继承于TextBox,并对TextBox的选择事件及字符改变事件做处理,以下是原代码

/************************************************************************/ 
/* 
作者:覃小春 
时间:20080826 
说明:解决silverlightBeta2中TextBox中文输入问题 
* blog:blog.csdn.net/colijian 
*/ 
/************************************************************************/ 
using System.Windows; 
using System.Windows.Controls; 
namespace TextBoxEx 
{ 
public class TextBoxEx:TextBox 
{ 
#region 属性 
private string _OldText = ""; 
private int _RecSelectStart = 0; 
private int _RecSelectLength = 0; 
#endregion 
public TextBoxEx() 
{ 
TextChanged += new TextChangedEventHandler(TextBoxEx_TextChanged); 
SelectionChanged += new RoutedEventHandler(TextBoxEx_SelectionChanged); 
} 
void TextBoxEx_SelectionChanged(object sender, RoutedEventArgs e) 
{ 
TextBox _sender = sender as TextBox; 
if (_sender == null) 
return; 
if (_sender.SelectionLength > 0) 
{ 
//recode user select position 
_RecSelectLength = _sender.SelectionLength; 
_RecSelectStart = _sender.SelectionStart; 
} 
else 
{ 
_RecSelectLength = 0; 
} 
} 
void TextBoxEx_TextChanged(object sender, TextChangedEventArgs e) 
{ 
TextBox _sender = sender as TextBox; 
if (_sender == null) 
return; 
string textIfnor = _sender.Text; 
#region 除去先中部份 
if (_RecSelectLength != 0) 
{ 
_OldText = _OldText.Substring(0, _RecSelectStart) + _OldText.Substring(_RecSelectStart + _RecSelectLength, _OldText.Length - _RecSelectStart - _RecSelectLength); 
_RecSelectLength = 0; 
} 
#endregion 
int LengthAdd = textIfnor.Length - _OldText.Length; 
if (LengthAdd <= 0) 
{ 
_OldText = _sender.Text; 
//这种情况是删除数据 
return; 
} 
else if (LengthAdd % 2 == 0) 
{ 
//如果当前是成双的情况下 
//得到当前字符串 
string AddInfor = textIfnor.Substring(_sender.SelectionStart - LengthAdd, LengthAdd); 
if (!AddInfor.Substring(0, AddInfor.Length / 2).Equals(AddInfor.Substring(AddInfor.Length / 2))) 
{ 
_OldText = _sender.Text; 
return; 
} 
//得到实际新增值 
AddInfor = AddInfor.Substring(0, AddInfor.Length / 2); 
//得到实际理论值 
string DealText = textIfnor.Substring(0, _sender.SelectionStart - LengthAdd) + AddInfor + textIfnor.Substring(_sender.SelectionStart, textIfnor.Length - _sender.SelectionStart); 
int RecodeSelectSTart = _sender.SelectionStart - LengthAdd / 2; 
_sender.SelectionStart = 0; 
_sender.Text = DealText; 
_sender.SelectionStart = RecodeSelectSTart; 
_OldText = DealText; 
} 
else 
{ 
_OldText = _sender.Text; 
} 
} 
} 
} 

使用:

<UserControl x:Class="MutilTextBox.Page" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:CT="clr-namespace:TextBoxEx;assembly=TextBoxEx" 
Width="400" Height="300"> 
<Grid x:Name="LayoutRoot" Background="White"> 
<Grid.RowDefinitions> 
<RowDefinition Height="50"></RowDefinition> 
<RowDefinition Height="50"></RowDefinition> 
<RowDefinition Height="50"></RowDefinition> 
<RowDefinition Height="50"></RowDefinition> 
</Grid.RowDefinitions> 
<TextBox x:Name="FirstTextBox" Text="first" Grid.Row="0" TextChanged="FirstTextBox_TextChanged"></TextBox> 
<CT:TextBoxEx x:Name="SecondTextBox" Grid.Row="1"></CT:TextBoxEx> 
<CT:TextBoxEx x:Name="ThreeTextBox" Grid.Row="2"></CT:TextBoxEx> 
<TextBox x:Name="Four" Grid.Row="3" ></TextBox> 
</Grid> 
</UserControl> 
注意:要先加入名称空间,具体的值是:
clr-namespace:名称空间全名;assembly=程序集名称
不清楚怎样上传程序集!否则将程序集上传
若发此控件有问题,或是不足,请给我留言


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务