Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Go Back  Xtreme Visual Basic Talk > > > Problem with "Me.Location.X/Y"


Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2012, 10:51 AM
ferion ferion is offline
Newcomer
 
Join Date: Jun 2012
Posts: 14
Default Problem with "Me.Location.X/Y"


Hello, I'm making a program in vb.net with Visual Studio 2010. I have som trouble with the location of my form. What I want to do is when the form gets resized, my listbox should still fit in the form. The problem is that the forms width/height/X/Y never is correct.

The X and Y for example doesn't point at the top-left corner of the form, it seems to be quadratic to the distance between the point (0, 0) and the forms location. Also the width and height never gives me a value that I can use, because they are alway much bigger than the form.


Code example:

Based on my knowledge I find this code to be correct:
Code:
Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
      listbox1.Location = New Point(Me.Location.X + [CONSTANT]*, Me.Location.Y + [CONSTANT]*)
      listbox1.Size = New Size(Me.Width - [CONSTANT]*, Me.Height - [CONSTANT]*)
End sub
*The constant should be the distance between the forms border and my listbox.
But the listbox is neither in the right position or location.



Can someone please help me with this? I would be most grateful.

// Ferion
Reply With Quote
  #2  
Old 06-06-2012, 11:02 AM
PlausiblyDamp's Avatar
PlausiblyDampProblem with "Me.Location.X/Y" PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Me.Location is the position of the form on the Desktop, therefore you are adjusting the position of the listbox not relative to the form but rather relative to the forms location on the desktop.

Unless you have some complex sizing logic for the listbox it might be easier to select the listbox in the designer and then use the Anchor property to set how it handles the form being resized.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 06-07-2012, 09:52 PM
hDC_0Problem with "Me.Location.X/Y" hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default control resize on form resize

Hi ferion, welcome to the forum!

Resizing controls when the form resizes is actually not all that complicated.

Often the solution to moving/resizing controls at runtime is as simple as using the Anchor property,
but here is some VB.Net code for the Form1_SizeChanged event that will allow
each control to "grow or shrink at the same rate as the form".

However, please be mindful of the note beneath the code:
Quote:
It will NOT work with Labels, CheckBoxes or anything else with a fixed size.
Reply With Quote
  #4  
Old 06-08-2012, 08:26 AM
ferion ferion is offline
Newcomer
 
Join Date: Jun 2012
Posts: 14
Default

Thank you guys
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y" Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
 
Problem with "Me.Location.X/Y"
Problem with "Me.Location.X/Y"
 
-->