Solved

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

Posted on 2000-05-01
4
305 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 57
ORA-01403: no data found 43 82
List out all word 7 220
Fibonacci challenge 11 82
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

743 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

12 Experts available now in Live!

Get 1:1 Help Now