Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to position a control on a form at run time

Posted on 2007-11-22
4
Medium Priority
?
336 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
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

824 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