473,324 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Resize only the height of Form

Rob
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
Nov 21 '05 #1
6 5160
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.

Nov 21 '05 #2
"Rob" <rl*****@worldnet.att.net> schrieb:
I need to create a form that will resize only the verticle size of the
Form
and not the width.


Instead of handling the form's 'Resize' event check out the form's
'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/>

Nov 21 '05 #3
<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"
Nov 21 '05 #4
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" <rl*****@worldnet.att.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
Nov 21 '05 #5
> 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"
Nov 21 '05 #6
Mike,
| Whooooooo That was frikken COOL!
| But hacking around with the WndProc was so much more fun :-)
Yep hacking WndProc can be fun! :-)
Looking at the SDK, I suspect Form.MinimumSize & Form.MaximumSize control
the WM_GETMINMAXINFO Win32 event.

http://msdn.microsoft.com/library/de...minmaxinfo.asp

Although it may need to tie into WM_WINDOWPOSCHANGING and/or instead of
WM_GETMINMAXINFO.

http://msdn.microsoft.com/library/de...oschanging.asp
Hope this helps
Jay
"Mike Labosh" <ml*****@hotmail.com> wrote in message
news:OT**************@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"
|
|
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Poul C | last post by:
Hello With the code below I can resize all the components on a Form when ever the Form resizes. For the time beeing it dosn't allow a component to contain another component, but with a...
0
by: Rod Billett | last post by:
The included html contains 3 divs. One primary Div, with 2 nested divs. the second nested DIV contains an empty table. Problem 1: Phantom Space. When viewed within the browser, the div 'action...
2
by: Peter Proost | last post by:
Hi group I have the following piece of code that should resize the bitmap in a picture box but it doesn't work as I tought it would. Can someone help me with it? thnx Peter Public Class...
2
by: DraguVaso | last post by:
Hi, I have to DataGrid's on a form, one on the top of my form, the other at the bottom, but they though each other somewhere in the middle. What I want now is that, when I resize the form, they...
2
by: Carl Gilbert | last post by:
Hi I am looking for either a component or technique to allow me to do the following: * Provide a panel with a background image * Resize the image to best fit the panel to maintain aspect...
7
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir =...
1
by: Bob Alston | last post by:
I have a system where many subforms are used. Often the size of the subform had to be larger than could be displayed without scrolling. I set the height of the subform to the typical height...
3
by: Noorain | last post by:
Sir i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me <form action="<?php echo $_server; ?>" method="post"...
10
by: =?Utf-8?B?UmljaA==?= | last post by:
A lot of users at my workplace use different screen resolutions, and I build apps to use 1680 x 1050 pixels res by default. But some users are using 800 x 600, and the apps are too large for their...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.