#眉標=Silverlight 4、Elevated Trust、OOB #副標=Silverlight最新技術與應用(1) #大標=Silverlight 4更進一步應用於用戶端 #作者=文/圖 董大偉 ============= 程式1 private void Button1_Click(object sender, System.Windows.RoutedEventArgs e) { System.Windows.Printing.PrintDocument pDoc = new System.Windows.Printing.PrintDocument(); pDoc.StartPrint += new EventHandler(pDoc_StartPrint); pDoc.PrintPage += new EventHandler(pDoc_PrintPage); pDoc.EndPrint += new EventHandler(pDoc_EndPrint); pDoc.DocumentName = "列印小叮噹"; //列印檔案名稱(出現在列表機視窗) pDoc.Print(); } void pDoc_EndPrint(object sender, System.Windows.Printing.EndPrintEventArgs e) { //throw new NotImplementedException(); } void pDoc_StartPrint(object sender, System.Windows.Printing.StartPrintEventArgs e) { //throw new NotImplementedException(); } void pDoc_PrintPage(object sender, System.Windows.Printing.PrintPageEventArgs e) { e.HasMorePages = false; //沒有其他列印頁 e.PageVisual = Canvas1; //要輸出到印表機的物件 } ================ ===<反灰>============= if (App.Current.HasElevatedPermissions) { //執行於Elevated Trust模式中 } else { //並未執行於Elevated Trust模式中 }    ================ ============= 程式2 //儲存檔案 private void buttonSave_Click(object sender, RoutedEventArgs e) { //取得用戶端MyDocuments實際路徑 string path=Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments); //建立檔案 System.IO.StreamWriter sw= System.IO.File.CreateText(path + "\\Test123.txt"); //透過StreamWriter將textBox1中的內容寫入檔案 sw.WriteLine(this.textBox1.Text); //關檔 sw.Close(); MessageBox.Show("OK"); } ================ ============= 程式3 private void Button_Click(object sender, RoutedEventArgs e) { //透過ComAutomationFactory呼叫Word應用程式 dynamic word = System.Windows.Interop.ComAutomationFactory.CreateObject("Word.Application"); //顯示 word.Visible = true; //建立新word文件 dynamic doc=word.Documents.Add(); //在文件中填入底下文字 word.Selection.TypeText("開啟新word文件,並輸入這段文字"); } ================