public void ResetFormPosition(ref Preview preview) { //設定位移單位 int previewUpOffset = (int)UpDownOffsetUp.Value; //在右側顯示 if (rightSideRadioButton.Checked) { //sourcePreview if (preview.formName == sourcePreviewString) { preview.Location = new Point(this.Location.X + this.Size.Width, this.Location.Y - previewUpOffset); } //resultPreview else { if (sourcePreviewCheckBox.Checked) { preview.Location = new Point(this.Location.X + this.Size.Width, this.Location.Y - previewUpOffset + sourcePreview.Size.Height); } else {//取代source原本的位置 preview.Location = new Point(this.Location.X + this.Size.Width, this.Location.Y - previewUpOffset); } } } //在下方顯示 else { //sourcePreview if (preview.formName == sourcePreviewString) { preview.Location = new Point(this.Location.X, this.Location.Y + this.Size.Height); } //resultPreview else { if (sourcePreviewCheckBox.Checked) { preview.Location = new Point(this.Location.X + sourcePreview.Size.Width, this.Location.Y + this.Size.Height); } else {//取代source原本的位置 preview.Location = new Point(this.Location.X, this.Location.Y + this.Size.Height); } } } }
//isImageLoading是用來預載圖片用的 public void ShowPreview(ref Preview preview, string formName, string htmlText, bool isImageLoading) { //加上網頁tag,須注意meta http-equiv必須有值,才能夠顯示影片及圖片 htmlText = "<html><meta http-equiv = 'X-UA-Compatible' content='IE = edge'/><body>" + htmlText + "</body></html>"; //如果當前不存在,就new出來 if (preview == null || preview.IsDisposed) { preview = new Preview(formName, this); } //依據不同的preview重設顯示位置 ResetFormPosition(ref preview); //設定是否為圖片預載 preview.isImageLoading = isImageLoading; //寫入Document並更新網頁 preview.WriteWebBrowserDocumentAndRefresh(htmlText); //將視窗置頂 preview.Focus(); }