private void AddColor(Color c) { bool writeSwatchesToFile = false; Point nextEmptySwatchPoint = m_nextEmptySwatchPoint; if (DoesColorAlreadyExist(c)) { MessageBox.Show(this.Parent, "Color already exists.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (m_numberOfEmptySwatches <= 0) { MessageBox.Show(this.Parent, "There are no empty swatches available.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (AddNewColorSwatchForm colorForm = new AddNewColorSwatchForm(c)) { colorForm.StartPosition = FormStartPosition.CenterParent; colorForm.ShowInTaskbar = false; if (colorForm.ShowDialog() == DialogResult.OK) { if (m_swatchBitmap != null) { int x = m_nextEmptySwatchPoint.X; int y = m_nextEmptySwatchPoint.Y; using (Graphics g = Graphics.FromImage(m_swatchBitmap)) { using (SolidBrush sb = new SolidBrush(c)) { g.FillRectangle(sb, x, y, 10, 10); } g.DrawRectangle(Pens.Black, x, y, 10, 10); } m_numberOfEmptySwatches--; ColorSwatch cs = new ColorSwatch( c, colorForm.ColorDescription, new Point(x, y), new Size(SWATCH_WIDTH, SWATCH_HEIGHT)); m_swatchArray[m_swatchColumnNum++, m_swatchRowNum] = cs; m_swatches.Add(cs); writeSwatchesToFile = true; UpdatePositions(ref x, ref y, ref m_swatchColumnNum, ref m_swatchRowNum); m_nextEmptySwatchPoint = new Point(x, y); } } } } if (writeSwatchesToFile) { ColorSwatchXml.WriteSwatches(m_customSwatchesFile, m_swatches); } m_paintActiveEmptySwatch = false; this.InvalidateEmptySwatch(nextEmptySwatchPoint); }
private void AddColor( Color c ) { bool writeSwatchesToFile = false; Point nextEmptySwatchPoint = m_nextEmptySwatchPoint; if ( DoesColorAlreadyExist( c ) ) { MessageBox.Show( this.Parent, "Color already exists.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error ); } else if ( m_numberOfEmptySwatches <= 0 ) { MessageBox.Show( this.Parent, "There are no empty swatches available.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error ); } else { using( AddNewColorSwatchForm colorForm = new AddNewColorSwatchForm( c ) ) { colorForm.StartPosition = FormStartPosition.CenterParent; colorForm.ShowInTaskbar = false; if ( colorForm.ShowDialog() == DialogResult.OK ) { if ( m_swatchBitmap != null ) { int x = m_nextEmptySwatchPoint.X; int y = m_nextEmptySwatchPoint.Y; using ( Graphics g = Graphics.FromImage( m_swatchBitmap ) ) { using ( SolidBrush sb = new SolidBrush( c ) ) { g.FillRectangle( sb, x, y, 10, 10 ); } g.DrawRectangle( Pens.Black, x, y, 10, 10 ); } m_numberOfEmptySwatches--; ColorSwatch cs = new ColorSwatch( c, colorForm.ColorDescription, new Point( x, y ), new Size( SWATCH_WIDTH, SWATCH_HEIGHT ) ); m_swatchArray[ m_swatchColumnNum++, m_swatchRowNum ] = cs; m_swatches.Add( cs ); writeSwatchesToFile = true; UpdatePositions( ref x, ref y, ref m_swatchColumnNum, ref m_swatchRowNum ); m_nextEmptySwatchPoint = new Point( x, y ); } } } } if ( writeSwatchesToFile ) { ColorSwatchXml.WriteSwatches( m_customSwatchesFile, m_swatches ); } m_paintActiveEmptySwatch = false; this.InvalidateEmptySwatch( nextEmptySwatchPoint ); }