winform控件-devexpress18下载安装注册以及在vs中使用:
https://blog.csdn.net/badao_liumang_qizhi/article/details/100061243
参照以上将devexpress安装并引进到工具箱。
这里使用的是vs2013所以安装的devexpress是14版本。
新建winfom程序,然后拖拽一个pdfvieerr控件。然后添加一个button按钮。
双击进入button按钮的点击事件中
private void simplebutton2_click(object sender, eventargs e) { //打开pdf文件,并获取文件路径 string filepath = filedialoghelper.openpdf(); //如果不为空 if (!string.isnullorempty(filepath)) { //加载预览 其中pdfviewer1 与控件的name相对应 this.pdfviewer1.loaddocument(filepath); } }
然后新建filedialoghelper工具类,实现选择打开文件并返回路径的功能。
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace pdfexport { class filedialoghelper { public static string openpdf() { openfiledialog filedialog = new openfiledialog(); filedialog.multiselect = true; filedialog.title = "请选择文件"; filedialog.filter = "所有文件(*pdf*)|*.pdf*"; //设置要选择的文件的类型 if (filedialog.showdialog() == dialogresult.ok) { return filedialog.filename;//返回文件的完整路径 } else { return null; } } } }
在窗体上再拖拽一个button,双击进入其点击事件中。
private void simplebutton1_click_1(object sender, eventargs e) { this.pdfviewer1.savedocument(@"d:\pdf\a.pdf"); }
注:
调用自带的savedocument()方法,这里传递的是保存的路径。
其还有个重载方法:
public void savedocument(stream stream);
再拖拽一个按钮,双击进入其点击事件中。
private void simplebutton3_click(object sender, eventargs e) { this.pdfviewer1.print(); }
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论