Click here to Skip to main content
11,932,048 members (56,488 online)
Rate this:
Please Sign up or sign in to vote.
See more: MFC VisualC++

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
joshrduncan2012 25-Mar-13 12:55pm
Have you checked with google?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2015
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