?
Solved

How to position a control on a form at run time

Posted on 2007-11-22
4
Medium Priority
?
334 Views
Last Modified: 2010-04-21
I have a form that can be resized.
I need to position the grid control so that it remains at X,Y relative to the top left of the form.

Point NewPos  = new Point(20,50);
dataGridView1.Location = NewPos;

When I set a breakpoint dataGridView1.Location  show 0,0 and not 20,50

Just what do I need to do to position a control where I want it.
 
0
Comment
Question by:hansw77041
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Expert Comment

by:doraiswamy
ID: 20335936
If you set the breakpoint at dataGridView1.Location = NewPos;
then the statement has not executed as yet. So the location will still be the original vaue
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20335947
>>I have a form that can be resized.
>>I need to position the grid control so that it remains at X,Y relative to the top left of the form.

Does it moves when you resize the form?
Do you want the grid to be resized with form? If so, you just have to set the grid's Anchor property to left,top,right,bottom
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 2000 total points
ID: 20336018
Very convinient methoid is like:

dataGridView1.SetBounds(20, 30, 100, 60);

First parameter - X (distance from left)
Second - Y (distance from top)
and next two: width and height.

If your control has constant location and size - just put numbers like above.
If size changes you may need to do some calculations before produce numbers, e.g.,
gridwidth = formWidth / 2;

0
 

Author Closing Comment

by:hansw77041
ID: 31410597
That did it... thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question