lothos12345 Posted March 24, 2005 Posted March 24, 2005 Everytime I try to resize my textboxes based on my form, I recieve a negative occurance. I have 3 textboxes on my form, each of them directly beneath the other. I anchored the textboxes on all four sides." top, left, right, and bottom. When the form is resized the middle textbox disappears and the other 2 become huge and take up the form. I have tried several different variations of anchoring, but to no avail. Any suggestions would greatly be appreiciated. The code is in VB.NET. Quote
Leaders snarfblam Posted March 24, 2005 Leaders Posted March 24, 2005 No... That is not going to work. If you anchor to all four sides of the form, the textboxes will resize with the form, but their location (this is, .Location()) will stay the same. If the form becomes 50 pixels taller, so will the textboxes. They will expand and cover eachother (which one covers which depends on the order in which you added them to the form). If you want them to expand only horizontally, un-anchor them from the bottom. If you do not want them to expand at all, but want them only to be centered (horizontally), anchor only from the top. If you want to do something more complicated, for example, have each textbox take up one third of the form and have them all expand with the form without overlapping, you have to program them to do this on the Resize event (make use of the .BeginUpdate and .EndUpdate methods). Quote [sIGPIC]e[/sIGPIC]
lothos12345 Posted March 25, 2005 Author Posted March 25, 2005 I do want the textboxes to resize the way you stated in the later part of your reply. Thus I will have to use code to accomplish this task. Unforunately I am not quite sure how, can you please give me an example? Any help given is greatly appreciated. Quote
Leaders snarfblam Posted March 25, 2005 Leaders Posted March 25, 2005 Resizing textboxes This code assumes that your textboxes are called TextBox1, TextBox2, and TextBox3. Each textbox should be anchored to the top, left, and right, and not the bottom. Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MyBase.Resize Static ExtraHeight As Integer = Me.Height _ - TextBox1.Height - TextBox2.Height - TextBox3.Height '^ Difference between form's height and total textbox height. 'Since ExtraHeight is static it will only be calculated once, immediately 'after the form is loaded and shown (which raises the resize event) Dim HeightLeft As Integer = Me.Height - ExtraHeight 'HeightLeft is what the sum of the textboxes' height should be. ' SuspendLayout() TextBox1.Height = HeightLeft \\ 3 TextBox2.Height = TextBox1.Height TextBox3.Height = (HeightLeft - TextBox1.Height * 2) 'The reason that we don't just give textbox3 the same exact height is because 'we want it to take up the extra 1 or 2 pixels leftover as a result of roundoff error. TextBox2.Top = TextBox1.Bottom + 8 TextBox3.Top = TextBox2.Bottom + 8 ResumeLayout() End Sub Quote [sIGPIC]e[/sIGPIC]
lothos12345 Posted March 25, 2005 Author Posted March 25, 2005 Problem The textboxes are Richtextboxes. The attributes are a little different. Can you help? Quote
Leaders snarfblam Posted March 26, 2005 Leaders Posted March 26, 2005 Have you tried the code? All controls have a .Top, .Bottom, and .Height property, which are the only properties that this code uses. Just make the appropriate variable name changes and this will work not only on textboxes and richtextboxes but any sizable control. Buttons, Labels, Groupboxes, you name it. Quote [sIGPIC]e[/sIGPIC]
lothos12345 Posted March 27, 2005 Author Posted March 27, 2005 Kinda of working I tried the code and it does resize in every direction except bottom. For some reason it is not resizing to fill the bottom of the form. Any suggestions? And as always any help is greatly appreiciated. Quote
Leaders snarfblam Posted March 27, 2005 Leaders Posted March 27, 2005 What do you mean it is not resizing to fill the bottom? Are they not resizing vertically at all? Or only the one on the bottom? Quote [sIGPIC]e[/sIGPIC]
lothos12345 Posted March 27, 2005 Author Posted March 27, 2005 Sizing Problem None of the boxes are resizing vertically. They resize horizontially just fine but not vertically. And as always any help given is greatly appreciated. Just a reminder Option Strict in turned on as per the project requirements. Not sure if that fact as any bearing on the resizing problem. Quote
Wile Posted March 28, 2005 Posted March 28, 2005 Textboxes only size in height when you have multiline turned on as far as I know. You might want to check that. Quote Nothing is as illusive as 'the last bug'.
Leaders snarfblam Posted March 29, 2005 Leaders Posted March 29, 2005 Good point, however, lothos said he was using RichTextBoxes, which don't exhibit this behavior. Also, it might be worth noting that a non-multiline textbox can be resized provided that the .AutoSize property is set to false. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.