Solved

How to position a control on a form at run time

Posted on 2007-11-22
4
332 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 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Name Space error VS2015 1 48
Visual Studio hangs on running project 6 84
ASP.NET MVC -Update model when click on <li> element 29 103
Adjust the codes 3 63
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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