zoukankan      html  css  js  c++  java
  • Win 8 app 获取窗口的宽度和高度, 本地化, 及文本读取

    在Windows 8的程序中:

    1. 获取用户窗口的宽高;

                    double height = Windows.UI.Xaml.Window.Current.Bounds.Height;
                    double width = Window.Current.Bounds.Width;

    2. 获取用户的语言设置;

     this._cultureInfo = System.Globalization.CultureInfo .CurrentUICulture .Name .ToString ();

    注释: 我现在还不清楚这个CurrentUICulture是怎么使用的。 我的应用中是通过获取用户的区域来决定显示的语言的:

    this._region = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion;

    如果返回的值_region是“CN”, 那么我的程序就显示中文。

    3. 文件的读取, text方式;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.Storage;
    
    namespace QpuzzleTouch.DataModel
    {
        public class FileAccess:QpuzzleTouch .Common .BindableBase
        {
            private static FileAccess _fileAccess=new FileAccess();
            public StorageFile StorageFile = null;
            string _fileName = null;
    
            public string UserData = string.Empty;
    
            public FileAccess()
            {
                this._fileName = "QpuzzleCustomConfig.txt";
            }
    
            public static async void InitStorageFile()
            {
                try
                {
                    StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
                    _fileAccess.StorageFile = await storageFolder .GetFileAsync (_fileAccess ._fileName );
                    if (_fileAccess.StorageFile != null)
                    {
                        _fileAccess.UserData = await FileIO.ReadTextAsync(_fileAccess.StorageFile);
                    }
                }
                catch { }
            }
    
            public static string GetData()
            {
                InitStorageFile();
                try
                {
                    if (_fileAccess.UserData != string.Empty)
                        return _fileAccess.UserData;
                    else
                        return string.Empty;
                }
                catch {
                    return string.Empty;
                }
            }
            
            public static async void CreateFile(string fileName)
            {
                try
                {
                    StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
                    _fileAccess.StorageFile = await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
                }
                catch { }
            }
    
            public static async void WriteText(string userContent)
            {
                CreateFile(_fileAccess._fileName);
                try
                {
                    if (_fileAccess.StorageFile != null)
                    {
                        await FileIO.WriteTextAsync(_fileAccess.StorageFile, userContent);
                    }
                }
                catch { }
            }
    
        }
    }

     向程序的本地目录里边写配置文件。

    Windows.Storage.ApplicationData.Current.LocalFolder.

            async void ReadFromFile()
            {
                StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                StorageFile storageFile = await storageFolder.CreateFileAsync("text.txt", CreationCollisionOption.OpenIfExists);
                string result =await FileIO.ReadTextAsync(storageFile);
                textbox1.Text = result;
            }
            private async void btwrite_Click(object sender, RoutedEventArgs e)
            {
                StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                StorageFile storageFile =await storageFolder.CreateFileAsync("text.txt", CreationCollisionOption.OpenIfExists);
                await FileIO.AppendTextAsync(storageFile, "abc");
            }
  • 相关阅读:
    启动Nginx、查看nginx进程、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级
    专为渗透测试人员设计的 Python 工具大合集
    如何为网站启用HTTPS加密传输协议
    正确设置nginx/php-fpm/apache权限 提高网站安全性 防止被挂木马
    java中十进制转换为任意进制
    多线程死锁的产生以及如何避免死锁
    Java Integer和String内存存储
    Java 内存溢出(java.lang.OutOfMemoryError)的常见情况和处理方式总结
    Jvm垃圾回收器详细
    分布式环境中的负载均衡策略
  • 原文地址:https://www.cnblogs.com/qixue/p/2819843.html
Copyright © 2011-2022 走看看