public override void DoAction(string path, FileType parFileType, frmMain frm) { System.Threading.Thread tt = new System.Threading.Thread(delegate() { try { if (FileExists(path)) { if (parFileType.PreviewType == null) { ShowError("Preview not available"); } else { Type t = parFileType.PreviewType; Form f = new Form(); Panel pnl = new Panel(); pnl.Dock = System.Windows.Forms.DockStyle.Fill; pnl.Location = new System.Drawing.Point(0, 0); pnl.Name = "pnlPreview"; pnl.Size = new System.Drawing.Size(96, 77); pnl.TabIndex = 1; f.Controls.Add(pnl); if (pnl.Controls.Count > 0) { Control pOld = pnl.Controls[0]; pOld.Dispose(); } pnl.Controls.Clear(); IPreview p = (IPreview)Activator.CreateInstance(t); pnl.Controls.Add((Control)p); ((Control)p).Dock = DockStyle.Fill; f.Load += delegate(object sender, EventArgs e) { p.Preview(path); }; Application.Run(f); } } } catch (Exception ex) { ShowError("An error occured while loading preview control"); } }); tt.SetApartmentState(System.Threading.ApartmentState.STA); tt.Start(); }
public override void DoAction(string path, FileType parFileType, frmPerview frm) { try { if (FileExists(path)) { if (parFileType.PreviewType == null) { ShowError("Preview not available"); } else { Type t = parFileType.PreviewType; //SplitContainer sc=(SplitContainer)frm.Controls.Find("sc", true)[0]; //Panel pnl=(Panel)sc.Panel2.Controls.Find("pnlPreview", true)[0]; Panel pnl = (Panel)frm.Controls.Find("pnlPreview", true)[0]; if (pnl.Controls.Count > 0) { Control pOld = pnl.Controls[0]; pOld.Dispose(); } pnl.Controls.Clear(); //sc.Panel2Collapsed = false; IPreview p = (IPreview)Activator.CreateInstance(t); pnl.Controls.Add((Control)p); ((Control)p).Dock = DockStyle.Fill; p.Preview(path); frm.SetPreviewPanelButtonsVisibility(); } } } catch (Exception ex) { ShowError("An error occured while loading preview control"); frm.SetPreviewPanelButtonsVisibility(); } }
private void frmPerview_Load(object sender, EventArgs e) { ft = GetFileType(strPath); try { if (FileExists(strPath)) { if (ft.PreviewType == null) { ShowError("Preview not available"); } else { Type t = ft.PreviewType; //SplitContainer sc=(SplitContainer)frm.Controls.Find("sc", true)[0]; //Panel pnl=(Panel)sc.Panel2.Controls.Find("pnlPreview", true)[0]; Panel pnl = (Panel)this.Controls.Find("pnlPreview", true)[0]; if (pnl.Controls.Count > 0) { Control pOld = pnl.Controls[0]; pOld.Dispose(); } pnl.Controls.Clear(); //sc.Panel2Collapsed = false; IPreview p = (IPreview)Activator.CreateInstance(t); pnl.Controls.Add((Control)p); ((Control)p).Dock = DockStyle.Fill; p.Preview(strPath); } } } catch (Exception ex) { ShowError("An error occured while loading preview control"); } }
private static void PreviewFile(string path, object file, Type PreviewType, object caller, System.Windows.Point?pos) { System.Threading.Thread tt = new System.Threading.Thread(delegate() { try { if (file != null || File.Exists(path) || Directory.Exists(path)) { if (PreviewType == null) { MessageBox.Show("Preview not available"); } else { Type t = PreviewType; if (t.GetInterface("IPreviewControl") != null) { Form f = new Form(); Panel pnl = new Panel(); pnl.Dock = System.Windows.Forms.DockStyle.Fill; pnl.Location = new System.Drawing.Point(0, 0); pnl.Name = "pnlPreview"; pnl.Size = new System.Drawing.Size(96, 77); pnl.TabIndex = 1; f.Controls.Add(pnl); if (pnl.Controls.Count > 0) { Control pOld = pnl.Controls[0]; pOld.Dispose(); } pnl.Controls.Clear(); IPreviewControl p = (IPreviewControl)Activator.CreateInstance(t); pnl.Controls.Add((Control)p); ((Control)p).Dock = DockStyle.Fill; f.Load += delegate(object sender, EventArgs e) { p.Preview(path); }; f.StartPosition = FormStartPosition.CenterScreen; f.ControlBox = false; f.Text = ""; //f.SetDesktopLocation( //f.FormBorderStyle = FormBorderStyle.None; f.PreviewKeyDown += delegate(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Space) { f.Close(); } }; ((Control)p).PreviewKeyDown += delegate(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Space) { f.Close(); } }; f.FormClosing += delegate(object sender, FormClosingEventArgs e) { if (OpenPreview == f) { OpenPreview = null; } }; OpenPreview = f; Application.Run(f); } else { IPreview p = (IPreview)Activator.CreateInstance(t); OpenPreview = p; p.Preview(file, caller, pos); } } } } catch (Exception) { MessageBox.Show("An error occured while loading preview control"); } }); tt.SetApartmentState(System.Threading.ApartmentState.STA); tt.Start(); }