Skip to content

Instantly share code, notes, and snippets.

@alshell7
Last active March 25, 2017 20:28
Show Gist options
  • Save alshell7/b681d44d14388b8f5cb431c3a0a58538 to your computer and use it in GitHub Desktop.
Save alshell7/b681d44d14388b8f5cb431c3a0a58538 to your computer and use it in GitHub Desktop.
Visual Studio (VB.Net) snippets
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Fade In and Out Effect</Title>
<Author>Alshell7</Author>
<Description>Does Fade In and Fade Out Effect, during form load and closing respectively.</Description>
<Shortcut>FormFadeEffect</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.Drawing.dll</Assembly>
</Reference>
<Reference>
<Assembly>System.Windows.Forms.dll</Assembly>
</Reference>
<Reference>
<Assembly>System.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Runtime.InteropServices</Namespace>
</Import>
<Import>
<Namespace>System.Threading</Namespace>
</Import>
</Imports>
<Declarations>
<Object>
<ID>formName</ID>
<Type>Form</Type>
<ToolTip>The form in which the snippet is inserted.</ToolTip>
<Default>Me</Default>
</Object>
</Declarations>
<Code Language="VB" Kind="method decl">
<![CDATA[
Private Sub $formName$_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
DoFadeInEffect()
End Sub
Private Sub $formName$_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
DoFadeOutEffect()
End Sub
Public Sub DoFadeInEffect()
For fadein = 0.0 To 1.1 Step 0.1
Me.Opacity = fadein
Me.Refresh()
Threading.Thread.Sleep(50)
Next
End Sub
Public Sub DoFadeOutEffect()
For fadeout = 1.1 To 0.0 Step -0.1
Me.Refresh()
Me.Opacity = fadeout
Threading.Thread.Sleep(50)
Next
End
End Sub
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Open any document with given extension from Resource file (.resx)</Title>
<Author>Allshell7</Author>
<Description>Opens any document from Resources</Description>
<Shortcut>conUp</Shortcut>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>System.Runtime.InteropServices</Namespace>
</Import>
<Import>
<Namespace>System.IO</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>Document</ID>
<Type>Byte()</Type>
<ToolTip>Replace with location of the file from Resources</ToolTip>
<Default>My.Resources.myfile</Default>
</Literal>
<Literal>
<ID>DocumentName</ID>
<Type>String</Type>
<ToolTip>Replace with the name of document which you would like to give.</ToolTip>
<Default>"MyOutputfile"</Default>
</Literal>
<Literal>
<ID>Extension</ID>
<Type>String</Type>
<ToolTip>Replace with the respective extension of your document.</ToolTip>
<Default>"txt"</Default>
</Literal>
<Literal>
<ID>Eventname</ID>
<Type>Keyword</Type>
<ToolTip>Replace with the event you prefer for.</ToolTip>
<Default>Mybase.Load</Default>
</Literal>
</Declarations>
<Code Language="VB" Kind="method body">
<![CDATA[
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OutputFileFromResource($Document$, $DocumentName$, $Extension$)
End Sub
Public Shared Sub OutputFileFromResource(ByRef Document As Byte(), ByVal DocumentName As String, ByVal extension As String)
'Note that the exception made to the sub is because, the
'solution needs to have code access permission to be set.
'Otherwise, due to security IO exeptions, document is not likely
'to be opened.
Try
Dim FullDocName As String = DocumentName + "." + extension
Using TempFile As New FileStream(FullDocName, FileMode.Create)
TempFile.Write(Document, 0, Document.Length)
End Using
Process.Start(FullDocName)
Catch ex As Security.SecurityException When Form1.Visible = True
My.Application.Log.WriteException(ex)
MsgBox("Error occured while opening the document." & vbCrLf & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Glass Effect</Title>
<Author>Alshell7</Author>
<Description>This adds the visual transparent glass effect using desktop window manager(dwmapi.dll) to the complete form.</Description>
<Shortcut>FormEffect</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.Drawing.dll</Assembly>
</Reference>
<Reference>
<Assembly>System.Windows.Forms.dll</Assembly>
</Reference>
<Reference>
<Assembly>System.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>Microsoft.VisualBasic</Namespace>
</Import>
<Import>
<Namespace> System.Runtime.InteropServices</Namespace>
</Import>
<Import>
<Namespace>System.Threading</Namespace>
</Import>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Declarations>
<Object>
<ID>formName</ID>
<Type>Form</Type>
<ToolTip>The form in which the snippet is inserted.</ToolTip>
<Default>Me</Default>
</Object>
</Declarations>
<Code Language="VB" Kind ="method decl">
<![CDATA[Private Sub $formName$_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
PerformGlassing()
End Sub
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> Public Structure Side
Public Left As Integer
Public Right As Integer
Public Top As Integer
Public Bottom As Integer
End Structure
<Runtime.InteropServices.DllImport("dwmapi.dll")>
Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarinset As Side) As Integer
End Function
Public Sub PerformGlassing()
Dim side As New Side
Dim result As Integer
Try
Me.BackColor = Color.Black
'You can try tweaking this below side vlaue's.For instance, changing everything
'to positive, ie. to 1, and giving the max value for your desired side makes a glass cum padding effect.
'Example :
'Side.Left = 1
'Side.Right = 1
'Side.Top = 1
'Side.Bottom = 50
Side.Left = -1
Side.Right = -1
Side.Top = -1
Side.Bottom = -1
result = DwmExtendFrameIntoClientArea(Me.Handle, side)
Catch ex As Exception
Me.BackColor = Color.Black
MessageBox.Show(ex.Message)
End Try
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.SystemDefault
MyBase.OnPaint(e)
End Sub]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment