有关多个窗体 打开同个文件的疑问(菜鸟求解)
时间:2011-12-08
来源:互联网
小弟初学C#,碰到一个问题,我要让winform显示指定文件夹中的PDF文件,我使用了adobe reader自带的com组件,然后当指定文件夹中的PDF文件被替换的时候,窗体中的PDF组件也随着变换,我使用了.net的filesystemwatcher控件,随后问题也就来了,当打开一个窗口时,文件显示和替换后显示都没有问题,但同时打开5个窗口时,替换文件夹中的文件,则只能打开两个,其他一个显示在载入,剩下两个则完全没有反应,总结了下,应该是filesystemwatcher下的 change 事件 同时让5个窗体一起访问了文件,导致了文件的无法载入,但我不知道解决的方法和思路,还是有相应的技术处理这种情况,(如果放在局域网,这种情况要如何解决),求各位大侠指点迷津...
C# code
C# code
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.IO; namespace PDFDisplay { public partial class Main : Form { public Main() { InitializeComponent(); } AxAcroPDFLib.AxAcroPDF axAcroPDF = new AxAcroPDFLib.AxAcroPDF(); private void Main_Load(object sender, EventArgs e) { fileSystemWatcher1.Path = GetPDFDocumentPath(); fileSystemWatcher1.InternalBufferSize = 1024; axAcroPDF.Location = new System.Drawing.Point(0, 24); axAcroPDF.Size = new System.Drawing.Size(292, 242); axAcroPDF.Dock = DockStyle.Fill; this.Controls.Add(axAcroPDF); axAcroPDF.setCurrentPage(GetFilePage());//获取要显示的页码 axAcroPDF.LoadFile(GetPDFFilePath(GetPDFDocumentPath())); } /// <summary> /// 获取文件夹位置 /// </summary> /// <returns></returns> private string GetPDFDocumentPath() { string ConfigPath = Application.StartupPath + "/Config/FilePath.ini"; string PDFDocumentPath = ""; FileInfo fif = new FileInfo(ConfigPath); DirectoryInfo dif = new DirectoryInfo(Application.StartupPath+"/Config"); if (dif.Exists) { if (fif.Exists) { StreamReader sr = new StreamReader(ConfigPath); PDFDocumentPath = sr.ReadLine(); sr.Close(); if (PDFDocumentPath.Length < 0) { MessageBox.Show("FilePath.ini 文件中没有配置完全!"); } } else { MessageBox.Show("文件不存在!"); } } else { MessageBox.Show("文件夹不存在!"); } return PDFDocumentPath; } /// <summary> /// 获取PDF文件路径 /// </summary> /// <param name="PDFDocumentPath">PDF文件夹路径</param> /// <returns></returns> private string GetPDFFilePath(string PDFDocumentPath) { string PDFFilePath=""; DirectoryInfo dif = new DirectoryInfo(PDFDocumentPath); if (dif.Exists) { FileInfo[] fif = dif.GetFiles(); foreach (FileInfo PDFFileName in fif) { PDFFilePath = PDFDocumentPath + PDFFileName.Name.ToString(); } } else { MessageBox.Show("PDF存放文件夹已被移动或删除!"); } return PDFFilePath; } private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e) { axAcroPDF.LoadFile(GetPDFFilePath(GetPDFDocumentPath())); } /// <summary> /// 获取文件路径 /// </summary> /// <returns></returns> private int GetFilePage() { string FilePage = ""; string ConfigPath = Application.StartupPath + "/Config/FilePath.ini"; FileInfo fif = new FileInfo(ConfigPath); DirectoryInfo dif = new DirectoryInfo(Application.StartupPath+"/Config"); if (dif.Exists) { if (fif.Exists) { StreamReader sr = new StreamReader(ConfigPath); sr.ReadLine(); FilePage = sr.ReadLine(); sr.Close(); } } if (FilePage==null ) { return 1; } else { return Int32.Parse(FilePage); } } } }
作者: sandra311 发布时间: 2011-12-08
顶下吧。。。。完全不会。。。
作者: fengyi9989 发布时间: 2011-12-08
顶下吧。。。。完全不会。。。
作者: xxxqingyu 发布时间: 2011-12-08
该回复于2011-12-08 10:59:13被管理员删除
- 对我有用[0]
- 丢个板砖[0]
- 引用
- 举报
- 管理
- TOP
|
#4楼 得分:0回复于:2011-12-08 11:48:59
|
作者: xisuo1110 发布时间: 2011-12-08
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28