Label Cloud

Friday, August 17, 2007

Tweaking RuleSetDialog to Resize

I've started working with Windows Workflow Rulesets to apply dynamically apply business rules to some internal processes. This involves using External RuleSet Toolset from Microsoft samples (some more on that in a later post)

One of the biggest peeves about the RuleSetDialog is its inability to resize. Viewing a complex rule in a three line window is very uncomfortable. It is, however, pretty easy to tweak the dialog and make it a lot more user friendly.

External RuleSet editor comes in source code. Open the code using Visual Studio, open the code for the RuleSetEditor form and find the editButton_Click event. What you'll may notice is that the RuleSetDialog class used derives from Dialog. Add a new function that will adjust the dialog to make it resizable.

private void TweakRuleSetDialogToResizable(RuleSetDialog ruleSetDialog) { ruleSetDialog.FormBorderStyle = FormBorderStyle.Sizable; ruleSetDialog.HelpButton = false; ruleSetDialog.MaximizeBox = true; ruleSetDialog.Controls["okCancelTableLayoutPanel"].Anchor = AnchorStyles.Right | AnchorStyles.Bottom; ruleSetDialog.Controls["rulesGroupBox"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; ruleSetDialog.Controls["ruleGroupBox"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom; ruleSetDialog.Controls["ruleGroupBox"].Controls["thenTextBox"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom; ruleSetDialog.Controls["ruleGroupBox"].Controls["elseLabel"].Anchor = AnchorStyles.Left | AnchorStyles.Bottom; ruleSetDialog.Controls["ruleGroupBox"].Controls["elseTextBox"].Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom; ruleSetDialog.Controls["ruleGroupBox"].Controls["conditionTextBox"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; ruleSetDialog.Controls["rulesGroupBox"].Controls["panel1"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; ruleSetDialog.Controls["rulesGroupBox"].Controls["panel1"].Controls["chainingBehaviourComboBox"].Anchor = AnchorStyles.Top | AnchorStyles.Right; ruleSetDialog.Controls["rulesGroupBox"].Controls["panel1"].Controls["chainingLabel"].Anchor = AnchorStyles.Top | AnchorStyles.Right; }

Then call the function passing the RuleSetDialog before it is display from the editButton_Click event.

RuleSetDialog ruleSetDialog = new RuleSetDialog(selectedRuleSetData.Activity, null, selectedRuleSetData.RuleSet); //Tweak the RuleSetDialog TweakRuleSetDialogToResizable(ruleSetDialog); DialogResult result = ruleSetDialog.ShowDialog();


Share/Save/Bookmark

3 comments:

Anonymous said...

Great stuff - Thanks very much. I really hate the RuleSetDialog.

Chris said...

At last! Hurray!

Many thanks for your solution. I've extended it to perform some dynamic layout so that the if/then/else text boxes remain the same size:


private void MakeRuleSetDialogResizable(RuleSetDialog ruleSetDialog)
{
ruleSetDialog.FormBorderStyle = FormBorderStyle.Sizable;
ruleSetDialog.HelpButton = false;
ruleSetDialog.MaximizeBox = true;
ruleSetDialog.Controls["okCancelTableLayoutPanel"].Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
ruleSetDialog.Controls["rulesGroupBox"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
ruleSetDialog.Controls["ruleGroupBox"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;

ruleSetDialog.Controls["ruleGroupBox"].Layout += new LayoutEventHandler(this.RulesGroupBox_Layout);

ruleSetDialog.Controls["rulesGroupBox"].Controls["panel1"].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
ruleSetDialog.Controls["rulesGroupBox"].Controls["panel1"].Controls["chainingBehaviourComboBox"].Anchor = AnchorStyles.Top | AnchorStyles.Right;
ruleSetDialog.Controls["rulesGroupBox"].Controls["panel1"].Controls["chainingLabel"].Anchor = AnchorStyles.Top | AnchorStyles.Right;
}

private void RulesGroupBox_Layout(object sender, LayoutEventArgs e)
{
int topOffset = 80;
int padding = 20;
int leftMargin = 10;
int labelHeight = 17;

int textBoxHeight = (e.AffectedControl.Size.Height - topOffset) / 3;
int textBoxWidth = e.AffectedControl.Size.Width - 20;

Control conditionTextBox = e.AffectedControl.Controls["conditionTextBox"];
if (conditionTextBox != null)
{
conditionTextBox.SetBounds(leftMargin, topOffset, textBoxWidth, textBoxHeight - padding);
}

Control conditionLabel = e.AffectedControl.Controls["conditionLabel"];
if (conditionLabel != null)
{
conditionLabel.SetBounds(leftMargin, topOffset - labelHeight, textBoxWidth, labelHeight);
}

Control thenTextBox = e.AffectedControl.Controls["thenTextBox"];
if (thenTextBox != null)
{
thenTextBox.SetBounds(leftMargin, textBoxHeight + topOffset, textBoxWidth, textBoxHeight - padding);
}

Control thenLabel = e.AffectedControl.Controls["thenLabel"];
if (thenLabel != null)
{
thenLabel.SetBounds(leftMargin, textBoxHeight + topOffset - labelHeight, textBoxWidth, labelHeight);
}

Control elseTextBox = e.AffectedControl.Controls["elseTextBox"];
if (elseTextBox != null)
{
elseTextBox.SetBounds(leftMargin, (textBoxHeight * 2) + topOffset, textBoxWidth, textBoxHeight - padding);
}

Control elseLabel = e.AffectedControl.Controls["elseLabel"];
if (elseLabel != null)
{
elseLabel.SetBounds(leftMargin, (textBoxHeight * 2) + topOffset - labelHeight, textBoxWidth, labelHeight);
}
}

Chris said...

For a complete solution that provides proportional resizing of all controls within the dialog, please visit
Workflow Foundation - Resizing the RuleSetDialog

Regards, Chris.

Directory of Computers/Tech Blogs