public override object EditValue( ITypeDescriptorContext context, IServiceProvider provider, object value ) { Palette original = (Palette) value; try { IWindowsFormsEditorService editorService = (IWindowsFormsEditorService) provider.GetService( typeof( IWindowsFormsEditorService ) ); _paletteForm = new PaletteForm(); if( value == null ) { value = new Palette(); } // Take a copy of the original Palette in case the user cancels // the PaletteForm Palette copy = new Palette(); foreach( Color c in original ) { copy.Add( c ); } _paletteForm.Value = original; _paletteForm.EditorService = editorService; DialogResult result = editorService.ShowDialog( _paletteForm ); if( result == DialogResult.OK ) { return _paletteForm.Value; } else { return copy; } } catch( Exception ex ) { ExceptionForm ef = new ExceptionForm( ex ); ef.ShowDialog(); return original; } }
public PaletteControl() { InitializeComponent(); try { NewPalette(); string[] standardPalettes = Directory.GetFiles( AppDomain.CurrentDomain.BaseDirectory + @"\ColourTables", "*.act" ); foreach( string file in standardPalettes ) { Palette p = Palette.FromFile( file ); Bitmap b = p.ToBitmap(); string name = Path.GetFileNameWithoutExtension( file ); ToolStripItem tsi = new ToolStripMenuItem( name, b ); tsi.Name = "palette" + name; tsi.Click += ToolStripMenuItemClick; openStandardToolStripMenuItem.DropDownItems.Add( tsi ); } } catch( Exception ex ) { // TESTME: exception thrown in constructor // Needs changes to CommonForms.ExceptionForm to detect when // being run as a unit test ExceptionForm ef = new ExceptionForm( ex ); ef.ShowDialog(); } }
private void listView1_KeyDown( object sender, KeyEventArgs e ) { try { switch( e.KeyValue ) { case 65://A AddColour(); break; case 46://Suppr (delete) DeleteColour(); break; default: break; } } catch( Exception ex ) { ExceptionForm ef = new ExceptionForm( ex ); ef.ShowDialog(); } }
private void listView1_DoubleClick(object sender, EventArgs e) { try { EditColour(); } catch( Exception ex ) { ExceptionForm ef = new ExceptionForm( ex ); ef.ShowDialog(); } }
private void ToolStripMenuItemClick( object sender, EventArgs e ) { ToolStripMenuItem item = (ToolStripMenuItem) sender; try { switch( item.Name ) { #region load / save / new case "openToolStripMenuItem": LoadPalette(); break; case "saveToolStripMenuItem": Save(); break; case "newToolStripMenuItem": NewPalette(); break; #endregion #region add / delete / edit colours case "addColourToolStripMenuItem": AddColour(); break; case "deleteColourToolStripMenuItem": DeleteColour(); break; case "editColourToolStripMenuItem": EditColour(); break; #endregion #region change ListView View property case "detailsToolStripMenuItem": listView1.View = View.Details; break; case "listToolStripMenuItem": listView1.View = View.List; break; case "tilesToolStripMenuItem": listView1.View = View.Tile; break; #endregion default: if( item.Name.StartsWith( "palette" ) ) { string fileName = item.Name.Remove( 0, 7 ) + ".act"; LoadPalette( @"ColourTables/" + fileName ); break; } string message = "Unexpected control: " + item.Name; throw new ArgumentException( message, "sender" ); } } catch( Exception ex ) { ExceptionForm ef = new ExceptionForm( ex ); ef.ShowDialog(); } }
private void contextMenuColor_Opening( object sender, CancelEventArgs e ) { try { if (listView1.SelectedItems.Count == 0) { editColourToolStripMenuItem.Enabled = false; deleteColourToolStripMenuItem.Enabled = false; } else { editColourToolStripMenuItem.Enabled = true; deleteColourToolStripMenuItem.Enabled = true; } } catch( Exception ex ) { ExceptionForm ef = new ExceptionForm( ex ); ef.ShowDialog(); } }