Solved

Changing the Style of an Edit Control in Run-time!

Posted on 2000-05-01
4
317 Views
Last Modified: 2013-11-20
The application is a MFC dialog based one. In run-time, I need to change the style of an edit control from ES_LEFT to ES_CENTER! What function should I use to do it?
Thank you!
Jim
0
Comment
Question by:nkhbeik
4 Comments
 
LVL 1

Expert Comment

by:RAVID
ID: 2768068
Hi,

To modify the syle from ES_LEFT to ES_CENTER use the function

m_edit.ModifyStyleEx(ES_LEFT,ES_CENTER,0);

Here m_edit is the member variable of the edit box whose style has to be changed.

Hope this helps u

Regards...
0
 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2768512
Use ModifyStyle instead of ModifyStyleEx
(which is for extended window styles)
m_edit.ModifyStyle(ES_LEFT,ES_CENTER,0)
0
 
LVL 5

Expert Comment

by:proskig
ID: 2768583
Frankly speaking, do not think that any of these approaches will work. There are some styles which you cannot change dynamically, you can only assign it upon creation. I think there was an message from Mike Blaszczak about it even at this site, saying that for alignment window checks this style on creation and fills up internal structures appropriately and you cannot change it during runtime. What you can do is to create two controls with central and left alignment and show/hide them when necessary, you also have to synchronize their content.
0
 

Accepted Solution

by:
bthomsen earned 20 total points
ID: 2781166
If you know which type of dialog you will need when creating the dialog, then you can create two separate versions of the dialog in the resource file, one with the edit control set to ES_LEFT, and the other with the edit control set to ES_CENTER.  For the constructor function in the dialog's support class, pass the CDialog constructor the resource ID of the appropriate dialog (instead of the enum IDD) for its first argument.

You could also use this technique after the dialog is up and running, but it would involve saving the state information for the dialog, closing that dialog, creating a new dialog using the different resource ID, and adjusting the position, edit controls values, and focus of this new dialog.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 62
Window placement 17 81
canBalance challenge 34 80
Excel file not created as expected 7 71
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

786 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