|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Resize only the height of FormI need to create a form that will resize only the verticle size of the Form
and not the width. So far I'm partial to the following code. Can someone please elaborate the ??? . . . . Const WM_SIZE = &H5 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Call MyBase.WndProc(m) Select Case m.Msg Case WM_SIZE ??? End Select End Sub One way would be the set the MinimumSize and MaximumSize properties of
the Form. Set the Width property on both to the same width and set the height properties to something suitable and that should work. "Rob" <rls_***@worldnet.att.net> schrieb: Instead of handling the form's 'Resize' event check out the form's > I need to create a form that will resize only the verticle size of the > Form > and not the width. 'MaximumSize' and 'MinimumSize' properties. If you set these properties' X or Y coordinate to equal values the form cannot be resized in this direction. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> <quote>
I need to create a form that will resize only the verticle size of the Form and not the width. So far I'm partial to the following code. Can someone please elaborate the ??? . . . . Const WM_SIZE = &H5 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Call MyBase.WndProc(m) Select Case m.Msg Case WM_SIZE ??? End Select End Sub </quote> Probably a safer way would be to bugger with something inside the Resize Event, but I couldn't figure out how to do it there. You need to know the meaning and value of the wParam and lParam items that get passed to the WindowProc of a window when the operating system sends the WM_SIZE message: 1. Launch the MSDN Library from your start menu. 2. In the URL combo box on MSDN's toolbar, paste this and press enter (will wrap): 3. While you're there, lookup bit shift operators, WM_SIZE message, WindowProc and the Message Structure. ms-help://MS.MSDNQTR.2003FEB.1033/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_size.htm I didn't get it quite right. I'm rusty on my bit-bashing, and didn't rebuild LParam correctly inside WndProc. But here's a sample Form to get you started. --------------------------------------------- Public Class VerticalResize Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If 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. Friend WithEvents btnHeight As System.Windows.Forms.Button Friend WithEvents lblHeight As System.Windows.Forms.Label Friend WithEvents lblWidth As System.Windows.Forms.Label <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.btnHeight = New System.Windows.Forms.Button Me.lblHeight = New System.Windows.Forms.Label Me.lblWidth = New System.Windows.Forms.Label Me.SuspendLayout() ' 'btnHeight ' Me.btnHeight.Location = New System.Drawing.Point(8, 8) Me.btnHeight.Name = "btnHeight" Me.btnHeight.Size = New System.Drawing.Size(80, 23) Me.btnHeight.TabIndex = 0 Me.btnHeight.Text = "Height += 50" ' 'lblHeight ' Me.lblHeight.Location = New System.Drawing.Point(96, 8) Me.lblHeight.Name = "lblHeight" Me.lblHeight.Size = New System.Drawing.Size(184, 23) Me.lblHeight.TabIndex = 1 ' 'lblWidth ' Me.lblWidth.Location = New System.Drawing.Point(96, 39) Me.lblWidth.Name = "lblWidth" Me.lblWidth.Size = New System.Drawing.Size(184, 23) Me.lblWidth.TabIndex = 2 ' 'VerticalResize ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 69) Me.Controls.Add(Me.lblWidth) Me.Controls.Add(Me.lblHeight) Me.Controls.Add(Me.btnHeight) Me.Name = "VerticalResize" Me.Text = "VerticalResize" Me.ResumeLayout(False) End Sub #End Region ' represents the window message flag for a resize Private Const WM_SIZE As Int32 = &H5 ' represents your constant width Private Const THE_WIDTH As Integer = 500 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) ' Don't call MyBase.WndProc(m) out here. ' You want to only call it selectively: Select Case m.Msg Case WM_SIZE ' When you get a WM_SIZE message, LParam ' contains a 32-bit integer, but it's represented ' to you by .NET as an IntPtr, so we have to call ' a method to get the Int32 out of it. Dim lParam As Int32 = m.LParam.ToInt32() ' Here's where it gets bizarre. When you get a WM_SIZE ' message, LParam has an Int32 in it, but it's really that ' the high 16 bits are the height, and the low 16 bits are ' the width. (I hate it when they do that) Dim high As Int16 'new height ' Doing a 16 right bitshift gets the high word. high = Convert.ToInt16(lParam >> 16) lblHeight.Text = high.ToString() ' Now here's where I'm too rusty. We need to reset ' LParam so that the high 16 bits are the same value ' that the message sent to us, but we need to change ' the low 16 bits to represent our constant width. ' you will have to play with this expression to get it right. m.LParam = New IntPtr(THE_WIDTH << 16 + high) ' Now that we've fiddled with the message so that LParam ' is what we want, we pass it back to let Windows handle ' it normally, but this time it has corrected values. MyBase.WndProc(m) Case Else ' Any other message just gets handled normally. MyBase.WndProc(m) End Select End Sub Private Sub btnHeight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHeight.Click Me.Height += 50 End Sub End Class -- Peace & happy computing, Mike Labosh, MCSD "Mr. McKittrick, after very careful consideration, I have come to the conclusion that this new system SUCKS." -- General Barringer, "War Games" Rob,
As the others suggest, I find the "easiest" way to do this is with the Form.MinimumSize & Form.MaximumSize properties. Windows forms already has handlers internal that watch the Resize, WM_SIZING, and other Win32 events to get this to work. The trick is to present the correct values for both MinimumSize & MaximumSize. For example if I want my Form to always be 600 units wide. I would set, in the Form.Load event, the constructor after InitializeComponent or even in the Form Designer: Me.MinimumSize = New Size(600, 0) Me.MaximumSize = New Size(600, Integer.MaxValue) Notice the Width is fixed at 600 for both minimum & maximum. While the height has a minimum of 0, and a maximum of the maximum of an integer. The designer will make you enter 2147483647. However! as long as you pick an arbitrarily large number that is significantly larger than any screen you can ever run on, you will be fine. ;-) The above was tested on VB.NET 2003. Hope this helps Jay "Rob" <rls_***@worldnet.att.net> wrote in message I need to create a form that will resize only the verticle size of the Formnews:%23WKhfDCfFHA.3584@TK2MSFTNGP09.phx.gbl... and not the width. So far I'm partial to the following code. Can someone please elaborate the ??? . . . . Const WM_SIZE = &H5 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Call MyBase.WndProc(m) Select Case m.Msg Case WM_SIZE ??? End Select End Sub > Me.MinimumSize = New Size(600, 0) Whooooooo That was frikken COOL!> Me.MaximumSize = New Size(600, Integer.MaxValue) But hacking around with the WndProc was so much more fun :-) -- Peace & happy computing, Mike Labosh, MCSD "Mr. McKittrick, after very careful consideration, I have come to the conclusion that this new system SUCKS." -- General Barringer, "War Games" Mike,
| Whooooooo That was frikken COOL! Yep hacking WndProc can be fun! :-)| But hacking around with the WndProc was so much more fun :-) Looking at the SDK, I suspect Form.MinimumSize & Form.MaximumSize control the WM_GETMINMAXINFO Win32 event. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_getminmaxinfo.asp Although it may need to tie into WM_WINDOWPOSCHANGING and/or instead of WM_GETMINMAXINFO. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_windowposchanging.asp Hope this helps Jay Show quoteHide quote "Mike Labosh" <mlab***@hotmail.com> wrote in message news:OTYLO9GfFHA.2472@TK2MSFTNGP15.phx.gbl... |> Me.MinimumSize = New Size(600, 0) | > Me.MaximumSize = New Size(600, Integer.MaxValue) | | Whooooooo That was frikken COOL! | | But hacking around with the WndProc was so much more fun :-) | -- | Peace & happy computing, | | Mike Labosh, MCSD | | "Mr. McKittrick, after very careful consideration, I have | come to the conclusion that this new system SUCKS." | -- General Barringer, "War Games" | | |
|||||||||||||||||||||||