dotnetmonitor.com

 
Index
Previous
Next

 

Settings are another feature handled in ToolStripManager. This uses the settings engine to automatically persist and restore the entire ToolStrip tree. This allows you to enable drag to dock scenarios in the ToolStripPanel and AllowItemReorder without having to manage restoring or saving that state. Add the following code to a form with ToolStrips on it and experiment. Make sure youve named your ToolStrips, they are in ToolStripPanels so they can be moved, and AllowItemReorder is set to true to enable ALT+drag item shuffling.

 

private void Form1_Load(object sender, EventArgs e)

{

// load and apply settings last saved

ToolStripManager.LoadSettings(this);

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

// Save out current state of ToolStrips

ToolStripManager.SaveSettings(this);

}

 

Q: Ok, so how about providing a way to reset the settings?

A: The sample code below will do that it simply uses a named set of settings that captures the state before any custom settings are applied. Then, with button click or whatever you can apply the custom set.

 

private void Form1_Load(object sender, EventArgs e)

{

// save out a snapshop of init component

ToolStripManager.SaveSettings(this, "RESET");

 

// load and apply settings last saved

ToolStripManager.LoadSettings(this);

}

 

private void newToolStripMenuItem_Click(object sender, EventArgs e)

{

// apply the RESET settings

ToolStripManager.LoadSettings(this, "RESET");

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

// Save out current state of ToolStrips

ToolStripManager.SaveSettings(this);

}

Painting
When should I use Paint/OnPaint and when should I override the ToolStripRenderer?
Do I need to worry about double buffering?
Parenting
Partial Trust
Usage