AddFile
向PictureViewer中添加图片。
语法:
AddFile(FileName)
FileName: 要添加的图片文件名。
示例一
添加本地图片:
Dim
dlg As
New
OpenFileDialog
Dim
piv As
WinForm.PictureViewer
= e.Form.Controls("PictureViewer1")
dlg.Filter=
"图形文件|*.bmp;*.jpg;*.gif"
If
dlg.ShowDialog
= DialogResult.OK
Then
piv.AddFile(dlg.FileName)
End
If
示例二
如果想将添加的图片文件自动复制到Attachments目录,就像内置的增加按钮一项,可以将代码改为:
Dim
dlg As
New
OpenFileDialog
Dim
piv As
WinForm.PictureViewer
= e.Form.Controls("PictureViewer1")
dlg.Filter=
"图形文件|*.bmp;*.jpg;*.gif"
If
dlg.ShowDialog
= DialogResult.OK
Then
Dim pth
As String =
ProjectPath &
"Attachments\"
If dlg.FileName.ToLower.StartsWith(pth.ToLower)
Then
'如果文件来自Attachments目录
piv.AddFile(dlg.FileName.SubString(pth.Length))
Else
'如果不是
FileSys.CopyFile(dlg.FileName,
pth &
FileSys.GetName(dlg.FileName))
piv.AddFile(FileSys.GetName(dlg.FileName))
End
If
End
If
示例三
如果使用FTP管理远程图片,可以参考下面的代码添加图片:
Dim
piv As
WinForm.PictureViewer
= e.Form.Controls("PictureViewer1")
Dim
Files As
List(of
String) = piv.FtpClient.SelectFile()
For
Each File
As String
In Files
piv.AddFile(File)
Next