以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  文件附件里面文件类型有可能是图片也有可能是文档 怎么实现当是图片的时候就用PictureBox打开 反之就用WebBrowser打开  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=149581)

--  作者:李孝春
--  发布时间:2020/5/6 17:11:00
--  文件附件里面文件类型有可能是图片也有可能是文档 怎么实现当是图片的时候就用PictureBox打开 反之就用WebBrowser打开
文件附件里面文件类型有可能是图片也有可能是文档  怎么实现当是图片的时候就用PictureBox打开  反之就用WebBrowser打开


当前代码如下:(能够实现PictureBox WebBrowser同时打开图片 WebBrowser打开非图片类的文件  
Dim pc2 As WinForm.PictureBox = e.Form.Controls("PictureBox1")
Dim web1 As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
web1.Address = Nothing
If Tables("收文列表.文件附件").Current Is Nothing Then
    Return
End If

Dim dr As DataRow = Tables("收文列表.文件附件").Current.DataRow
Dim fl As String =  ProjectPath &  dr("文件名")
If FileSys.FileExists(fl) AndAlso CRCCheckFile(fl) = dr.SQLGetValue("CRC值") Then \'如果本地存在同名文件且CRC校验值相同
    \'则直接使用本地文件
    web1.Address = fl
    pc2.Image= GetImage(fl)     这个部分怎么写文件类型判断呢?
Else \'否则从数据库提取文件
    If dr.SQLLoadFile("附件",fl) = False Then \'如果提取文件失败
        Messagebox.Show("附件提取失败,可能并不存在附件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Return
    End If
End If
\'Dim Proc As New Process \'打开文件
\'Proc.File = fl
\'Proc.Start()




--  作者:有点蓝
--  发布时间:2020/5/6 17:19:00
--  
判断扩展名,比如:
if fl.EndsWith(".jpg") orelse fl.EndsWith(".png") then
msgbox("图片")
else
msgbox("不是图片")
end if


--  作者:李孝春
--  发布时间:2020/5/6 17:54:00
--  
Dim pc2 As WinForm.PictureBox = e.Form.Controls("PictureBox1")
Dim kp As WinForm.TabControl = e.Form.Controls("TabControl1")
Dim web1 As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
web1.Address = Nothing
If Tables("收文列表.文件附件").Current Is Nothing Then
    Return
End If

Dim dr As DataRow = Tables("收文列表.文件附件").Current.DataRow
Dim fl As String =  ProjectPath &  dr("文件名")
If FileSys.FileExists(fl) AndAlso CRCCheckFile(fl) = dr.SQLGetValue("CRC值") Then \'如果本地存在同名文件且CRC校验值相同
    \'则直接使用本地文件
    If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") Then
        pc2.Image= GetImage(fl)
        kp.SelectedIndex=0
    Else
        web1.Address = fl   如果打开的是text文本文件的话,文件中的中文会是乱码  有没有办法修正呢?
        kp.SelectedIndex=1
    End If
    
Else \'否则从数据库提取文件
    If dr.SQLLoadFile("附件",fl) = False Then \'如果提取文件失败
        Messagebox.Show("附件提取失败,可能并不存在附件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Return
    End If
End If

--  作者:有点蓝
--  发布时间:2020/5/7 8:23:00
--  
text文本文件另存为,保存对话框下方选择不同的编码试试
--  作者:李孝春
--  发布时间:2020/5/7 8:52:00
--  回复:(有点蓝)text文本文件另存为,保存对话框下方...
默认都是保存的utf-8


如果文件是doc或者xls时候,怎么在WebBrowser打开时  不显示office工具的那些按钮呢?
[此贴子已经被作者于2020/5/7 9:16:35编辑过]

--  作者:有点蓝
--  发布时间:2020/5/7 9:31:00
--  
控制不了
--  作者:李孝春
--  发布时间:2020/5/7 9:40:00
--  回复:(有点蓝)控制不了

好的 谢谢   

再请教一下   为什么我代码如下后,需要点两次运行  才能显示图片呢?

Dim pc2 As WinForm.PictureBox = e.Form.Controls("PictureBox1")
Dim kp As WinForm.TabControl = e.Form.Controls("TabControl1")
Dim web1 As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
web1.Address = Nothing


If FileSys.DirectoryExists(ProjectPath & "预览文件") Then \'如果目录存在
    
    If Tables("收文列表.文件附件").Current Is Nothing Then
        Return
    End If
    
    Dim dr As DataRow = Tables("收文列表.文件附件").Current.DataRow
    
    Dim fl As String =  ProjectPath & "预览文件\\" &  dr("文件名")
    If FileSys.FileExists(fl) AndAlso CRCCheckFile(fl) = dr.SQLGetValue("CRC值") Then \'如果本地存在同名文件且CRC校验值相同
        \'则直接使用本地文件
        If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") OrElse fl.EndsWith(".bmp") OrElse fl.EndsWith(".gif") Then
            pc2.Image= GetImage(fl)
            kp.SelectedIndex=0
        Else  If fl.EndsWith(".txt") OrElse fl.EndsWith(".zip") OrElse fl.EndsWith(".rar") OrElse fl.EndsWith(".pdf") OrElse fl.EndsWith(".exe") Then
            Dim Proc As New Process \'打开文件
            Proc.File = fl
            Proc.Start()
        Else
            web1.Address = fl
            kp.SelectedIndex=1
        End If
        
    Else \'否则从数据库提取文件
        If dr.SQLLoadFile("附件",fl) = False Then \'如果提取文件失败
            Messagebox.Show("附件提取失败,可能并不存在附件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If
    End If
End If
[此贴子已经被作者于2020/5/7 9:54:06编辑过]