Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Visual-Studio VB.NET
I'm creating an app that is kinda like Adding custom skins for Forms in VB.Net[^] but with way more features.
 
One thing I'm stuck on is Aerosnap. Is there a way in VB.NET to make Aerosnap work like in Photoshop or iTunes?
Posted 21-Jun-10 10:17am
Edited 22-Jun-10 6:44am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Imports System.Data
 
Imports System.Drawing
 
Imports System.Text
 
Imports System.Windows.Forms
 
Imports System.Runtime.InteropServices
 
Public Class Form1
 
' Import functions from dwmapi.dll - get this info from the sdk dwmapi.h
 
_
 
Public Shared Sub DwmExtendFrameIntoClientArea(ByVal hWnd As System.IntPtr, ByRef pMargins As Margins)
 
End Sub
 
_
 
Public Shared Sub DwmIsCompositionEnabled(ByRef IsIt As Boolean)
 
End Sub
 
' Create the brush that'll work around the Alpha transparency issue
 
Private DWMFrame As SolidBrush = New SolidBrush(Color.Black)
 
Dim BlurBehind As Boolean = False
 
Dim MaxTrans As Boolean = False
 
Dim blurect As Boolean = False
 
' Create an instance of the Margins struct for use in our form
 
Private inset As Margins = New Margins
 

 
' Define the Margins struct - get this from dwmapi.h
 
Public Structure Margins
 
Public Left As Integer
 
Public Right As Integer
 
Public Top As Integer
 
Public Bottom As Integer
 
End Structure
 
Public Sub New()
 
InitializeComponent()
 
' Set the Margins to their default values
 
inset.Top = 40
 
inset.Left = 0
 
inset.Right = 0
 
inset.Bottom = 0
 
' Check if DWM is enabled. This is a pretty stupid way to check, since it requires dwmapi.dll to be present anyway...
 
Dim isit As Boolean = False
 
DwmIsCompositionEnabled(isit)
 
If isit Then
 
' If DWM is enabled, call the function that gives us glass, passing a reference to our inset Margins
 
DwmExtendFrameIntoClientArea(Me.Handle, inset)
 
Else
 
' If DWM isn't enabled, shout it out
 
MessageBox.Show("DWM isn't enabled")
 
End If
 
End Sub
 
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
 
MyBase.OnPaint(e)
 
Me.PaintSquare(e, Me.DWMFrame)
 
End Sub
 
Private Sub PaintSquare(ByRef e As System.Windows.Forms.PaintEventArgs, ByVal b As SolidBrush)
 
e.Graphics.FillRectangle(b, 0, 0, Width, inset.Top)

e.Graphics.FillRectangle(b, 0, 0, inset.Left, Height)
 
' Note the numbers ( -14, -34) are just trial-and-error values, used to fix the glass... try omitting them, you'll get the idea.
 
e.Graphics.FillRectangle(b, Width - inset.Right - 14, 0, inset.Right, Height)
 
e.Graphics.FillRectangle(b, 0, Height - inset.Bottom - 34, Width, inset.Bottom)
 
End Sub
 
End Class
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,212
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 10 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100