Winform 进度条学习

 
namespace ProcessBar
{
    public partial class formMain : Form
    {
        private delegate void UpdateProgress(int max, int value); 
        private UpdateProgress myIncrease = null;
        private frmProcessBar myProcessBar = null;
        public formMain()
        {
            InitializeComponent();
        }

        private void ShowProcessBar()
        {
            myProcessBar = new frmProcessBar();

            // Init increase event
            myIncrease = new UpdateProgress(myProcessBar.SetProgess);
            myProcessBar.ShowDialog();
            myProcessBar = null;

        }

        private void ThreadFun()
        {
            MethodInvoker mi = new MethodInvoker(ShowProcessBar);
            this.BeginInvoke(mi);
            Thread.Sleep(1000);             //Sleep a while to show window
            for (int i = 1; i <= 100;i++)
            {
                Thread.Sleep(50);
                object a = this.Invoke(myIncrease, new object[] { 100,i });
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread thdSub = new Thread(new ThreadStart(ThreadFun));
            thdSub.Start();
        }


    }
}

namespace ProcessBar
{
    public partial class frmProcessBar : Form
    {
        public frmProcessBar()
        {
            InitializeComponent();

            linkLabel.Text = "csdn Win 百度 谷歌 YAHOO";
            linkLabel.Links.Add(0, 4, "http://www.csdn.net/");
            linkLabel.Links.Add(9, 2, "http://www.baidu.com/");
            linkLabel.Links.Add(12, 2, "http://www.google.cn/");
            linkLabel.Links.Add(15, 5, "http://www.yahoo.com.cn/"); 
        }

        /// <summary>
        /// 设置进度条
        /// </summary>
        /// <param name="max"></param>
        /// <param name="Value"></param>
        public void SetProgess(int max, int value)
        {
            if (value <= max)
            {
                if (!this.InvokeRequired)
                {
                    progressBar1.Maximum = max;
                    progressBar1.Value = value;
                    label1.Text = value * 100 / max + "/" + max;
                    if (value == max)
                    {
                        progressBar1.Value = 0;
                        progressBar1.Visible = false;
                        label1.Visible = false;
                    }
                    else
                    {
                        progressBar1.Visible = true;
                    }
                }
                //else
                //{
                //    UpdateProgress p = new UpdateProgress(SetProgessSQL);
                //    this.Invoke(p, new object[] { max, value });
                //}

            }

        }

 

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string fileName = @"d:\tr.doc";
            if (!File.Exists(fileName))
            {
                MessageBox.Show(" 文件路径不存在!");
                return;
            }
            System.Diagnostics.Process.Start(fileName);
        }

        private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel.Links[linkLabel.Links.IndexOf(e.Link)].Visited = true;
            string targetUrl = e.Link.LinkData as string;
            if (string.IsNullOrEmpty(targetUrl))
                MessageBox.Show("没有链接地址!");
            else
                System.Diagnostics.Process.Start(targetUrl); 
        }
    }
}

===================================

C#读PPT文件与搜索

 

private void button10_Click(object sender, System.EventArgs e)
    {
      string fileName = "d:\\a.ppt";

      PowerPoint.Application pptApp = new PowerPoint.ApplicationClass();
      PowerPoint.Presentation pptPre = pptApp.Presentations.Open(fileName,
        Microsoft.Office.Core.MsoTriState.msoTrue,
        Microsoft.Office.Core.MsoTriState.msoFalse,
        Microsoft.Office.Core.MsoTriState.msoFalse);
      PowerPoint.Slides mySlides = pptPre.Slides;

      string[] strKeyWordList = {"无线"}; //要搜索的文本
      try
      {
        /*
        for (int i=0;i<mySlides.Count;i++)
        {
          PowerPoint.Shapes myShapes = mySlides[i].Shapes;
          for (int j=0;j<myShapes.Count;j++)
          {
            if (myShapes[j].HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
            {
              if (Microsoft.Office.Core.MsoTriState.msoTrue == myShapes[j].TextFrame.HasText)
              {
                textBox2.Text = textBox2.Text + myShapes[j].TextFrame.TextRange.Text;
              }
            }
          }
        }
        */
        foreach(PowerPoint.Slide sld in pptPre.Slides)
        {
          foreach(PowerPoint.Shape shp in sld.Shapes)
          {
            if(Microsoft.Office.Core.MsoTriState.msoTrue == shp.HasTextFrame)
            {
              if(Microsoft.Office.Core.MsoTriState.msoTrue == shp.TextFrame.HasText)
              {
                textBox2.Text = textBox2.Text + shp.TextFrame.TextRange.Text;
              }
            }
          }
        }
        /*
        PowerPoint.TextRange oText = null;
        foreach(PowerPoint.Slide slide in pptPre.Slides)
        {
          foreach(PowerPoint.Shape shape in slide.Shapes)
          {
            foreach(string strKeyWord in strKeyWordList)
            {
              oText = shape.TextFrame.TextRange.Find(strKeyWord, 0,
              Microsoft.Office.Core.MsoTriState.msoFalse,
              Microsoft.Office.Core.MsoTriState.msoTrue);

              if(oText!=null)
              {
                MessageBox.Show("文档中包含指定的关键字 " + strKeyWord + " !", "搜索结果", MessageBoxButtons.OK);
                continue;
              }
            }
          }
        }
        */
      }
      finally
      {
        pptPre.Close();
        System.Runtime.InteropServices.Marshal.ReleaseComObject (pptPre);
        pptPre = null;
        pptApp.Quit();
        System.Runtime.InteropServices.Marshal.ReleaseComObject (pptApp);
        pptApp = null;
      }
    }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值