Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

17 Experts available now in Live!

Get 1:1 Help Now