VB.NET中的Aero Snap [英] Aero Snap in VB.NET

查看:74
本文介绍了VB.NET中的Aero Snap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个类似于在VB.Net中为表单添加自定义外观的应用程序 [ ^ ]但可以更多功能.

我坚持的一件事是Aerosnap.在VB.NET中有没有一种方法可以使Aerosnap像在Photoshop或iTunes中一样工作?

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?

推荐答案

导入System.Data

导入System.Drawing

导入System.Text

导入System.Windows.Forms

导入System.Runtime.InteropServices

公共课程表格1

''从dwmapi.dll导入函数-从sdk dwmapi.h获取此信息

_

公共共享的子DwmExtendFrameIntoClientArea(ByVal hWnd作为System.IntPtr,ByRef pMargins作为页边距)

结束子

_

Public Shared Sub DwmIsCompositionEnabled(ByRef IsIt as Boolean)

结束子

''创建可以解决Alpha透明度问题的画笔

专用DWMFrame作为SolidBrush =新的SolidBrush(颜色.黑色)

昏暗的BlurBehind为Boolean = False

Dim MaxTrans As Boolean = False

昏暗的模糊为Boolean = False

''创建Margins结构的实例以在我们的表单中使用

专用插图作为保证金=新保证金



''定义Margins结构-从dwmapi.h获取此

公共结构保证金

公共左为整数

作为整数的公共权利

公开整数形式

底部为整数的

端部结构

Public Sub New()

InitializeComponent()

''将边距设置为其默认值

inset.Top = 40

inset.Left = 0

inset.Right = 0

inset.Bottom = 0

''检查DWM是否已启用.这是一种非常愚蠢的检查方法,因为它仍然需要dwmapi.dll的存在...

Dim isit As Boolean = False

DwmIsCompositionEnabled(isit)

如果是那么

''如果启用了DWM,则调用给我们玻璃的函数,并传递一个对我们的插图边距的引用

DwmExtendFrameIntoClientArea(Me.Handle,inset)

其他

''如果未启用DWM,请大喊大叫

MessageBox.Show(未启用DWM")

如果结束

结束子

受保护的重写Sub OnPaint(ByVal e作为System.Windows.Forms.PaintEventArgs)

MyBase.OnPaint(e)

Me.PaintSquare(e,Me.DWMFrame)

结束子

专用子PaintSquare(由System.Windows.Forms.PaintEventArgs引用,由SolidBrush引用ByVal b)

e.Graphics.FillRectangle(b,0,0,Width,inset.Top)
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)

''请注意,数字(-14,-34)只是反复试验的数值,用于固定玻璃杯...尝试省略它们,您会明白的.

e.Graphics.FillRectangle(b,宽度-inset.Right-14,0,inset.Right,Height)

e.Graphics.FillRectangle(b,0,Height-inset.Bottom-34,Width,inset.Bottom)

结束子

结束类


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


这篇关于VB.NET中的Aero Snap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆