Csharp: winform PDF view control use Adobe Reader X
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using AcroPDFLib;//引用COM組件Adobe Acrobat Browser Control Type Library 1.0 //http://www.adobe.com/devnet/acrobat/sdk/eula.html 10 using System.Runtime.InteropServices; 11 12 namespace WindowsChineseCalender 13 { 14 /// <summary> 15 ///安裝 Adobe Reader X 16 /// winform pdf view control 17 /// Geovin Du 塗聚文 18 /// 20121022 19 /// </summary> 20 public partial class PDFviewControlForm : Form 21 { 22 23 [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 24 static extern uint GetShortPathName( 25 [MarshalAs(UnmanagedType.LPTStr)] string lpszLongPath, 26 [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszShortPath, 27 uint cchBuffer); 28 29 /// <summary> 30 /// 31 /// </summary> 32 public PDFviewControlForm() 33 { 34 InitializeComponent(); 35 this.addressLeft.Text = "http://www.dusystem.com/%E4%BD%8F%E6%88%BF%E5%92%8C%E5%9F%8E%E4%B9%A1%E5%BB%BA%E8%AE%BE%E9%83%A8%E7%9D%A3%E5%AF%9F%E5%8A%9E%E5%85%AC%E5%AE%A4201200825.pdf"; 36 37 } 38 /// <summary> 39 /// 40 /// </summary> 41 /// <param name="sender"></param> 42 /// <param name="e"></param> 43 private void PDFviewControlForm_Load(object sender, EventArgs e) 44 { 45 46 } 47 /// <summary> 48 /// 瀏覽本地文件 49 /// 塗聚文 50 /// </summary> 51 /// <param name="sender"></param> 52 /// <param name="e"></param> 53 private void browseButtonLeft_Click(object sender, EventArgs e) 54 { 55 56 OpenFileDialog openFile = new OpenFileDialog(); 57 DialogResult result = openFile.ShowDialog(); 58 59 60 if (result == DialogResult.Cancel) 61 return; 62 63 64 string strFileName = openFile.FileName; 65 66 67 string strFileNameDup = strFileName; 68 if (strFileNameDup.ToUpper().EndsWith(".PDF")) 69 { 70 addressLeft.Text = strFileName; 71 } 72 else 73 MessageBox.Show(this, "請選擇PDF文件!", "文件類型錯誤", MessageBoxButtons.OK, 74 MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 75 } 76 /// <summary> 77 /// 打開文件 78 /// </summary> 79 /// <param name="sender"></param> 80 /// <param name="e"></param> 81 private void goButtonLeft_Click(object sender, EventArgs e) 82 { 83 if (0 == addressLeft.Text.Length) 84 MessageBox.Show(this, "輸入正解的 \"地址\"比 !", "錯誤提示", 85 MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 86 if (addressLeft.Text.StartsWith("http://")) 87 pdfWindowLeft.src = addressLeft.Text; //網絡文件地址 88 else 89 { 90 //本地文件 91 StringBuilder shortFileName = new StringBuilder(4096); 92 uint shortFileNameSize = (uint)shortFileName.Capacity; 93 if (GetShortPathName(addressLeft.Text, shortFileName, shortFileNameSize) != 0) 94 pdfWindowLeft.LoadFile(shortFileName.ToString()); 95 else 96 MessageBox.Show(this, "不正確的文件.", "需正確的文件", 97 MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 98 } 99 } 100 } 101 }
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
CSharp code
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2009-10-23 cookieLibrary.js 写入cookie的JavaScript代码库