文号
t77986
阅读
4917
回复
2
收藏
2
【小程序】用VB实现的简易图片查看器
2015/11/22
IP:四川
代码很简单,只有15行(添加了两个事件)→_→
Class MainWindow
    Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
        Dim opendlg As New Microsoft.Win32.OpenFileDialog()
        If opendlg.ShowDialog() Then
            imagebox.Source = New BitmapImage(New Uri(opendlg.FileName))
        End If
    End Sub
               
    Private Sub MainWindow_Drop(sender As Object, e As DragEventArgs) Handles Me.Drop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim filelist As String() = e.Data.GetData(DataFormats.FileDrop)
            imagebox.Source = New BitmapImage(New Uri(filelist(0)))
        End If
    End Sub
End Class

界面用的WPF,XAML标记如下(都是自动生成的):
<window x:class="MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:local="clr-namespace:picview"         mc:ignorable="d"         title="图片查看器" height="350" width="525" allowdrop="True">
    <grid>
        <button x:name="button" content="打开" horizontalalignment="Left" margin="10,10,0,0" verticalalignment="Top" width="75">
        <image x:name="imagebox" margin="10,40,10,10">
    </image></button></grid>
</window>

使用.NET 3.5编写并使用app.config补丁,Win7/8/8.1/10免运行库。app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup uselegacyv2runtimeactivationpolicy="true">
        <supportedruntime version="v4.0.30319">
        <supportedruntime version="v2.0.50727">
    </supportedruntime></supportedruntime></startup>
</configuration>

运行界面如图(可使用打开按钮打开,也可拖拽):

tupian.png

程序和源代码下载(工程是VS2015格式的):

attachment icon picview.rar 53.82KB RAR 58次下载
[ 修改于11年1个月前 - 2015/11/22 11:00:21 ]
acmilan作者
11年1个月前IP:四川
798214
1楼
app.config建议把4.0.30319(Win8+带的版本)放在前面,优先匹配.NET 4.x。如果把2.0.50727放前面,控件会变成Win7样式。
引用
评论
acmilan作者
11年1个月前IP:四川
798220
2楼
用.NET3.5+app.config免库,适合编写小程序。编写大程序的话可以选择更高版本的.NET。
WPF原生支持高DPI,和Windows窗体不同,在高DPI时不会导致模糊或错位。
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的