<title>Monkeybread Software - MBS FileMaker Plugin: WinPreview.CreateWithControl</title></head><body>WinPreview.CreateWithControl
----------------------------

Creates a new preview on the given window covering the area of the given control.

<style>
td.grau 
{
background-color:#EEE;
text-align: center;
}
</style>| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [WinPDF](component_WinPDF.md) | [13.3](newinversion133.md) | ❌ No | ✅ Yes | ❌ No | ❌ No | ❌ No |

MBS( "WinPreview.CreateWithControl"; WindowRef; ControlName { ; DX; DY } ) 

**MBS**( **"WinPreview.CreateWithControl";** /\* Creates a new preview on the given window covering the area of the given control. \*/  
**$WindowRef**; /\* Window Reference is the unique OS level window ID. You can obtain this by using the [Window.FindByTitle](WindowFindByTitle.md) or [Window.FindByIndex](WindowFindByIndex.md) functions. Pass zero to access the frontmost window.e.g. 0 \*/   
**$ControlName**; /\* The name of the control on your FileMaker form.   
e.g. you can place a rectangle there to define the position.e.g. "mymedia" \*/   
**$DX**; /\* Optional; A delta to move drop area more to left or right.e.g. 0 \*/   
**$DY**) /\* Optional; A delta to move drop area more to top or bottom.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| WindowRef | Window Reference is the unique OS level window ID. You can obtain this by using the [Window.FindByTitle](WindowFindByTitle.md) or [Window.FindByIndex](WindowFindByIndex.md) functions. Pass zero to access the frontmost window. | 0 |  |
| ControlName | The name of the control on your FileMaker form.    e.g. you can place a rectangle there to define the position. | "mymedia" |  |
| DX | A delta to move drop area more to left or right. | 0 | Optional |
| DY | A delta to move drop area more to top or bottom. | 0 | Optional |

### Result

Returns reference number or error.

### Description

Creates a new preview on the given window covering the area of the given control.  
A way to display a PDF Viewer in FileMaker independent of an interactive container.  
Available on Windows 10 and newer.  
  
If you use a register (tab controls) on the window, be aware that the preview actually is in front of the register (tab controls). You may hide the preview if another register is visible.  
  
Use [WinPreview.Release](WinPreviewRelease.md) later to destroy the text view.  
Preview reference numbers are starting at 92000 and counting up for each new text view.  
  
When creating on a card window, please pass reference to parent window or just 0 for front window. On MacOS you may need to pass delta y value to adjust position.  
  
If you create a control on a new window, you may do window update command in your script first to have FileMaker actually build the window with controls and display it. A short script pause or using [FM.RunScriptLater](FMRunScriptLater.md) with 0.1 delay can help having all controls draw themselves. Then you can use this command to put our control on top. We use GetLayoutObjectAttribute() to query left, top, width and height and this gives empty value if control is not yet here.  
  
Creation fails to pick the right window in case the window is selected by name and the window name is not unique. In that case better work with window reference numbers or just pass 0 for current front window.  
  
Please call [WinPreview.Release](WinPreviewRelease.md) later to free the view.  
### Examples

Create with placeholder control:

\# let FileMaker draw layout   
Pause/Resume Script \[ Duration (seconds): ,1 \]   
\#   
\# now add control   
Set Variable \[ $$preview ; Value: MBS( "WinPreview.CreateWithControl"; 0; "placeholder") \]   
\#   
If \[ MBS("IsError") \]   
 Show Custom Dialog \[ "Failed to create preview contr…" ; $$preview \]   
 Set Variable \[ $$preview ; Value: "" \]   
End If  
\#   
\# load content   
If \[ not IsEmpty ( PDF Viewer::PDF Container ) \]   
 Set Variable \[ $r ; Value: MBS( "[WinPreview.LoadContainer](WinPreviewLoadContainer.md)"; $$preview; PDF Viewer::PDF Container ) \]   
 If \[ MBS("IsError") \]   
 Show Custom Dialog \[ "Failed to load container" ; $r \]   
 End If  
Else If \[ not IsEmpty ( PDF Viewer::PDF Path ) \]   
 Set Variable \[ $r ; Value: MBS( "[WinPreview.LoadFile](WinPreviewLoadFile.md)"; $$preview; PDF Viewer::PDF Path ) \]   
 If \[ MBS("IsError") \]   
 Show Custom Dialog \[ "Failed to load file" ; $r \]   
 End If  
End If

### See also

- [FM.RunScript](FMRunScript.md)
- [ImageView.CreateWithControl](ImageViewCreateWithControl.md)
- [IsError](IsError.md)
- [MapView.CreateWithControl](MapViewCreateWithControl.md)
- [TextView.CreateWithControl](TextViewCreateWithControl.md)
- [WebView.CreateWithControl](WebViewCreateWithControl.md)
- [Window.FindByIndex](WindowFindByIndex.md)
- [Window.FindByTitle](WindowFindByTitle.md)
- [WinPreview.LoadFile](WinPreviewLoadFile.md)
- [WinPreview.SetFrameWithControl](WinPreviewSetFrameWithControl.md)

This function checks for a paid license.

Created 12nd June 2023 , last changed 12nd June 2023

  
[WinPreview.Create](WinPreviewCreate.md) - [WinPreview.List](WinPreviewList.md)

💬 [Ask a question or report a problem](https://www.monkeybreadsoftware.com/feedback/?what=filemaker&path=WinPreview.CreateWithControl)

[HTML Version](WinPreviewCreateWithControl.shtml)