Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
Hi,
 
I have a application that contains several controls (static text, button, edit control) and I want to create them dynamically and reposition them according to add and remove of controls. Is there any tutorial or sample that gives me an idea how to add, remove and reposition of controls dynamically.
Posted 25-Mar-13 7:52am
SNI1.5K
Comments
joshrduncan2012 at 25-Mar-13 12:55pm
   
Have you checked with google?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Creating controls dynamically is typically not too difficult as the first link of solution 1 will show you. The repositioning in the face of dialog resizing is a little more challenging. There are a couple of good articles here on CodeProject that you can find under the keywords "dialog" "resize", for example this one:
 
Simple and more powerful resizable dialog[^]
 
If you are starting a new development, C# and WinForms make the dynamic layout of controls so much easier by the use of panels and anchoring.
 
If you want to stick with C++ and MFC, note that all the positions and sizes in dialog resources are measured in DLU (dialog units), while at runtime you need to calculate in pixels. So if you want to position a new control in relation to another existing control, created by the dialog template, I'd recommend to ask the other control's position at runtime via GetWindowRect and do my calculations from there.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100