Skip to content

Commit

Permalink
vb. net example
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Oct 22, 2020
1 parent 47defbd commit 74499cd
Show file tree
Hide file tree
Showing 12 changed files with 519 additions and 1 deletion.
22 changes: 22 additions & 0 deletions DemoApp.VB/ApplicationEvents.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Imports Microsoft.VisualBasic.ApplicationServices

Namespace My
' The following events are available for MyApplication:
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.

' **NEW** ApplyHighDpiMode: Raised when the application queries the HighDpiMode to set it for the application.

' Example:

' Private Sub MyApplication_ApplyHighDpiMode(sender As Object, e As ApplyHighDpiModeEventArgs) Handles Me.ApplyHighDpiMode
' e.HighDpiMode = HighDpiMode.PerMonitorV2
' End Sub

Partial Friend Class MyApplication

End Class
End Namespace
50 changes: 50 additions & 0 deletions DemoApp.VB/DemoApp.VB.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<RootNamespace>DemoApp.VB</RootNamespace>
<StartupObject>Sub Main</StartupObject>
<UseWindowsForms>true</UseWindowsForms>
<MyType>WindowsForms</MyType>
</PropertyGroup>

<ItemGroup>
<Import Include="System.Data" />
<Import Include="System.Drawing" />
<Import Include="System.Windows.Forms" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NotificationWindow\NotificationWindow.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="My Project\Application.Designer.vb">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Update="My Project\Resources.Designer.vb">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="My Project\Resources.resx">
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<Generator>PublicVbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<None Update="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions DemoApp.VB/Form1.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions DemoApp.VB/Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
8 changes: 8 additions & 0 deletions DemoApp.VB/Form1.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Public Class Form1
Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click
Dim notify = New NotificationWindow.PopupNotifier()
notify.Image = My.Resources.icon
notify.ContentText = "test"
notify.Popup()
End Sub
End Class
69 changes: 69 additions & 0 deletions DemoApp.VB/My Project/Application.Designer.HighDpi.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Option Strict On
Option Explicit On

'This constant indicates whether the Application Framework is in use.
#Const APPLICATION_FRAMEWORK = True

#If APPLICATION_FRAMEWORK Then

#If NET5_0 And Not NET6_0 Then

Imports System.Collections.ObjectModel

Namespace My

Partial Friend Class MyApplication

Public Event ApplyHighDpiMode(sender As Object, e As ApplyHighDpiModeEventArgs)

Private _highDpiMode As HighDpiMode?

Friend Shadows Property HighDpiMode As HighDpiMode
Get
Return If(
_highDpiMode Is Nothing,
Application.HighDpiMode,
_highDpiMode.Value)
End Get
Set(value As HighDpiMode)
_highDpiMode = value
End Set
End Property

' IMPORTANT:
' If this method causes an compilation error after you've unchecked 'Application Framework'
' in the project properties, go to the top of this file and change the value to 'False' in this line:
' #Const APPLICATION_FRAMEWORK = False

' For more about using WinForms without the Application Framework
' see: https://aka.ms/visualbasic-appframework-net5
Protected Overrides Function OnInitialize(commandLineArgs As ReadOnlyCollection(Of String)) As Boolean
Dim eventArgs = New ApplyHighDpiModeEventArgs(
If(
_highDpiMode Is Nothing,
HighDpiMode.SystemAware,
_highDpiMode.Value))

RaiseEvent ApplyHighDpiMode(Me, eventArgs)

Windows.Forms.Application.SetHighDpiMode(eventArgs.HighDpiMode)

Return MyBase.OnInitialize(commandLineArgs)
End Function
End Class

Public Class ApplyHighDpiModeEventArgs
Inherits EventArgs

Public Sub New(highDpiMode As HighDpiMode)
Me.HighDpiMode = highDpiMode
End Sub

Public Property HighDpiMode As HighDpiMode

End Class

End Namespace

#End If ' #If NET5_0 And Not NET6_0
#End If ' #If APPLICATION_FRAMEWORK
38 changes: 38 additions & 0 deletions DemoApp.VB/My Project/Application.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions DemoApp.VB/My Project/Application.myapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>true</MySubMain>
<MainForm>Form1</MainForm>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>
73 changes: 73 additions & 0 deletions DemoApp.VB/My Project/Resources.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 74499cd

Please sign in to comment.