GVKun编程网logo

如何使用C#Windows应用程序将字节中的图像写入MS WORD(c#图片转换为字节数组)

2

如果您想了解如何使用C#Windows应用程序将字节中的图像写入MSWORD的相关知识,那么本文是一篇不可错过的文章,我们将对c#图片转换为字节数组进行全面详尽的解释,并且为您提供关于cordova应

如果您想了解如何使用C#Windows应用程序将字节中的图像写入MS WORD的相关知识,那么本文是一篇不可错过的文章,我们将对c#图片转换为字节数组进行全面详尽的解释,并且为您提供关于cordova应用程序接收从其他应用程序共享的内容 – iOS,Android和Windows应用程序商店、Cordova:如何诊断ajax不适用于UWP(Windows应用商店)应用程序、C# – 捕获Windows应用程序输出、C#Windows应用程序删除页面的有价值的信息。

本文目录一览:

如何使用C#Windows应用程序将字节中的图像写入MS WORD(c#图片转换为字节数组)

如何使用C#Windows应用程序将字节中的图像写入MS WORD(c#图片转换为字节数组)

我试图从FileStream , StreamWriter写入数据到一个word文件。

当数据是文本格式(使用StreamWriter )时,它工作正常。 但是,当我用Binarywriter (用于将文字写入Word文档)尝试相同的方法时, Binarywriter Word文档写入不正确。

在下面的代码中, lstOrderedSpares[index].SparePicture是包含图像数据的字节数组。

我需要一个没有OPENXML的解决scheme。

.NET中的DLL可以使用不同的扩展名,例如MLL?

防止subprocess创build可见的窗口?

通过远程桌面提高WPF应用程序的速度?

成为“真正的pipe理员”(Windows),并在.NET C#中执行真正的pipe理任务?

Windows服务 – 安装2份

这是我迄今为止所尝试的:

这里是我的button点击我初始化的数据类和List

private void btnCreateQuotation_Click(object sender,EventArgs e) { try { Quotation aQuotation = new Quotation(); aQuotation.QuotationId = quotationId; aQuotation.QuotationDate = lblQuotationDateValue.Text; //Reading from Datagridview and adding to List<Spare> List<Spare> lstOrderedSpares = new List<Spare>(); if (dataGridView1.Rows.Count > 0) { foreach (DataGridViewRow dr in dataGridView1.Rows) { Spare aSpare = new Spare(); aSpare.SapreSerialNumber = dr.Cells["SlNo"].Value.ToString(); aSpare.SparePartId = dr.Cells["SparePartID"].Value.ToString(); aSpare.SparePicture = (byte[])dr.Cells["SparePicture"].Value; aSpare.SpareDescription = dr.Cells["SpareDescription"].Value.ToString(); aSpare.EURPrice = Convert.Todouble(dr.Cells["EURPrice"].Value.ToString()); aSpare.Quantity = Convert.Todouble(dr.Cells["Quantity"].Value.ToString()); aSpare.TotalPrice = Convert.Todouble(dr.Cells["TotalPrice"].Value.ToString()); aSpare.DeliveryCharge = Convert.Todouble(txtDeliveryCharge.Text.Trim()); aSpare.Vat = txtVAT.Text.Trim(); aSpare.INRPrice = Convert.Todouble(dr.Cells["INRPrice"].Value.ToString()); lstOrderedSpares.Add(aSpare); } } Contact aContact = new Contact(); aContact.CompanyName = txtCustomerName.Text.Trim(); aContact.ContactName = cmbContactPersonName.Text; aContact.ContactId = Convert.ToInt32(lblContactPeronIdValue.Text); aContact.CompanyId = Convert.ToInt32(lblCustomerIDValue.Text); string fileName = "SparePart_" + aQuotation.QuotationId + "_"; string fileNameWithPath = "C:\Quotations\SpareQuotations\" + fileName; if (isaddedtodb) { CreateDocument(aQuotation,aContact,lstOrderedSpares,fileNameWithPath); fileNameWithPath = fileNameWithPath + aContact.CompanyName.Trim() + ".doc"; btnCreateQuotation.Visible = false; this.Hide(); //start ms word to open the document System.Diagnostics.Process.Start(fileNameWithPath); } } catch (Exception objEx) { } }

这里是将数据写入Word文档的CreateDocument方法。

private void CreateDocument(Quotation aQuotation,Contact aContact,List<Spare> lstOrderedSpares,string fileNameWithPath) { try { _Application oWord = new Microsoft.Office.Interop.Word.Application(); _Document odoc = oWord.Documents.Add(); oWord.Visible = true; //modify secondparameter to include customer name in file name fileNameWithPath = fileNameWithPath + aContact.CompanyName.Trim() + ".doc"; //Insert text Range rng = odoc.Range(); rng.Text = "TSV/" + aQuotation.EnquiredBy.ToString() + "/JS/" + aQuotation.QuotationId + "/SPARES" + "t" + "t" + "t" + "t" + "t" + aQuotation.QuotationDate; //oWord.Selection.EndKey(); //oWord.Selection.TypeParagraph(); rng.InsertBreak(); rng.Text = "To,"; rng.InsertBreak(); rng.Text = "M/s. " + aContact.CompanyName + ","; rng.InsertBreak(); rng.Text = aContact.AddressLine1 + ","; rng.InsertBreak(); rng.Text = aContact.AddressLine2 + ","; rng.InsertBreak(); rng.Text = aContact.City + "," + aContact.State + ","; rng.InsertBreak(); rng.Text = aContact.Country + "-" + aContact.PinNo; rng.InsertBreak(); rng.Text = "Phone : " + aContact.PhoneNo; rng.InsertBreak(); rng.Text = "Mobile No : " + aContact.MobileNo; rng.InsertBreak(); rng.InsertBreak(); //Salutation and subject rng.Text = "t" + "t" + "Kind Attention : " + aContact.ContactName; rng.InsertBreak(); rng.Text = "Dear Sir,"; rng.InsertBreak(); rng.Text = "Sub: " + aQuotation.Subject; rng.InsertBreak(); rng.Text = "Ref: your email enquiry dt: " + aQuotation.EmailEnquiredDate; rng.InsertBreak(); rng.Text = "We thank you for your valuable email enquiry dt. " + aQuotation.EmailEnquiredDate + " for supply of spares for your .........Capacity," + " fabrik nos Sl. No :.................."; rng.InsertBreak(); rng.InsertBreak(); int europeancount = 0; for (int index = 0; index < lstOrderedSpares.Count; index++) { if (lstOrderedSpares[index].INRPrice == 0.00) { europeancount++; } } rng.Text = "A) We wish to inform you that the following " + europeancount + " spares can be supplied directly by in Euros."; rng.InsertBreak(); rng.InsertBreak(); int tempslno1 = 0; for (int index = 0; index < lstOrderedSpares.Count; index++) { if (lstOrderedSpares[index].INRPrice == 0.00) { tempslno1++; rng.Text = tempslno1 + "." + lstOrderedSpares[index].SpareDescription.toupper() + " : ARTICLE NO: " + lstOrderedSpares[index].SparePartId + "t" + Math.Round(lstOrderedSpares[index].EURPrice) + lbleuroSymbol.Text + "(" + new NumberToEnglish().changeCurrencyToWords(Math.Round(lstOrderedSpares[index].EURPrice)) + ")"; //To insert a picture from a byte array you need to use the Clipboard to paste it in object endOfContent = odoc.Content.End - 1; Range rngPic = odoc.Range(endOfContent); //Here is the trick to convert the ByteArray into an image and paste it in the document Image sparePicture = ByteArrayToImage(lstOrderedSpares[index].SparePicture); Clipboard.SetDataObject(sparePicture); rngPic.Paste(); rng.InsertBreak(); } } rng.InsertBreak(); rng.InsertBreak(); rng.Text = "Price Quoted Ex-works ."; rng.InsertBreak(); rng.Text = "Freight/Courier,Insurance,duties,any and all other expenses extra to " + "customers account."; rng.InsertBreak(); rng.InsertBreak(); rng.Text = "HOW TO ORDER :- Please register your order in favour of ...."; rng.InsertBreak(); rng.Text = "PAYMENT :- Full payment in advance against proforma invoice from ...." + " through their bankers ..... "; rng.InsertBreak(); rng.InsertBreak(); rng.Text = "Delivery / dispatch: 2 Weeks from the date of receipt of payment."; rng.InsertBreak(); rng.Text = "In case if you have account with ...then kindly mention the account number," + "since it will be economical if send via ...."; rng.Text = "Please provide your 'IEC Code number'."; rng.InsertBreak(); rng.InsertBreak(); rng.Text = "B) We wish to inform you that the following spare can be supplied from ex-stock " + "our Office in INR"; rng.InsertBreak(); int tempslno2 = 0; for (int index = 0; index < lstOrderedSpares.Count; index++) { if (lstOrderedSpares[index].INRPrice != 0.00) { tempslno2++; rng.Text = tempslno2 + "." + lstOrderedSpares[index].SpareDescription.toupper() + " : ARTICLE NO: " + lstOrderedSpares[index].SparePartId + "t" + Math.Round(lstOrderedSpares[index].INRPrice) + " " + lblINRSymbol.Text + "(" + new NumberToEnglish().changeNumericToWords(Math.Round(lstOrderedSpares[index].INRPrice)) + ")"; //To insert a picture from a byte array you need to use the Clipboard to paste it in object endOfContent = odoc.Content.End - 1; Range rngPic = odoc.Range(endOfContent); //Here is the trick to convert the ByteArray into an image and paste it in the document Image sparePicture = ByteArrayToImage(lstOrderedSpares[index].SparePicture); Clipboard.SetDataObject(sparePicture); rngPic.Paste(); rng.InsertBreak(); } } rng.Text = "Price quoted ex-our office"; rng.InsertBreak(); rng.Text = "Taxes: VAT TNGST @ " + lstOrderedSpares[0].Vat + "% extra"; rng.InsertBreak(); rng.Text = "Delivery/Despatch: on receipt of order along with payment"; rng.Text = "Delivery/Courier Charges - extra " + lstOrderedSpares[0].DeliveryCharge.ToString() + "/-"; rng.InsertBreak(); rng.Text = "The order & payment may please be released in favour of..."; rng.InsertBreak(); rng.InsertBreak(); rng.Text = "Payment: Full payment in advance by way of Electronic Transfer as per following details :"; rng.InsertBreak(); rng.Text = "Current Account Number: ......"; rng.InsertBreak(); rng.Text = "IFSC Code: .........."; rng.InsertBreak(); rng.Text = "Name of the account holder: ........."; rng.InsertBreak(); rng.Text = "t" + "t" + "t" + "OR"; rng.InsertBreak(); rng.Text = "By way of Demand Draft"; rng.InsertBreak(); rng.InsertBreak(); rng.Text = "Offer validity 30 days"; rng.InsertBreak(); rng.Text = "Thanking you and awaiting your valuable instructions to fulfill your needs well in time."; rng.InsertBreak(); rng.InsertBreak(); rng.Text = "Yours sincerely"; rng.InsertBreak(); oWord.Selection.EndKey(); oWord.Selection.TypeParagraph(); odoc.SaveAs(fileNameWithPath); //If you're creating a document odoc.Close(); oWord.Quit(); } catch (Exception objEx) { } } public Image ByteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); returnImage = ResizeImage(returnImage,new Size(30,30)); return returnImage; } public static Image ResizeImage(Image imgToResize,Size size) { return (Image)(new Bitmap(imgToResize,size)); }

使用.NET(C#)获取所有打开的窗口的位置和大小

如何将对象转换为未知types为T的IList <T>

C#:什么是最快的方式来生成一个唯一的文件名?

有没有办法通过局域网caching和分发Visual Studio更新?

将两个RichTextBox的内容附加为单个RichTextstring

当你创建一个文件,例如C: Temp MyWordDoc.doc,并使用FileStream和StreamWriter将数据写入它时,实际上是将信息写入文本文件。

doc或docx文件扩展名会导致Microsoft Word打开该文件,但它不是Word格式的文本。

您需要使用MS Word对象模型将图片添加到Word文档中。 为此,请在项目中引用Microsoft.Office.Interop.Word .Net DLL并尝试下面的代码:

using Microsoft.Office.Interop.Word; using System.IO; private void btnCreateQuotation_Click(object sender,EventArgs e) { var spareList = new List<Spare>(); spareList.Add(new Spare{ SparePicture = ImagetoByteArray(Image.FromFile(@"C:temp11.png"))}); spareList.Add(new Spare { SparePicture = ImagetoByteArray(Image.FromFile(@"C:temp1.png")) }); CreateDocument(@"C:TempMyWordDoc.docx",spareList); } public void CreateDocument(string docFilePath,List<Spare> lstOrderedSpares) { Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word._Document odoc = oWord.Documents.Add(); //If you're creating a document //Microsoft.Office.Interop.Word._Document odoc = oWord.Documents.Open(docFilePath,ReadOnly: false,Visible: true); //If you're opening a document //To see whats going on while populating the word document set Visible = true oWord.Visible = true; //Insert text Object oMissing = System.Reflection.Missing.Value; var oPara1 = odoc.Content.Paragraphs.Add(ref oMissing); oPara1.Range.Text = "First Text"; oPara1.Range.InsertParagraphAfter(); //Here is the trick to insert a picture from a byte array into MS Word you need to //convert the ByteArray into an Image and using the Clipboard paste it into the document Image sparePicture = ByteArrayToImage(lstOrderedSpares[0].SparePicture); Clipboard.SetDataObject(sparePicture); var oPara2 = odoc.Content.Paragraphs.Add(ref oMissing); oPara2.Range.Paste(); oPara2.Range.InsertParagraphAfter(); //Insert some more text var oPara3 = odoc.Content.Paragraphs.Add(ref oMissing); oPara3.Range.Text = "Second Text" + Environment.NewLine; oPara3.Range.InsertParagraphAfter(); sparePicture = ByteArrayToImage(lstOrderedSpares[1].SparePicture); Clipboard.SetDataObject(sparePicture); var oPara4 = odoc.Content.Paragraphs.Add(ref oMissing); oPara4.Range.Paste(); oPara4.Range.InsertParagraphAfter(); odoc.SaveAs(docFilePath); //If you're creating a document //odoc.Save(); //If you're opening a document odoc.Close(); oWord.Quit(); } public Image ByteArrayToImage(byte[] byteArrayIn) { using (MemoryStream ms = new MemoryStream(byteArrayIn)) { Image returnImage = Image.FromStream(ms); return returnImage; } } //Method I use to test loading images from disk into byte[]'s and inserting them into word public byte[] ImagetoByteArray(System.Drawing.Image imageIn) { byte[] result = null; using (MemoryStream ms = new MemoryStream()) { imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Png); result = ms.ToArray(); } return result; }

这是结果:

cordova应用程序接收从其他应用程序共享的内容 – iOS,Android和Windows应用程序商店

cordova应用程序接收从其他应用程序共享的内容 – iOS,Android和Windows应用程序商店

我正在开发一个通信器,我想将我的应用程序作为应用程序扩展插件展示给本地设备,允许用户从本地共享菜单共享图像,文本和video到我的cordova应用程序。 有没有办法在iOS,Android和Windows Store应用程序上使用Cordova应用程序?

QueryWorkingSetEx应用于共享内存时返回无效页面

叉的共享内存

在linux中的信号量和共享内存

通过UNC使用模拟主机的身份validation问题

在完成ReportCompleted后分享目标合约

对于Android来说,这更容易,你可以使用一个科尔多瓦插件 。

对于iOS来说,这很难,我已经在这里记录下来

如果我理解正确,

首先 ,在Manifest.xml manifest添加android:sharedUserId="action.name"这两个应用程序。 (nativa应用程序和cordova应用程序) 重要的是sharedUserId将是相同的。

其次 ,在本机应用程序上保存此代码的对象。

SharedPreference prefs = context.getSharedPreferences(prefName,Activity.MODE_MULTI_PROCESS);

最后 ,您可以在cordova应用程序中获得此代码的对象。

Context con = cordova.getActivity().getApplicationContext().createPackageContext("action.name",Context.MODE_MULTI_PROCESS); SharedPreferences pref = con.getSharedPreferences("prefName",Context.MODE_MULTI_PROCESS);

这是一个很好而且仍然相关的问题。

对于iOS,解决方案在于为iOS应用程序创建共享扩展,幸运的是,这个过程几乎已经自动化了。

在我的研究过程中,我尝试着使用Jean-Christophe Hoelt的真棒cordova-plugin-openwith ,但遇到了几个问题。 该插件旨在接收在安装期间配置的一种类型(例如,URL,文本或图像)的共享项目。 另外,在目前的实现中,写一个笔记来分享和选择一个Cordova应用程序中的接收器是不同的(本地和Cordova)上下文中的两个不同的步骤,因此它对我来说并不是一个好的用户体验。

我做了这些和其他更正这个插件,并作为一个单独的插件发布: https : //github.com/EternallLight/cordova-plugin-openwith-ios

如果你只需要接收一个类型的股份,只说照片,cordova-plugin-openwith应该没问题。 但是,您仍然可以一次共享一个图像。

请注意,它仅适用于iOS,不适用于Android。

Cordova:如何诊断ajax不适用于UWP(Windows应用商店)应用程序

Cordova:如何诊断ajax不适用于UWP(Windows应用商店)应用程序

我有一个简单的Cordova应用程序,在构建时,作为 Windows UWP应用程序运行时,ajax调用在某种程度上被阻止了我的工作网络.

我以前曾多次问过这个问题,但是想过会试着改写,因为从来没有得到任何解决方案.

应用程序ajax调用在我的家用机器上工作正常,或者什么似乎是大多数其他网络.当它工作时,我可以看到Wireshark中的所有输出

当我的工作机器连接到我们的工作网络时,我在Wireshark中看不到任何东西.如果我指向在localhost上运行的服务器,该应用程序确实有效(但我在Wireshark中看不到任何内容,但这可能是因为它是localhost)

如果我在UWP容器之外运行应用程序,即我只是在同一台机器上运行,在同一个网络上运行,但是通过桌面浏览器运行(就像你为Cordova调试一样),它也可以运行.

所以它甚至在它进入网络之前就被阻止了,因为我们根本看不到Wireshark,所以这排除了主机无法访问,CORS等,因为它甚至没有被发送到服务器.

我可以通过Visual Studio在调试中运行它,并运行以下测试代码…

document.addEventListener(''deviceready'',callUrl,false);

function callUrl() {

  console.log(''callUrl''); 
  var xhr = new XMLHttpRequest();

  xhr.onreadystatechange = function () {
    var DONE = 4; // readyState 4 means the request is done.
    var OK = 200; // status 200 is a successful return.
    console.log(xhr.readyState);
    if (xhr.readyState === DONE) {
      if (xhr.status === OK)
        console.log(xhr.responseText); // ''This is the returned text.''
    } else {
      console.log(''Error: '' + xhr.status); // An error occurred during the request.
    }
  }

  xhr.open(''GET'',''https://httpbin.org/get'');
  xhr.send(null);

};

onreadystatechangeis调用两次,xhr.readyState前2然后4.
状态始终为0.

我怎样才能诊断阻塞这个的是什么?我完全不知道.这是低级别的东西,但怎么看?我也浏览了Windows事件日志,但什么都找不到.

Ajax调用只返回0,带有空白描述.我们的网络管理员只是说我的应用程序有问题(我尝试了多个Cordova应用程序,包括基本的测试应用程序)

在此先感谢您的帮助.

[EDIT1]

为了回应@Xavier的评论,我在AppxManifest.xml中的所有内容(我从我构建的.appxupload文件中提取的)都是

<Capabilities> 
  <Capability Name="internetClient" /> 
</Capabilities>

有一些关于here功能的文档,我们有以下内容(位于页面底部).

The following capabilities are unavailable when deploying your Remote Mode application to the Windows Store:

    Enterprise Authentication (enterpriseAuthentication)
    Shared User Certificates (sharedUserCertificates)
    Documents Library (documentsLibrary)
    Music Library (musicLibrary)
    Pictures Library (picturesLibrary)
    Videos Library (videosLibrary)
    Removable Storage (removableStorage)
    Internet client/server (internetClientServer) - note that internetClient is still permitted
    Private network client/server (privateNetworkClientServer)

我不确定我们是否在Visual Studio(config.xml)中设置了这些,但上面似乎也说这些中的一些不能使用?

internetClient应该足够吗(我只想作为客户端呼叫服务器,而不是充当服务器).

此外,这似乎足以在大多数网络上工作,除了我的工作..

[EDIT2]

回应关于CSP的回复……

有关此here的讨论.我在Visual Studio中创建的测试Cordova应用程序确实具有以下功能:

<Meta http-equiv="Content-Security-Policy" content="default-src ''self'' data: gap: https://ssl.gstatic.com ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; media-src *">

令人惊讶的是,我没有在我的Ionic index.html中看到这一点,但也许这是因为它使用的是白名单插件?

我的Ionic应用程序在config.xml中有以下内容

<access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <allow-navigation href="http://localhost:8080/*" />
  ....
  <plugin name="cordova-plugin-whitelist" spec="^1.3.1" />

如果ajax甚至有一些错误说它与CSP有关,那将是很好的,如果它就是这样,但我们什么都没得到.

再一次,这个问题只出现在我的工作网络上(无论是有线还是我们的WIFI),这很奇怪.如果我在另一个连接上运行确切的机器(例如Surface平板电脑)(例如将它连接到我的手机电池),那么一切都按预期工作.所以它必须是与网络(或防火墙可能)有关的一些设置,我也觉得奇怪,因为我至少会在Wireshark中看到一些东西.

很高兴能够“调试”ajax调用,并查看它失败的地方.

[编辑3]

阅读其中一条评论后,我用小提琴手看看我能看到什么,我做了……

enter image description here

它甚至报告200(这是不正确的),我的请求仍然失败.

解决方法

根据 this,您需要请求privateNetworkClientServer功能才能与本地网络通信.

请注意,此功能仅在您的应用程序配置为local mode时才有效(如果在远程模式下使用此功能,您的应用程序将从商店中被拒绝).

要启用本地模式,您需要设置< preference name =“WindowsDefaultUriPrefix”value =“ms-appx://”/>在你的cordova config.xml中.

请注意,本地模式可能会导致其他问题,因为您无法使用例如本地模式下的内联脚本(CSP违规)

C# – 捕获Windows应用程序输出

C# – 捕获Windows应用程序输出

我的应用程序启动“C: Windows System32 Msra.Exe”来控制域计算机。 有没有一种方法可以捕获这个msra.Exe显示的错误消息。 (即从msra.exe的内部错误消息,而不是从我的应用程序。)该应用程序本身是一个Windows窗体应用程序。

任何帮助表示赞赏。

启动MSRA的代码在下面…这只是完整应用程序的一小部分。

string msra = "C:\Windows\System32\runas.exe"; string domainname = "**********"; string domaincontroller = "*************"; if (File.Exists(msra) == false) { System.Windows.Forms.MessageBox.Show("Runas.exe not found.nrPlease contact your internal IT support.","Fatal error",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error); } else { try { Process p = new Process(); p.StartInfo.UseShellExecute = true; p.StartInfo.WindowStyle = ProcessWindowStyle.normal; p.StartInfo.ErrorDialog = true; p.StartInfo.FileName = msra; p.StartInfo.Arguments = "/noprofile /netonly /user:" + domainname + "\" + username + " "cmd /server:" + domaincontroller + " /C msra.exe /offerra " + computerip + """; p.Start(); p.dispose(); Thread.Sleep(1700); SendKeys.SendWait(password); SendKeys.SendWait("{ENTER}"); } catch { System.Windows.Forms.MessageBox.Show("MSRA Could not be started for an unkNown reason"); } }

通过.Net设置Windows进程“评论”?

Windows服务不能在冷启动时启动

如何使用Windows SDK更新“其他时钟”设置

将应用程序更新部署到多个站点

如何从远程计算机获取CommonApplicationData?

有效字幕文本颜色 – 检测变化(在.Net中)

Windows系统时间精确​​到毫秒级

用WMI调用解决“拒绝访问”exception

通过Teamviewer连接时,WPF应用程序崩溃

如何完全卸载Red Gate的.NET Reflector?

您可以将RedirectStandardOutput或RedirectStandardError设置为true ,以便能够从流程的标准输出或错误输出读取。

然后你有几个选择如何实际读取数据:

使用StandardOutput属性

子输出到OutputDataReceived事件并调用BeginoutputReadLine()

或者错误流的相应成员。

您需要http://msdn.microsoft.com/zh-CN/library/system.diagnostics.process.standardoutput.aspx

[更新为指向.net示例]

您正在使用Process,请尝试Process.StandardError属性。 你分配一个流,你将能够使用它。

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror.aspx

而当你在那里,你也可以使用Process.StandardOutput

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx

C#Windows应用程序删除页面

C#Windows应用程序删除页面

我做了一个简单的Windows 8测验游戏。

我有3页:MainPage,GamePage和scorePage

GamePage有一个计时器,所以我必须在30秒内回答尽可能多的问题。 它也有一个后退button,以防止我想放弃和重试button重新开始。

问题在于,无论何时点击“返回”或“重试”button,新页面都会正确显示,但旧的GamePage仍会在后台运行,当时间到时,将显示scorePage

例如,我打开应用程序,启动游戏,然后单击返回。 时间到了,即使我closures了游戏(或者我想),scorePage仍然会显示…

那么我怎样才能完全处理这个页面的实例呢?

这是我第一次尝试制作一个W8应用程序,我以前只使用过WinForms,在这里我使用了this.Close(); 彻底摆脱页面/表格。

打开页面我用this.Frame.Navigate(typeof(GamePage),null); 和this.Frame.Navigate(typeof(scorePage),new int[] { Correct,Wrong });

下面的代码删除堆栈中的条目

if (NavigationService.CanGoBack) { while (NavigationService.RemoveBackEntry() != null) { NavigationService.RemoveBackEntry(); } }

你可以这样关闭应用程序

Application.Current.Terminate();

我们今天的关于如何使用C#Windows应用程序将字节中的图像写入MS WORDc#图片转换为字节数组的分享就到这里,谢谢您的阅读,如果想了解更多关于cordova应用程序接收从其他应用程序共享的内容 – iOS,Android和Windows应用程序商店、Cordova:如何诊断ajax不适用于UWP(Windows应用商店)应用程序、C# – 捕获Windows应用程序输出、C#Windows应用程序删除页面的相关信息,可以在本站进行搜索。

本文标签: