469,926 Members | 1,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

3 textboxes on the panel - resizing issue

I know this must be trivial for many of you. But I am playing with
this and can't figure it out.

I have a form, on that form is one panel which has 3 textboxes, when I
run my program and maximize the form I want to resize my 3 text boxes
according to the size of the form. Each text box should take 33% of
the panel's width and full hight of the panel's height. Resizing of
the panel is easy with docking... but these 3 textboxes are driving
me crazy.
Any ideas?
Please

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #1
13 2271
Martin,
I would dock one Textbox to the Top, dock one Textbox to the Bottom and set
the third to Fill.

In the Layout event for the Panel I would set the height of the top TextBox
to 1/3 height of the panel, I would set the bottom Textbox to 1/3 height of
the panel. The third TextBox will take care of itself. (Remember that most
numbers are not easily divisible by three, hence my setting the height of
only two text boxes and allowing the middle one to take up the slack...)

Remember to set the Multiline property for each TextBox to true!

Of course you can do the same thing with Left & Right if you want horizontal
instead of vertical. With horizontal you can leave Multiline to false.

Hope this helps
Jay

"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:3f********@127.0.0.1...
I know this must be trivial for many of you. But I am playing with
this and can't figure it out.

I have a form, on that form is one panel which has 3 textboxes, when I
run my program and maximize the form I want to resize my 3 text boxes
according to the size of the form. Each text box should take 33% of
the panel's width and full hight of the panel's height. Resizing of
the panel is easy with docking... but these 3 textboxes are driving
me crazy.
Any ideas?
Please

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #2
Hehehehe
I had a problem like this but I was using listview but the control type
doesn't matter. You're going to want to put your own code in to the panel
_Resize event to change the size and position of the textboxs the way you
want them. I tried all types of things in .Net so that I wouldn't have to
do that but in the end I had to..

"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:3f********@127.0.0.1...
I know this must be trivial for many of you. But I am playing with
this and can't figure it out.

I have a form, on that form is one panel which has 3 textboxes, when I
run my program and maximize the form I want to resize my 3 text boxes
according to the size of the form. Each text box should take 33% of
the panel's width and full hight of the panel's height. Resizing of
the panel is easy with docking... but these 3 textboxes are driving
me crazy.
Any ideas?
Please

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #3
Jay, I don't want them to dock to top bottom and fill...
I want them to look like a vertical columns, I don't want them to look
like a horizontal boxes.

Mike Bulava, could you please provide some little code on how to do
this?

I would really appreciate to see some example.
I have no idea why something so trivial is so ridiculously
complicated.
This should be easy to setup, the same way as when you designing
tables in html or so... This is just damn hard :)

Martin

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #4
I'm usally not one to give code answers because I don't want to be doing
someone elses work but here a little something. Becaufe I'm not testing
this, and I'm leaving a few things out.
Private Sub Panel_Resize(Args) handles Panel.resize
Dim iHieght as integer=Panel.height/3
Textbo1.top=0
Textbox1.hieght=ihieght
textbox2.top=ihieght
textbox2.hieght=ihieght
texbox3.top=textbox2.top+ihieght
textbox3.hieght=ihieght
end sub

You basicly mathamticly figuring out where each textbox should be in the
panel and then placing it there.

This is complicated at all it's called coding...

Have a nice day,
Mike
"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:3f********@127.0.0.1...
I know this must be trivial for many of you. But I am playing with
this and can't figure it out.

I have a form, on that form is one panel which has 3 textboxes, when I
run my program and maximize the form I want to resize my 3 text boxes
according to the size of the form. Each text box should take 33% of
the panel's width and full hight of the panel's height. Resizing of
the panel is easy with docking... but these 3 textboxes are driving
me crazy.
Any ideas?
Please

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #5
Mike,
Rather then using the Resize event, I would recommend the Layout event
instead.

As the Layout event occurs "when a control should reposition its child
controls", while a Resize event occurs "when the control is resized".

Which basically means that the Layout event can occur independent of the
form resizing. Also using Control.SuspendLayout & Control.ResumeLayout you
can control when the Layout event occurs (it is normally turned off when the
form is being constructed!)

Hope this helps
Jay

"Mike Bulava" <mb*****@comcast.net> wrote in message
news:OQ**************@TK2MSFTNGP10.phx.gbl...
I'm usally not one to give code answers because I don't want to be doing
someone elses work but here a little something. Becaufe I'm not testing
this, and I'm leaving a few things out.
Private Sub Panel_Resize(Args) handles Panel.resize
Dim iHieght as integer=Panel.height/3
Textbo1.top=0
Textbox1.hieght=ihieght
textbox2.top=ihieght
textbox2.hieght=ihieght
texbox3.top=textbox2.top+ihieght
textbox3.hieght=ihieght
end sub

You basicly mathamticly figuring out where each textbox should be in the
panel and then placing it there.

This is complicated at all it's called coding...

Have a nice day,
Mike
"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:3f********@127.0.0.1...
I know this must be trivial for many of you. But I am playing with
this and can't figure it out.

I have a form, on that form is one panel which has 3 textboxes, when I
run my program and maximize the form I want to resize my 3 text boxes
according to the size of the form. Each text box should take 33% of
the panel's width and full hight of the panel's height. Resizing of
the panel is easy with docking... but these 3 textboxes are driving
me crazy.
Any ideas?
Please

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000

Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via

Encryption =---

Nov 20 '05 #6
Martin,
Jay, I don't want them to dock to top bottom and fill...
I want them to look like a vertical columns, I don't want them to look
like a horizontal boxes. As I stated in my message if you want vertical columns (horizontal layout),
then dock on the left, right and change the Width.

If you want horizontal columns (vertical layout), then you need to dock on
the top & bottom and change the Height!
I have no idea why something so trivial is so ridiculously
complicated. It is extremely trivial! I really don't see where it is complicated ;-)

The following is a form that has both vertical & horizontal Text boxes!

---x--- cut here ---x---
Option Strict On
Option Explicit On

Public Class TestForm
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.
Private WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Private WithEvents Panel2 As System.Windows.Forms.Panel
Private WithEvents TextBox4 As System.Windows.Forms.TextBox
Private WithEvents TextBox5 As System.Windows.Forms.TextBox
Private WithEvents TextBox6 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Panel2 = New System.Windows.Forms.Panel
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.TextBox6 = New System.Windows.Forms.TextBox
Me.Panel1.SuspendLayout()
Me.Panel2.SuspendLayout()
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Me.Panel1.Controls.Add(Me.TextBox3)
Me.Panel1.Controls.Add(Me.TextBox2)
Me.Panel1.Controls.Add(Me.TextBox1)
Me.Panel1.Location = New System.Drawing.Point(8, 56)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(272, 192)
Me.Panel1.TabIndex = 0
'
'TextBox3
'
Me.TextBox3.Dock = System.Windows.Forms.DockStyle.Bottom
Me.TextBox3.Location = New System.Drawing.Point(0, 168)
Me.TextBox3.Multiline = True
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(272, 24)
Me.TextBox3.TabIndex = 2
Me.TextBox3.Text = "TextBox3"
'
'TextBox2
'
Me.TextBox2.Dock = System.Windows.Forms.DockStyle.Fill
Me.TextBox2.Location = New System.Drawing.Point(0, 24)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(272, 168)
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = "TextBox2"
'
'TextBox1
'
Me.TextBox1.Dock = System.Windows.Forms.DockStyle.Top
Me.TextBox1.Location = New System.Drawing.Point(0, 0)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(272, 24)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'Panel2
'
Me.Panel2.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Me.Panel2.Controls.Add(Me.TextBox6)
Me.Panel2.Controls.Add(Me.TextBox5)
Me.Panel2.Controls.Add(Me.TextBox4)
Me.Panel2.Location = New System.Drawing.Point(8, 8)
Me.Panel2.Name = "Panel2"
Me.Panel2.Size = New System.Drawing.Size(272, 32)
Me.Panel2.TabIndex = 1
'
'TextBox4
'
Me.TextBox4.Dock = System.Windows.Forms.DockStyle.Left
Me.TextBox4.Location = New System.Drawing.Point(0, 0)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(80, 22)
Me.TextBox4.TabIndex = 0
Me.TextBox4.Text = "TextBox4"
'
'TextBox5
'
Me.TextBox5.Dock = System.Windows.Forms.DockStyle.Fill
Me.TextBox5.Location = New System.Drawing.Point(80, 0)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(192, 22)
Me.TextBox5.TabIndex = 1
Me.TextBox5.Text = "TextBox5"
'
'TextBox6
'
Me.TextBox6.Dock = System.Windows.Forms.DockStyle.Right
Me.TextBox6.Location = New System.Drawing.Point(172, 0)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.TabIndex = 2
Me.TextBox6.Text = "TextBox6"
'
'TestForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(292, 260)
Me.Controls.Add(Me.Panel2)
Me.Controls.Add(Me.Panel1)
Me.Name = "TestForm"
Me.Text = "Test Form"
Me.Panel1.ResumeLayout(False)
Me.Panel2.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Panel1_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs) Handles Panel1.Layout
TextBox1.Height = Panel1.Height \ 3
TextBox3.Height = Panel1.Height \ 3
End Sub

Private Sub Panel2_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs) Handles Panel2.Layout
TextBox4.Width = Panel2.Width \ 3
TextBox6.Width = Panel2.Width \ 3
End Sub

End Class

---x--- cut here ---x---

Hope this helps
Jay

"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:3f**********@127.0.0.1... Jay, I don't want them to dock to top bottom and fill...
I want them to look like a vertical columns, I don't want them to look
like a horizontal boxes.

Mike Bulava, could you please provide some little code on how to do
this?

I would really appreciate to see some example.
I have no idea why something so trivial is so ridiculously
complicated.
This should be easy to setup, the same way as when you designing
tables in html or so... This is just damn hard :)

Martin

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #7
Martin,
Of course if you want to generalize the layout even more to support any
number of controls, you can use something like:

' single vertical column
Private Sub Panel1_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs) Handles Panel1.Layout
For Each control As Control In Panel1.Controls
control.Dock = DockStyle.Top
control.Height = Panel1.Height \ Panel1.Controls.Count
Next
End Sub

' single horizontal row
Private Sub Panel1_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs) Handles Panel1.Layout
For Each control As Control In Panel1.Controls
control.Dock = DockStyle.Left
control.Width = Panel1.Width \ Panel1.Controls.Count
Next
End Sub

Just place all the controls on a panel, then use the above code, in the
panel's layout event.

Note: The above routine will leave a slight gap after the last control... I
would consider making the very last control Fill to avoid this gap.

Hope this helps
Jay

"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:3f********@127.0.0.1...
I know this must be trivial for many of you. But I am playing with
this and can't figure it out.

I have a form, on that form is one panel which has 3 textboxes, when I
run my program and maximize the form I want to resize my 3 text boxes
according to the size of the form. Each text box should take 33% of
the panel's width and full hight of the panel's height. Resizing of
the panel is easy with docking... but these 3 textboxes are driving
me crazy.
Any ideas?
Please

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #8
Thanks a lot for all your help guy's.
Martin

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #9
My control is called GroupBox2, so I added this code suggested by Jay
B. Harlow, and it worked like a charm, thanks a lot Jay:

Private Sub GroupBox2_Layout(ByVal sender As
Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles
GroupBox2.Layout
For Each control As Control In GroupBox2.Controls
control.Dock = DockStyle.Top
control.Height = GroupBox2.Height \
GroupBox2.Controls.Count
Next
For Each control As Control In GroupBox2.Controls
control.Dock = DockStyle.Left
control.Width = GroupBox2.Width \
GroupBox2.Controls.Count
Next
End Sub
Backup form for this topic:
http://www.dotnetboards.com/viewtopic.php?t=7483

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #10
Martin,
You only need one of the two loops!

Remember I had samples for both horizontal & vertical layouts.

Glad you got it working.

Hope this helps
Jay

"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:3f**********@127.0.0.1...
My control is called GroupBox2, so I added this code suggested by Jay
B. Harlow, and it worked like a charm, thanks a lot Jay:

Private Sub GroupBox2_Layout(ByVal sender As
Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles
GroupBox2.Layout
For Each control As Control In GroupBox2.Controls
control.Dock = DockStyle.Top
control.Height = GroupBox2.Height \
GroupBox2.Controls.Count
Next
For Each control As Control In GroupBox2.Controls
control.Dock = DockStyle.Left
control.Width = GroupBox2.Width \
GroupBox2.Controls.Count
Next
End Sub
Backup form for this topic:
http://www.dotnetboards.com/viewtopic.php?t=7483

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #11
Jay :)
I am still drunk from the new years celebration... :)
Sorry, thanks for letting me know.
Martin

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #12
On 2004-01-02, Martin Ho <ma******@74tech-dot-com.no-spam.invalid> wrote:
Jay, I don't want them to dock to top bottom and fill...
I want them to look like a vertical columns, I don't want them to look
like a horizontal boxes.
A couple of notes to add to the code. First, if you want to use docking
but don't like the look, you can always embed your textboxes into
individual panels and dock the panels instead. Just set all four
anchors on the textboxes, dock the panels, and you essentially have
docking with a margin.

Most importantly, realize that while docking and anchoring have their
marginal uses, they aren't an equivalent to real layout managers. If
you're doing anything beyond simple layout, you're going to have to get
down and figure out positions and sizes in code, just like you did in
VB6.
This should be easy to setup, the same way as when you designing
tables in html or so... This is just damn hard :)


It really isn't hard. Once you stop fighting the anchoring/docking
thing and just accept that you have to do the code yourself, the actual
code you need is pretty trivial, as the examples others have posted
shows.

--
David
dfoster at
hotpop dot com
Nov 20 '05 #13
David,
It really isn't hard. Once you stop fighting the anchoring/docking
thing and just accept that you have to do the code yourself, the actual
code you need is pretty trivial, as the examples others have posted
shows. On the same token, you can do an awful lot with the standard
anchoring/docking!

Searching www.google.com identifies a number of articles on using
anchoring/docking to create some flexible yet easy layouts, and also how to
do customized layouts.

I like this article (among others) on how to define a custom layout manager:

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

My only real recommendation is if you code the layouts yourself, use the
Layout event instead of the Resize event!

Hope this helps
Jay

"David" <df*****@127.0.0.1> wrote in message
news:sl********************@woofix.local.dom... On 2004-01-02, Martin Ho <ma******@74tech-dot-com.no-spam.invalid> wrote:
Jay, I don't want them to dock to top bottom and fill...
I want them to look like a vertical columns, I don't want them to look
like a horizontal boxes.


A couple of notes to add to the code. First, if you want to use docking
but don't like the look, you can always embed your textboxes into
individual panels and dock the panels instead. Just set all four
anchors on the textboxes, dock the panels, and you essentially have
docking with a margin.

Most importantly, realize that while docking and anchoring have their
marginal uses, they aren't an equivalent to real layout managers. If
you're doing anything beyond simple layout, you're going to have to get
down and figure out positions and sizes in code, just like you did in
VB6.
This should be easy to setup, the same way as when you designing
tables in html or so... This is just damn hard :)


It really isn't hard. Once you stop fighting the anchoring/docking
thing and just accept that you have to do the code yourself, the actual
code you need is pretty trivial, as the examples others have posted
shows.

--
David
dfoster at
hotpop dot com

Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by the friendly display name | last post: by
2 posts views Thread by tjfdownsouth | last post: by
3 posts views Thread by Yuk Tang | last post: by
1 post views Thread by theresa | last post: by
4 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.