Solved

How to position a control on a form at run time

Posted on 2007-11-22
4
327 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 29

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now