Last active
January 15, 2025 15:49
-
-
Save cedx/fc379d01b5676a428a63f3197180b257 to your computer and use it in GitHub Desktop.
Node API for .NET: JavaScript + .NET Interop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<GenerateNodeApiTypeDefinitionsForReferences>true</GenerateNodeApiTypeDefinitionsForReferences> | |
<NodeApiAssemblyJSModuleType>esm</NodeApiAssemblyJSModuleType> | |
<OutDir>bin</OutDir> | |
<TargetFramework>net8.0-windows</TargetFramework> | |
<UseWindowsForms>true</UseWindowsForms> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.JavaScript.NodeApi" Version="*"/> | |
<PackageReference Include="Microsoft.JavaScript.NodeApi.Generator" Version="*"/> | |
<PackageReference Include="System.Drawing.Common" Version="*"/> | |
<PackageReference Include="System.Drawing.Primitives" Version="*"/> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dotnet from "node-api-dotnet/net8.0"; | |
dotnet.load("System.Drawing.Common"); | |
dotnet.load("System.Drawing.Primitives"); | |
dotnet.load("System.Windows.Forms"); | |
const { | |
Icon, | |
Point, | |
Size | |
} = dotnet.System.Drawing; | |
const { | |
Application, | |
Button, | |
DialogResult, | |
Form, FormBorderStyle, FormStartPosition, | |
Label, | |
MessageBox, MessageBoxButtons, MessageBoxIcon, | |
TextBox | |
} = dotnet.System.Windows.Forms; | |
Application.EnableVisualStyles(); | |
const productKeyLabel = new Label; | |
productKeyLabel.Location = new Point(10, 10); | |
productKeyLabel.Size = new Size(390, 20); | |
productKeyLabel.Text = "Référence Sage :"; | |
const productKeyInput = new TextBox; | |
productKeyInput.Location = new Point(10, 30); | |
productKeyInput.Size = new Size(390, 20); | |
const pathOrUrlLabel = new Label; | |
pathOrUrlLabel.Location = new Point(10, 60); | |
pathOrUrlLabel.Size = new Size(390, 20); | |
pathOrUrlLabel.Text = "Chemin ou URL de l'image :"; | |
const pathOrUrlInput = new TextBox; | |
pathOrUrlInput.Location = new Point(10, 80); | |
pathOrUrlInput.Size = new Size(390, 20); | |
const okButton = new Button; | |
okButton.DialogResult = DialogResult.OK; | |
okButton.Location = new Point(240, 120); | |
okButton.Size = new Size(75, 26); | |
okButton.Text = "OK"; | |
const cancelButton = new Button; | |
cancelButton.DialogResult = DialogResult.Cancel; | |
cancelButton.Location = new Point(325, 120); | |
cancelButton.Size = new Size(75, 26); | |
cancelButton.Text = "Annuler"; | |
const form = new Form; | |
form.AcceptButton = okButton; | |
form.CancelButton = cancelButton; | |
form.FormBorderStyle = FormBorderStyle.FixedSingle; | |
// form.Icon = new Icon(`${import.meta.dirname}/res/favicon.ico`); | |
form.MaximizeBox = false; | |
form.Size = new Size(430, 195); | |
form.StartPosition = FormStartPosition.CenterScreen; | |
form.Text = "Importer l'image d'un produit sur Grossiste"; | |
form.TopMost = true; | |
// form.Add_Shown({ productKeyInput.Select() }); | |
form.Controls.AddRange([ | |
productKeyLabel, | |
productKeyInput, | |
pathOrUrlLabel, | |
pathOrUrlInput, | |
okButton, | |
cancelButton | |
]); | |
form.ShowDialog(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using Namespace System.Drawing | |
Using Namespace System.Windows.Forms | |
Set-StrictMode -Version Latest | |
Add-Type -AssemblyName System.Drawing | |
Add-Type -AssemblyName System.Windows.Forms | |
[Application]::EnableVisualStyles() | |
$productKeyLabel = [Label]::New() | |
$productKeyLabel.Location = [Point]::New(10, 10) | |
$productKeyLabel.Size = [Size]::New(390, 20) | |
$productKeyLabel.Text = "Référence Sage :" | |
$productKeyInput = [TextBox]::New() | |
$productKeyInput.Location = [Point]::New(10, 30) | |
$productKeyInput.Size = [Size]::New(390, 20) | |
$pathOrUrlLabel = [Label]::New() | |
$pathOrUrlLabel.Location = [Point]::New(10, 60) | |
$pathOrUrlLabel.Size = [Size]::New(390, 20) | |
$pathOrUrlLabel.Text = "Chemin ou URL de l'image :" | |
$pathOrUrlInput = [TextBox]::New() | |
$pathOrUrlInput.Location = [Point]::New(10, 80) | |
$pathOrUrlInput.Size = [Size]::New(390, 20) | |
$okButton = [Button]::New() | |
$okButton.DialogResult = [DialogResult]::OK | |
$okButton.Location = [Point]::New(240, 120) | |
$okButton.Size = [Size]::New(75, 26) | |
$okButton.Text = "OK" | |
$cancelButton = [Button]::New() | |
$cancelButton.DialogResult = [DialogResult]::Cancel | |
$cancelButton.Location = [Point]::New(325, 120) | |
$cancelButton.Size = [Size]::New(75, 26) | |
$cancelButton.Text = "Annuler" | |
$form = [Form]::New() | |
$form.AcceptButton = $okButton | |
$form.CancelButton = $cancelButton | |
$form.FormBorderStyle = [FormBorderStyle]::FixedSingle | |
# $form.Icon = [Icon]::New("$PSScriptRoot/res/favicon.ico") | |
$form.MaximizeBox = $False | |
$form.Size = [Size]::New(430, 195) | |
$form.StartPosition = [FormStartPosition]::CenterScreen | |
$form.Text = "Importer l'image d'un produit sur Grossiste" | |
$form.TopMost = $True | |
$form.Add_Shown({ $productKeyInput.Select() }) | |
$form.Controls.AddRange(@( | |
$productKeyLabel, | |
$productKeyInput, | |
$pathOrUrlLabel, | |
$pathOrUrlInput, | |
$okButton, | |
$cancelButton | |
)) | |
$form.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment