0

我只是想知道这里是否有人知道如何编写代码如何检查项目是否为图像,然后使用 Windows 图像预览打开,否则使用媒体播放器中的构建打开。

代码是这样的:

private bool listbox3job()
{
    AxWMPLib.AxWindowsMediaPlayer axWmp = wfh.Child as AxWMPLib.AxWindowsMediaPlayer;
    WMPLib.IWMPPlaylist playlist = axWmp.newPlaylist("myPlaylist", string.Empty);
    DateTime? start = starttid2.Value;
    DateTime? end = sluttid2.Value;
    DateTime now = DateTime.Now;

    if (start == null || end == null)
    {
        return false;
    }
    else if (now >= start.Value && now <= end.Value)
    {
        foreach (var selected in listBox3.Items)
        {
            string s = selected.ToString();
            if (listBox3Dict.ContainsKey(s))
            {
    if (extentions.Contains(System.IO.Path.GetExtension(s).ToUpperInvariant()))
    {
        Process process = new Process();
        process.StartInfo.FileName = "rundll32.exe";
        process.StartInfo.Arguments = @"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " + listBox3Dict[s];
        process.Start();
        Thread.Sleep(7000);
        {
            exit();
        }
    }
    else
    {
                WMPLib.IWMPMedia temp = axWmp.newMedia(listBox3Dict[s]);  
                playlist.appendItem(temp);
                axWmp.settings.setMode("loop", true);
                axWmp.settings.autoStart = true;
                axWmp.currentPlaylist = playlist; 
    }
            }
        }
                return true;
    }
    return false;
}
4

1 回答 1

1

这个给你

 public static List<string> extentions = new List<string> { ".JPG", ".JPE", ".BMP", ".GIF", ".PNG" };

private void Open()
{

    foreach (var selected in listBox4.Items)
    {
        string s = selected.ToString();

        if (listBox4Dict.ContainsKey(s))
        {
            if (extentions.Contains(Path.GetExtension(s).ToUpperInvariant()))
            {
                Process process = new Process();
                process.StartInfo.FileName = "rundll32.exe";
                process.StartInfo.Arguments = @"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " +listBox4Dict[s];
                process.Start();
                process.WaitForExit();
                while (!process.HasExited)
                    Thread.Sleep(500);
            }
            else
            {
                Mediaplayer.URL = (listBox4Dict[s]);
            }
        }
    }
}
于 2013-04-20T22:20:48.813 回答