Solved

c# how to put this code into a function...

Posted on 2011-03-16
4
570 Views
Last Modified: 2013-12-17
hi all, i want to put the below code into a function but dont know how to

the cmd will change everytime as will the state.EditValue

is what im after possible?

Thanks
ToggleFontBoldCommand cmd = new ToggleFontBoldCommand(CurrentEditor);
            ICommandUIState state = cmd.CreateDefaultCommandUIState();
            cmd.UpdateUIState(state);
            if (!state.Enabled && CurrentEditor.ReadOnly) state.Enabled = true;
            state.EditValue = FontStyle.Bold;
            cmd.ForceExecute(state);

Open in new window

0
Comment
Question by:awilderbeast
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Kusala Wijayasena
ID: 35150964
How about this:

public void ToggleFontBoldStyle(IRichEditControl currentEditor)
{
           ToggleFontBoldCommand cmd = new ToggleFontBoldCommand(currentEditor);
            ICommandUIState state = cmd.CreateDefaultCommandUIState();
            cmd.UpdateUIState(state);
            if (!state.Enabled && currentEditor.ReadOnly) state.Enabled = true;
            state.EditValue = FontStyle.Bold;
            cmd.ForceExecute(state);
}

Open in new window


-Kusala


0
 
LVL 1

Author Comment

by:awilderbeast
ID: 35154824
the toggle command will change each time i want to use it though

what im tryign to do is turn 8 lines of code into 1


so i do:-

(type i dont know) action = functioname(togglefontitaliccommand, fonstyle.italic);
action.forceexecute();

something like the above if you understand what im trying to to?
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35157789
What about this?

Calling code:
ToggleFontBoldCommand cmd = new ToggleFontBoldCommand(CurrentEditor);
ForceExecute(cmd, FontStyle.Bold);

Open in new window


Method: (it assumes that CurrentEditor is accessible in the method, otherwise it needs to be passed as a parameter)
public void ForceExecute(RichEditCommand cmd, object editValue)
{
            ICommandUIState state = cmd.CreateDefaultCommandUIState();
            cmd.UpdateUIState(state);
            if (!state.Enabled && CurrentEditor.ReadOnly) state.Enabled = true;
            state.EditValue = editValue;
            cmd.ForceExecute(state);
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:awilderbeast
ID: 35157817
brilliant, thankyou!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web page design problem 3 41
C# DateTime Help 6 46
How does this modal gets closed? 6 41
Intermittent OleDbConnection Error 20 53
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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