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

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
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
w_w___w__.__ja_v__a2_s_.__co__m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.