1、C#调用EXE文件
System.Diagnostics.Process.Start("calc.exe"); //这样就能启动了,当然后你也可以来容错处理。
string _path = Application.StartupPath;上面是获去你当前正在执行程序的路进.string dfgdf = _path + "\\General.txt";有了"_path"你就可以想处理字符串那样想怎么整就怎么整了.
2、 如何在c#中调用外部dos程序?
使用Process对象:
System.Diagnostics.Process p=new System.Diagnostics.Process();
p.StartInfo.FileName="arj.exe" ;//需要启动的程序名
p.StartInfo.Arguments="-x sourceFile.Arj c:\temp";//启动参数
p.Start();//启动
if(p.HasExisted)//判断是否运行结束
p.kill();
3、读取word内容,并且显示在控件里
在Form里加一个button按钮和一个richtextbox,给按钮加一个Click事件
private void button1_Click(object sender, EventArgs e)
{
object filepath= "D:\\Debugtest.doc";
openWord(filepath);
}
//把Word
文档内容取出来放到richtextBox里
private void openWord(object SPath)
{
object file = SPath;
object nullobj = System.Reflection.Missing.Value;
Word.Document doc = myWordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
this.richTextBox1.Text = data.GetData(DataFormats.Text).ToString();
doc.Close(ref nullobj, ref nullobj, ref nullobj);
}
4、c#加载flash控件
如后我们考虑如何把Flash嵌入到WinForm程序当中,在 Visual Studio 2010 中有一个默认未启用的组件——Shockwave Flash Object,此组件即可加载Flash程序,启用 Shockwave Flash Object 请打开左上角的工具箱,在工具箱中右键单击,选添加选项卡,命名为AAA,然后右键单击 AAA 选项卡,选“选择项”,即可打开“选择工具箱项”对话框,然后单击 “COM组件”,拖动滚动条至接近底端处,你将会看见
Shockwave Flash Object 组件,将其勾选,点确定,如图所示:
此时, Shockwave Flash Object 组件已添加完成,此组件在工具箱的AAA选项卡中可以看到,然后将此组件拖入WinForm设计视图中,设置大小258×192,然后在工具箱的 公共控件选项卡中分别拖入一个 Button 控件和一个 Label 控件,并且给Button添加单击事件处理函数,如下图:
然后按F7,进入代码编辑器,代码如下:
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;
using System.Xml;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
label1.Text = "Button";
axShockwaveFlash1.Movie = Application.StartupPath + "\\CallAPP.swf"; //加载同路径下的CallAPP.swf文件
//Flash每次调用C#中的函数时,C#中会有一个事件响应,此事件由 axShockwaveFlash1 来接收
axShockwaveFlash1.FlashCall += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEventHandler(axShockwaveFlash1_FlashCall);
}
private void axShockwaveFlash1_FlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)//向as发送请求
{
XmlDocument document = new XmlDocument();
//Flash与C#之间通信其实就是互相传输数据,数据格式是XML格式,存储于事件对象的 request 属性中
document.LoadXml(e.request);
// 得到信息并解析
XmlAttributeCollection attributes = document.FirstChild.Attributes;
// get function
String command = attributes.Item(0).InnerText;
// get parameters
XmlNodeList list = document.GetElementsByTagName("arguments");
String arg = list.Item(0).InnerText;
switch (command)
{
case "callCSharp":
callCSharp(arg);
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
callFunction("output", "why?"); //调用as中的output()函数,why?为参数
}
private void callFunction(string funName, string arg)
{
//C#传给Flash的值
axShockwaveFlash1.CallFunction("<invoke name=\"" + funName + "\" returntype=\"xml\"><arguments><string>" + arg + "</string></arguments></invoke>");
}
public void callCSharp(String _str)
{
label1.Text = _str;
axShockwaveFlash1.SetReturnValue("<string>" + _str + "</string>"); //C#给Flash返回的值
}
}
}
原文地址:http://blog.csdn.net/xinxinzhaochao/article/details/8292959