欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
c# 與 winform 界面開(kāi)發(fā)

在 windows 下使用 vs2010 開(kāi)發(fā),未深入研究。

 

c# 與 .net 開(kāi)發(fā),一堆又一堆的新名詞,頭暈目眩,比如 CLR / apartments / STA / MTA / COM

吐槽無(wú)力,只一個(gè)問(wèn)題:微軟真的是軟件公司,而不是文學(xué)公司?

1. 工程代碼結構

創(chuàng )建 Windows Forms Application 工程后,自動(dòng)生成如下代碼:

Form1.cs 與 Form1.Designer.cs  是 2 個(gè)文件,一起定義了一個(gè) form 的行為/樣式等。在 vs2010 中會(huì )折疊在一起。

其中,Designer 中定義樣式。事件監聽(tīng)、事件處理都在 form.cs 中定義。

雙擊 form.cs 會(huì )打開(kāi) UI 效果界面,可以直接拖拽完成界面布局。右鍵 view code 可以查看 form1.cs 源碼。

 

Program.cs 內定義了 main 函數,是啟動(dòng)文件。

用一個(gè) App run 一個(gè) form。

[STAThread]/[MTAThead] 指定單/多線(xiàn)程運行模式。

using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace AppDemo{    static class Program    {        /// <summary>        /// The main entry point for the application.        /// </summary>        [STAThread]        static void Main()        {            Application.EnableVisualStyles();            Application.SetCompatibleTextRenderingDefault(false);            Application.Run(new Form1());        }    }}

2. Form.cs 與 Form.Designer.cs

form1.cs 與 designer.cs 2個(gè)文件定義的是同一個(gè) namespace 下的 同一個(gè) class

每一個(gè)文件定義時(shí),都使用了 partial class

界面布局的代碼,一般自動(dòng)生成,在 Designer 中。

手寫(xiě)的代碼主要是事件處理,一般放在 form.cs 中

 

form.cs 的構造函數中,一般會(huì )先調用 Designer.cs 中定義的 InitializeComponent() 完成界面初始化。

在 InitializeComponent 中會(huì )聲明每個(gè)控件的索引   private System.Windows.Forms.Button button1; 

在 form.cs 中可以直接用過(guò)變量名 button1 操作該控件。

所以,form.cs 的構造函數中,一般先調用 InitializeComponent。

Designer.cs 中,InitializeComponent 初始化界面。Dispose 方法釋放資源。釋放時(shí)需要注意不要造成資源泄露。

// --------------- Form1.cs -----------------------------------using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace AppDemo{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }    }}// ------------------- Form1.Designer.cs -------------------------namespace AppDemo{    partial class Form1    {        /// <summary>        /// Required designer variable.        /// </summary>        private System.ComponentModel.IContainer components = null;        /// <summary>        /// Clean up any resources being used.        /// </summary>        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>        protected override void Dispose(bool disposing)        {            if (disposing && (components != null))            {                components.Dispose();            }            base.Dispose(disposing);        }        #region Windows Form Designer generated code    }}

3. 資源文件 與 resx

exe 或者 dll 文件需要依賴(lài)其它文件得以正常運行,

最簡(jiǎn)單的做法是:把依賴(lài)文件拷貝到客戶(hù)端,程序內部用相對路徑讀取。

這一般是可以的,但若客戶(hù)刪除了這些資源,則會(huì )導致不可預期的效果。

通過(guò)資源文件,可以把這些文件嵌入到 exe 或者 dll 中。

 

資源文件可分為 2 類(lèi):.resx 和 .resources。前者是 xml 格式,后者是二進(jìn)制。

只有當前 solution 存在同名的 .cs 文件時(shí),.resx 文件才能正常工作。resources 則無(wú)此限制。

 

通過(guò) System.Resources 下的 ResourceWriter 可以生成資源文件,Generate 產(chǎn)生文件,Close 關(guān)閉文件。

創(chuàng )建實(shí)例后,即可通過(guò) AddResource 方法添加資源。第一個(gè)參數是標示符,可以在代碼中通過(guò)標示符使用資源。

資源文件中一般存三種類(lèi)型的數據:byte流(byte[])、對象(object)和字符串(string)。

ResourceWriter rw = new ResourceWriter ( "filename.resources" ) ;rw.Generate ( ) ;  // 產(chǎn)生文件rw.Close ( ) ;// 添加資源public void AddResource ( str_identifier , byte [ ] ) ;public void AddResource ( str_identifier , object );public void AddResource ( str_identifier , str_value ) ;
resources.ApplyResources( this.myButton, str_identifier ); // 為 this.myButton 使用資源 str_identifier
this.ApplyResource();

4. 多國語(yǔ)言與本地化

4.1 添加多國語(yǔ)言支持

在界面上添加組件后,會(huì )生成 .resx 文件,vs2010 中折疊在對應的 form.cs 下。

這是默認語(yǔ)言的資源文件,文件名為 form1.resx

若要開(kāi)發(fā)其他語(yǔ)言版本,在對應 form 右側的屬性菜單中,將 Localizable 設為 True,并將 language 設為所需語(yǔ)言即可。

設置新的顯示文本后保存,會(huì )生成對應語(yǔ)言的 .resx 文件。文件名格式為 form1.language-Location.resx,例如:簡(jiǎn)體中文為 form1.zh-CN.resx

  1. 僅當 Language 為 default 時(shí)才可以添加或刪除界面中的組件。
  2. 僅當設定為新 language,且修改過(guò)顯示內容后,才會(huì )創(chuàng )建對應的資源文件。
  3. 僅當選定 form 時(shí),才能在右側屬性菜單中設置語(yǔ)言。若選中 form 中的 button、text 等組件時(shí),無(wú)法設置本地化屬性。
  4. 添加多國語(yǔ)言支持后,默認語(yǔ)言的 form1.resx 中不再包含顯示文字 Text、控件大小 Size、顯示位置 Location 等,而是放在了對應語(yǔ)言的資源文件中,通過(guò) ApplyResources 取用。

4.2 獲取與設定運行時(shí)語(yǔ)言

兩個(gè)關(guān)鍵概念:

  • CurrentCulture:默認值是操作系統的用戶(hù)區域設置,它在“區域選項”控制面板中設置。
  • CurrentUICulture: 默認值是操作系統的用戶(hù)界面 (UI) 語(yǔ)言,即操作系統用戶(hù)界面所使用的語(yǔ)言。
System.Globalization.CultureInfo.InstalledUICulture.Name;  // 獲取當前運行語(yǔ)言System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "zh-CHS" );  // 設置當前運行語(yǔ)言

5. 頁(yè)面布局與樣式設定

SuspendLayout() 調用后控件的布局邏輯被掛起,直到調用 ResumeLayout() 方法為止。

當調整控件的多個(gè)屬性時(shí),將先調用 SuspendLayout 方法,然后設置控件的 Size、Location、Anchor 或 Dock 屬性,

最后調用 ResumeLayout 方法以使更改生效。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
C# 一個(gè)界面類(lèi)對應多個(gè)cs文件(源代碼文件)
Reflector反編譯.NET文件后修復【轉】
用C#播放mp3[C#實(shí)例學(xué)習系列]
利用WebClient類(lèi)向服務(wù)器上載文件
Asp.Net 網(wǎng)站多語(yǔ)言解決方案
WinForm(一) WinForm入門(mén)與基本控件使用
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久