Overrides WndProc(ByRef m As System.Windows.Forms.Message) : WndProc « Windows System « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows System » WndProcScreenshots 
Overrides WndProc(ByRef m As System.Windows.Forms.Message)
Overrides WndProc(ByRef m As System.Windows.Forms.Message)

Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms


Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim myform As Form = New Form1()
        Application.Run(myform)

    End Sub

End Class



Public Class Form1
    Public Structure Rect
        Public left As Integer
        Public top As Integer
        Public right As Integer
        Public bottom As Integer
    End Structure

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_SIZING As Long = &H214
        Const WMSZ_LEFT As Integer = 1
        Const WMSZ_RIGHT As Integer = 2
        Const WMSZ_TOP As Integer = 3
        Const WMSZ_TOPLEFT As Integer = 4
        Const WMSZ_TOPRIGHT As Integer = 5
        Const WMSZ_BOTTOM As Integer = 6
        Const WMSZ_BOTTOMLEFT As Integer = 7
        Const WMSZ_BOTTOMRIGHT As Integer = 8
        Static fixed_aspect_ratio As Double = 0
        Dim new_aspect_ratio As Double
        If m.Msg = WM_SIZING And m.HWnd.Equals(Me.HandleThen
            Dim As Rect
            r = DirectCast_
            Marshal.PtrToStructure(m.LParam, GetType(Rect)), _
            Rect)

            Dim width As Double = r.right - r.left
            Dim height As Double = r.bottom - r.top

            new_aspect_ratio = height / width

            If fixed_aspect_ratio = Then
                fixed_aspect_ratio = new_aspect_ratio
            End If

            If fixed_aspect_ratio <> new_aspect_ratio Then

                If m.WParam.ToInt32 = WMSZ_TOPLEFT Or _
                m.WParam.ToInt32 = WMSZ_TOPRIGHT Or _
                m.WParam.ToInt32 = WMSZ_BOTTOMLEFT Or _
                m.WParam.ToInt32 = WMSZ_BOTTOMRIGHT _
                Then
                    If new_aspect_ratio > fixed_aspect_ratio Then
                        width = height / fixed_aspect_ratio
                    Else
                        height = width * fixed_aspect_ratio
                    End If
                ElseIf m.WParam.ToInt32 = WMSZ_LEFT Or _
                m.WParam.ToInt32 = WMSZ_RIGHT _
                Then
                    height = width * fixed_aspect_ratio
                ElseIf m.WParam.ToInt32 = WMSZ_TOP Or _
                m.WParam.ToInt32 = WMSZ_BOTTOM _
                Then
                    width = height / fixed_aspect_ratio
                End If

                If m.WParam.ToInt32 = WMSZ_TOP Or _
                m.WParam.ToInt32 = WMSZ_TOPLEFT Or _
                m.WParam.ToInt32 = WMSZ_TOPRIGHT _
                Then
                    r.top = r.bottom - CInt(height)
                Else
                    r.bottom = r.top + CInt(height)
                End If
                If m.WParam.ToInt32 = WMSZ_LEFT Or _
                m.WParam.ToInt32 = WMSZ_TOPLEFT Or _
                m.WParam.ToInt32 = WMSZ_BOTTOMLEFT _
                Then
                    r.left = r.right - CInt(width)
                Else
                    r.right = r.left + CInt(width)
                End If
                Marshal.StructureToPtr(r, m.LParam, True)
            End If
        End If
        MyBase.WndProc(m)
    End Sub
End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292273)
        Me.Name = "Form1"
        Me.Text = "FixedAspectRatio"
        Me.ResumeLayout(False)

    End Sub

End Class

           
       
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.