Link to home
Start Free TrialLog in
Avatar of awilderbeast
awilderbeastFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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

Avatar of Kusala Wijayasena
Kusala Wijayasena
Flag of Sri Lanka image

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


Avatar of awilderbeast

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
brilliant, thankyou!