让WPF应用最小到系统托盘?可以调用System.Windows.Forms.NotifyIcon来实现,下面是示例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
public partial class MainWindow : Window { private NotifyIcon notifyIcon; public MainWindow() { InitializeComponent(); this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "系统监控中... ..."; this.notifyIcon.ShowBalloonTip(2000); this.notifyIcon.Text = "系统监控中... ..."; this.notifyIcon.Icon = new System.Drawing.Icon(@"AppIcon.ico"); this.notifyIcon.Visible = true; //打开菜单项 System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open"); open.Click += new EventHandler(Show); //退出菜单项 System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit"); exit.Click += new EventHandler(Close); //关联托盘控件 System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { open, exit }; notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen); this.notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler((o, e) => { if (e.Button == MouseButtons.Left) this.Show(o, e); }); } private void Show(object sender, EventArgs e) { this.Visibility = System.Windows.Visibility.Visible; this.ShowInTaskbar = true; this.Activate(); } private void Hide(object sender, EventArgs e) { this.ShowInTaskbar = false; this.Visibility = System.Windows.Visibility.Hidden; } private void Close(object sender, EventArgs e) { System.Windows.Application.Current.Shutdown(); } } |
运行时发现,程序一定要能找到ICON,否则会报错,并且ICON还没包含到程序中,需要一个额外的ICON来做托盘图标。当然这个都是能解决的:
1 |
this.notifyIcon.Icon = new System.Drawing.Icon(@"AppIcon.ico"); |
将以上一句替换成下面内容,意思就是读取程序图标,来作为托盘图标
1 |
this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath); |
运行,搞定,这样你的程序就不用拖着一个ICON文件当累赘了。 from:https://www.cnblogs.com/ke10/archive/2012/11/16/NotifyIcon.html
View Details就本人而言,C#中关闭应用主要有以下途径: 1.Close():关闭当前窗口,可以在OnClosing和 OnClosed中捕获消息,在OnClosing的时候,可以取消关闭窗口 2.Application.Current.Shutdown()/App.Current.Shutdown(): 关闭当前程序,如果有其他线程没有结束,不会关闭 3.Environment.Exit(0):强制退出,即使有其他的线程没有结束 4.Process类的CloseMainWindow, Kill:Process.CloseMainWindow是GUI程序的最友好结束方式,从名字上就可以看出来它是通过结束主窗体,相当于用户点击窗体的关闭按钮或者按Alt + F4 5.Environment类的FailFast:这是最暴力最彻底最直接的方法,一般不建议使用 现对各方式做简单的介绍: Close():如过调用了Close,而在Closing中没有显示的取消退出,则系统可以退出,这种情况仅仅是在没有多余线程,没有其他窗口启动的时候,如果有其他窗口同时启动,则要考虑App.Current.ShutdownMode。 Application.Current.Shutdown()/App.Current.Shutdown():其使用讲究最多。 在WPF应用程序的关闭是有ShutdownMode属性设置,具有3中枚举类型的值: 1)OnLastWindowClose(默认值)—应用程序最后一个窗体关闭时关闭应用程序 2)OnMainWindowClose—应用程序主窗体关闭时关闭应用程序 3)OnExplicitShutdown—显示调用关闭 示例如下: <Application x:Class="TestApplication.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22 StartupUri="Window1.xaml" ShutdownMode="OnMainWindowClose"> </Application> Environment.Exit(0):Environment.Exit相当于在Main函数中的return指令。不过它不会执行代码块的finally块(如果有的话),但资源清理还是要进行的。它是最常见的退出当前进程的方法之一。在Main函数中我们可以直接return语句便退出了程序。如果不在Main函数内,那么Environment.Exit方法就可以派上用场。 示例如下: private void CloseApp() { CloseSignal(); AppManager.Instance.Close(); Environment.Exit(0); } Environment类的FailFast:此方法更速度,它甚至不需要向操作系统返回进程退出代码(ExitCode),直接结束当前进程并在应用程序事件薄中写入信息,用于程序出现致命错误需要立即停止。 Process.Kill:从名字也可以看出来,直接杀掉,不给喘息喘息机会,Kill方法会直接结束整个进程,不进行常规资源清理(什么finally块等……)。Kill本质调用本地API:TerminateProcess函数。 from:http://blog.csdn.net/nncrystal/article/details/36422785
View DetailsWPF在样式定义和UI动画上面相对于以前的技术有了不少的提升,下面给出WPF技术实现钟表的效果: 1、Visual Studio新建一个WPF应用程序,命名为WpfClock,新建一个images文件夹,并准备一个钟表的背景图片和程序图标素材。 2、编辑MainWindow.xaml文件,对UI进行定制,代码如下(指针都是用Rectangle实现的,当然可以用图片代替):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<Window x:Class="WpfClock.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Margin="2" Height="327" Width="311" AllowsTransparency="True" WindowStyle="None" Background="Transparent" WindowStartupLocation="CenterScreen" Icon="images/clock.ico" ResizeMode="NoResize" Topmost="False" Opacity="1"> <Grid Width="300" Height="300" MouseLeftButtonDown="Grid_MouseLeftButtonDown"> <Image Source="images/backGround.png"></Image> <Label Name="lab商标" Foreground="White" Margin="0,0,0,211" HorizontalAlignment="Center" VerticalAlignment="Bottom" Height="Auto" Width="Auto" FontSize="13" >JackMoon</Label> <Label Name="lab创建时间" Foreground="White" Margin="0,91,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Height="Auto" Width="Auto">1987</Label> <!-- 秒针定义 --> <Rectangle Margin="150,0,149,150" Name="rectangleSecond" Stroke="White" Height="120" VerticalAlignment="Bottom" Width="1"> <Rectangle.RenderTransform> <RotateTransform x:Name="secondPointer" CenterX="0" CenterY="120" Angle="0" /> </Rectangle.RenderTransform> </Rectangle> <!-- --> <!-- 分钟定义 --> <Rectangle Margin="150,49,149,151" Name="rectangleMinute" Stroke="LightGreen" Width="1"> <Rectangle.RenderTransform> <RotateTransform x:Name="minutePointer" CenterX="0" CenterY="100" Angle="45" /> </Rectangle.RenderTransform> </Rectangle> <!-- --> <!-- 时针定义 --> <Rectangle Margin="150,80,149,150" Name="rectangleHour" Stroke="LightYellow" Width="1"> <Rectangle.RenderTransform> <RotateTransform x:Name="hourPointer" CenterX="0" CenterY="70" Angle="90" /> </Rectangle.RenderTransform> </Rectangle> <!----> <Label Content="08:08:08" FontSize="16" Foreground="White" Height="Auto" HorizontalAlignment="Center" Margin="114,0,113,86" Name="labTime" VerticalAlignment="Bottom" Width="Auto" /> </Grid> </Window> |
3、编辑MainWindow.xaml.CS文件,对后台逻辑进行定制,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfClock { using System.Threading; using System.Windows.Threading; /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { //计时器 System.Timers.Timer timer = new System.Timers.Timer(1000); public MainWindow() { InitializeComponent(); #region 初始化时间 secondPointer.Angle = DateTime.Now.Second * 6; minutePointer.Angle = DateTime.Now.Minute * 6; hourPointer.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5); this.labTime.Content = DateTime.Now.ToString("HH:mm:ss"); #endregion timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Enabled = true; } private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //进行拖放移动 this.DragMove(); } private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //UI异步更新 this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => { //秒针转动,秒针绕一圈360度,共60秒,所以1秒转动6度 secondPointer.Angle = DateTime.Now.Second * 6; //分针转动,分针绕一圈360度,共60分,所以1分转动6度 minutePointer.Angle = DateTime.Now.Minute * 6; //时针转动,时针绕一圈360度,共12时,所以1时转动30度。 //另外同一个小时内,随着分钟数的变化(绕一圈60分钟),时针也在缓慢变化(转动30度,30/60=0.5) hourPointer.Angle = (DateTime.Now.Hour * 30)+ (DateTime.Now.Minute * 0.5); //更新时间值 this.labTime.Content = DateTime.Now.ToString("HH:mm:ss"); })); } } } |
4、编译运行,如果运气不错的话,应该能显示如下效果: 5、总结 WPF可以用RotateTransform中的Angle进行旋转,可以指定中心点(CenterX,CenterY)
1 2 3 |
<Rectangle.RenderTransform> <RotateTransform x:Name="hourPointer" CenterX="0" CenterY="70" Angle="90" /> </Rectangle.RenderTransform> |
from:https://www.cnblogs.com/isaboy/p/wpfclock.html
View Details简介 但凡涉及到图形界面,往往的设计都是不支持或者不推荐使用多个线程操作界面内容.而且通常会有一个专门的线程调度器来处理任务线程和界面线程的问题.下面提供两个两个方案. 使用Dispatcher.BeginInvoke 这个方法简单暴力适合小工作量的修改一些界面内容.使用Dispatcher.BeginInvoke()会将代码安排为调度程序的一个任务. 步骤 使用Thread新建并开始一个线程 在新建的线程处理函数中需要修改界面的时候获取界面的dispatcher 使用Dispatcher的BeginInvoke方法指定一个线程优先级,和一个委托,这个委托时用于修改界面内容的 下面给出一部分代码
1 2 3 |
//新建线程 Thread thread = new Thread(UpdateTextRight); thread.Start(); |
下面是新线程中的方法
1 2 3 4 5 6 7 8 9 10 |
//这个事例刚好是先窗体类中定义的,所以获取Dispatcher变得比较方便,而且使用了匿名委托.在通常的代码中会把委托给分离出去比较好. private void UpdateTextRight() { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { txt.Text = "Here is some new text."; } ); } |
使用BackgroupWorker 这个类是专门用于简化Windows Form程序与线程相关的问题设计的,同样适用于WPF程序.适合于一个长期的后台进程,支持进度通知,取消支持,完成通知等功能. 使用方法也很简单,创建一个BackfruopWorker实例,它有几个事件. DoWork事件会在另外一个线程中执行,用RunWorkerAsync()启动.所以在这个事件中不要去处理修改界面的事情 RunWorkerCompleted事件,在DoWork事件返回时(正常或者异常返回),在图形的线程中执行,所以可以修改界面 ProgressChanged事件,使用ReportProgress()方法调用,同时是在图形界面的线程中执行,通常负责修改一下进度条什么的.而ReportProgress()方法,通常会在DoWork的事件中调用,然后给一个百分比的值.要使用这个功能,需要把WorkerReportsProgress属性设置成true 另外值得一说的是,要取消支持需要把WorkerSupportsCancellation属性设为true,使用CancelAsync()方法调用,但是这个调用不会终止进程,所以在DoWork事件中需要判断CancellationPending. 下面给出部分代码 创建BackgroundWorker实例
1 2 3 4 5 6 7 8 9 10 11 |
BackgroundWorker backgroundWorker; backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += backgroundWorker_DoWork; backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; //可以返回工作进度 backgroundWorker.WorkerReportsProgress = true; backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged; //允许取消 backgroundWorker.WorkerSupportsCancellation = true; |
开始执行DoWork
1 |
backgroundWorker.RunWorkerAsync(); |
DoWork事件范例,这个方法的内容是在另外一个线程,异步执行得
1 2 3 4 5 6 7 8 9 10 11 |
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { while(!backgroundWorker.CancellationPending) { //Do SomeThing //在合适的时候使用 //backgroundWorker.ReportProgress(i); //报告一下进度,其中i是0-100的整数 } //这里可以使用e.Result给一个返回值,如果有需要的话 } |
进度改变时的处理事件,也就是修改一下进度条什么的
1 2 3 4 |
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar.Value = e.ProgressPercentage; } |
完成事件我就不演示,下面是取消任务的方法
1 2 3 4 |
private void cmdCancel_Click(object sender, RoutedEventArgs e) { backgroundWorker.CancelAsync(); } |
https://www.cnblogs.com/atskyline/archive/2012/06/22/2558516.html
View Details这个问题似乎以前碰到过,不过记不太清了。 程序重新生成,提示错误:在证书存储区中找不到清单签名证书。 可能是之前部署的程序证书被我删掉了或是证书过期了,结果出现这个问题。解决方案如下: 方案1:右击项目属性—>签名—>为ClickOnce清单签名,将勾掉的选项去掉。 方案2:在签名中创建一个新的签名。 方案3:记事本打开相应的csproj文件,调整节点值。<SignManifests>true</SignManifests>将true修改为false。 以上解决方案任选其一,我选了方案一,简单嘛。重新生成,问题搞定! from:https://www.cnblogs.com/190196539/archive/2011/12/03/2272861.html
View Details1、ArrarList 转换为 string[] ArrayList list = new ArrayList(); list.Add("aaa"); list.Add("bbb"); //转换成数组 string[] arrString = (string[])list.ToArray(typeof( string)); 2、string[] 转换为 ArrarList ArrayList list = new ArrayList(new string[] { "aaa", "bbb" }); 3、ArrayList 转换为 string ArrayList list = new ArrayList(); list.Add("aaa"); list.Add("bbb"); //转换成数组 string str= string.Join(",", (string[])list.ToArray(typeof( string))); 4、string 转换为 ArrayList string str="1,2,3,4,5"; ArrayList b = new ArrayList( str.Split(',') ); from:https://www.cnblogs.com/stone_w/archive/2012/03/21/2409357.html
View Details表示伪随机数生成器,这是一种能够产生满足某些随机性统计要求的数字序列的设备。 若要浏览此类型的.NET Framework 源代码,请参阅 Reference Source。 命名空间: System 程序集: mscorlib(位于 mscorlib.dll) 继承层次结构 System.Object System.Random 语法 C#
1 2 3 |
[SerializableAttribute] [ComVisibleAttribute(true)] public class Random |
构造函数 名称 说明 Random() 新实例初始化 Random 类,使用依赖于时间的默认种子值。 Random(Int32) 新实例初始化 Random 类,使用指定的种子值。 方法 名称 说明 Equals(Object) 确定指定的对象是否等于当前对象。(继承自 Object。) Finalize() 在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。(继承自 Object。) GetHashCode() 作为默认哈希函数。(继承自 Object。) GetType() 获取当前实例的 Type。(继承自 Object。) MemberwiseClone() 创建当前 Object 的浅表副本。(继承自 Object。) Next() 返回一个非负随机整数。 Next(Int32) 返回一个小于所指定最大值的非负随机整数。 Next(Int32, Int32) 返回在指定范围内的任意整数。 NextBytes(Byte[]) 用随机数填充指定字节数组的元素。 NextDouble() 返回一个大于或等于 0.0 且小于 1.0 的随机浮点数。 Sample() 返回一个介于 0.0 和 1.0 之间的随机浮点数。 ToString() 返回表示当前对象的字符串。(继承自 Object。) 说明 若要查看此类型的.NET Framework 源代码,请参阅 Reference Source。 您可以浏览源代码、 下载脱机查看参考资料和调试; 在逐句通过源 (包括修补程序和更新)see instructions. 伪随机数字从一组有限的数字选择以相同的概率。 因为数学算法可用于选择它们,但它们是充分随机实用的角度而言,所选的数字不完全随机的。 当前实现 Random 类根据 Donald E.Knuth 删减随机数生成器算法的修改版本。 有关详细信息,请参阅 D.e。 Knuth。 计算机编程,卷 2 的艺术︰ Seminumerical 算法。 Addison-wesley,Reading,MA,第三个版本,1997年。 若要生成加密性极安全的随机数字,如一个适合于创建随机密码,使用 RNGCryptoServiceProvider 类或从派生类 System.Security.Cryptography.RandomNumberGenerator。 在本主题中: 实例化的随机数字生成器 避免多个实例化 System.Random 类和线程安全 生成不同类型的随机数字 替换您自己的算法 如何使用到 System.Random… 检索相同的随机值序列 检索唯一的随机值序列 […]
View DetailsC# DateTime与时间戳的相互转换,包括JavaScript时间戳和Unix的时间戳。 1. 什么是时间戳 首先要清楚JavaScript与Unix的时间戳的区别: JavaScript时间戳:是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数。 Unix时间戳:是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。 可以看出JavaScript时间戳总毫秒数,Unix时间戳是总秒数。 比如同样是的 2016/11/03 12:30:00 ,转换为JavaScript时间戳为 1478147400000;转换为Unix时间戳为 1478147400。 2. JavaScript时间戳相互转换 2.1 C# DateTime转换为JavaScript时间戳 1 2 3 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 long timeStamp = (long)(DateTime.Now – startTime).TotalMilliseconds; // 相差毫秒数 System.Console.WriteLine(timeStamp); 2.2 JavaScript时间戳转换为C# DateTime 1 2 3 4 long jsTimeStamp = 1478169023479; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 DateTime dt = startTime.AddMilliseconds(jsTimeStamp); System.Console.WriteLine(dt.ToString("yyyy/MM/dd HH:mm:ss:ffff")); 3. Unix时间戳相互转换 3.1 C# DateTime转换为Unix时间戳 1 2 3 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 long timeStamp = (long)(DateTime.Now – startTime).TotalSeconds; // 相差秒数 System.Console.WriteLine(timeStamp); 3.2 Unix时间戳转换为C# DateTime 1 2 3 4 longunixTimeStamp = […]
View Details1.Math.Round:四舍六入五取偶
1 2 3 4 5 6 7 8 9 10 |
Math.Round(0.0) //0 Math.Round(0.1) //0 Math.Round(0.2) //0 Math.Round(0.3) //0 Math.Round(0.4) //0 Math.Round(0.5) //0 Math.Round(0.6) //1 Math.Round(0.7) //1 Math.Round(0.8) //1 Math.Round(0.9) //1 |
说明:对于1.5,因要返回偶数,所以结果为2。 2.Math.Ceiling:只要有小数都加1
1 2 3 4 5 6 7 8 9 10 |
Math.Ceiling(0.0) //0 Math.Ceiling(0.1) //1 Math.Ceiling(0.2) //1 Math.Ceiling(0.3) //1 Math.Ceiling(0.4) //1 Math.Ceiling(0.5) //1 Math.Ceiling(0.6) //1 Math.Ceiling(0.7) //1 Math.Ceiling(0.8) //1 Math.Ceiling(0.9) //1 |
说明:例如在分页算法中计算分页数很有用。 3.Math.Floor:总是舍去小数
1 2 3 4 5 6 7 8 9 10 |
Math.Floor(0.0) //0 Math.Floor(0.1) //0 Math.Floor(0.2) //0 Math.Floor(0.3) //0 Math.Floor(0.4) //0 Math.Floor(0.5) //0 Math.Floor(0.6) //0 Math.Floor(0.7) //0 Math.Floor(0.8) //0 Math.Floor(0.9) //0 |
from:https://www.cnblogs.com/rwh871212/p/6962099.html
View Detailspublic enum StringComparison { CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase } CurrentCulture 使用区域敏感排序规则和当前区域比较字符串。 CurrentCultureIgnoreCase 使用区域敏感排序规则、当前区域来比较字符串,同时忽略被比较字符串的大小写。 InvariantCulture 使用区域敏感排序规则和固定区域比较字符串。 InvariantCultureIgnoreCase 使用区域敏感排序规则、固定区域来比较字符串,同时忽略被比较字符串的大小写。 Ordinal 使用序号排序规则比较字符串。 OrdinalIgnoreCase 使用序号排序规则并忽略被比较字符串的大小写,对字符串进行比较。 1.首先是StringComparison.Ordinal 在进行调用String.Compare(string1,string2,StringComparison.Ordinal)的时候是进行非语言(non-linguistic)上的比较,API运行时将会对两个字符串进行byte级别的比较,因此这种比较是比较严格和准确的,并且在性能上也很好,一般通过StringComparison.Ordinal来进行比较比使用String.Compare(string1,string2)来比较要快10倍左右.(可以写一个简单的小程序验证,这个挺让我惊讶,因为平时使用String.Compare从来就没想过那么多).StringComparison.OrdinalIgnoreCase就是忽略大小写的比较,同样是byte级别的比较.性能稍弱于StringComparison.Ordinal. 2.StringComparison.CurrentCulture 是在当前的区域信息下进行比较,这是String.Compare在没有指定StringComparison的时候默认的比较方式.例子如下: Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); //当前的区域信息是美国 string s1 = "visualstudio"; string s2 = "windows"; Console.WriteLine(String.Compare(s1, s2,StringComparison.CurrentCulture)); //输出"-1" Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE"); //当前的区域信息是瑞典 Console.WriteLine(String.Compare(s1, s2,StringComparison.CurrentCulture)); //输出"1" StringComarison.CurrentCultureIgnoreCase指在当前区域信息下忽略大小写的比较. 3.StringComarison.InvariantCulture 使用StringComarison.InvariantCulture来进行字符串比较,在任何系统中(不同的culture)比较都将得到相同的结果,他是使用CultureInfo.InvariantCulture的静态成员CompareInfo来进行比较操作的.例子如下: Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); //当前的区域信息是美国 string s1 = "visualstudio"; string s2 = "windows"; Console.WriteLine(String.Compare(s1, s2,StringComparison.InvariantCulture)); //输出"-1" Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE"); //当前的区域信息是瑞典 Console.WriteLine(String.Compare(s1, s2,StringComparison.InvariantCulture)); //输出"-1" 参考文章:http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dndotnet/html/StringsinNET20.asp from:http://www.cnblogs.com/zhw511006/archive/2010/07/09/1774591.html
View Details