Solved

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

Posted on 2000-05-01
4
326 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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