protected override void OnMouseUp(MouseEventArgs e) { int width = m_swatchOuterRegionWidth - (2 * OUTER_PADDING); int height = m_swatchOuterRegionHeight - (2 * OUTER_PADDING); int x = e.X - OUTER_PADDING; int y = e.Y - OUTER_PADDING; Rectangle r = new Rectangle(m_startX, m_startY, width, height); Rectangle c = new Rectangle(e.X, e.Y, 1, 1); if (c.IntersectsWith(r)) { int swatchColumnIndex = (x / (SWATCH_WIDTH + PADDING)); int swatchRowIndex = (y / (SWATCH_HEIGHT + PADDING)); ColorSwatch potentialSwatch = m_swatchArray[swatchColumnIndex, swatchRowIndex]; Rectangle potentialSwatchRectangle = new Rectangle(potentialSwatch.Location, potentialSwatch.Size); Point cursorPoint = new Point(e.X, e.Y); Rectangle cursorRectangle = new Rectangle(cursorPoint, new Size(1, 1)); if (cursorRectangle.IntersectsWith(potentialSwatchRectangle)) { if (ColorSwatchSelected != null) { ColorSwatchSelected(this, new ColorSelectedEventArgs(potentialSwatch.Color)); } } } }
public override bool Equals(object obj) { ColorSwatch swatch = ( ColorSwatch )obj; bool isEquals = false; if (this.Color == swatch.Color && this.Description.Equals(swatch.Description)) { isEquals = true; } return(isEquals); }
protected override void OnMouseMove(MouseEventArgs e) { int width = m_swatchOuterRegionWidth - (2 * OUTER_PADDING); int height = m_swatchOuterRegionHeight - (2 * OUTER_PADDING); int x = e.X - OUTER_PADDING; int y = e.Y - OUTER_PADDING; Rectangle r = new Rectangle(m_startX, m_startY, width, height); Rectangle c = new Rectangle(e.X, e.Y, 1, 1); if (c.IntersectsWith(r)) { int swatchColumnIndex = (x / (SWATCH_WIDTH + PADDING)); int swatchRowIndex = (y / (SWATCH_HEIGHT + PADDING)); ColorSwatch potentialSwatch = m_swatchArray[swatchColumnIndex, swatchRowIndex]; Rectangle potentialSwatchRectangle = new Rectangle(potentialSwatch.Location, potentialSwatch.Size); Point cursorPoint = new Point(e.X, e.Y); Rectangle cursorRectangle = new Rectangle(cursorPoint, new Size(1, 1)); if (cursorRectangle.IntersectsWith(potentialSwatchRectangle)) { // hides the tooltip when moving from swatch to swatch. if (!m_lastSwatch.Equals(potentialSwatch)) { this.colorTip.Active = false; } if (!potentialSwatch.Description.Equals(colorTip.GetToolTip(this))) { this.colorTip.SetToolTip(this, potentialSwatch.Description); } this.colorTip.Active = true; m_lastSwatch = potentialSwatch; this.Cursor = Cursors.Hand; } else { this.Cursor = Cursors.Default; this.colorTip.SetToolTip(this, ""); this.colorTip.Active = false; } } }
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 ); }
protected override void OnMouseMove( MouseEventArgs e ) { int width = m_swatchOuterRegionWidth - ( 2 * OUTER_PADDING ); int height = m_swatchOuterRegionHeight - ( 2 * OUTER_PADDING ); int x = e.X - OUTER_PADDING; int y = e.Y - OUTER_PADDING; Rectangle r = new Rectangle( m_startX, m_startY, width, height ); Rectangle c = new Rectangle( e.X, e.Y, 1, 1 ); if ( c.IntersectsWith( r ) ) { int swatchColumnIndex = ( x / ( SWATCH_WIDTH + PADDING ) ); int swatchRowIndex = ( y / ( SWATCH_HEIGHT + PADDING ) ); ColorSwatch potentialSwatch = m_swatchArray[ swatchColumnIndex, swatchRowIndex ]; Rectangle potentialSwatchRectangle = new Rectangle( potentialSwatch.Location, potentialSwatch.Size ); Point cursorPoint = new Point( e.X, e.Y ); Rectangle cursorRectangle = new Rectangle( cursorPoint, new Size( 1, 1 ) ); if ( cursorRectangle.IntersectsWith( potentialSwatchRectangle ) ) { // hides the tooltip when moving from swatch to swatch. if ( !m_lastSwatch.Equals( potentialSwatch ) ) { this.colorTip.Active = false; } if ( !potentialSwatch.Description.Equals( colorTip.GetToolTip( this ) ) ) { this.colorTip.SetToolTip( this, potentialSwatch.Description ); } this.colorTip.Active = true; m_lastSwatch = potentialSwatch; this.Cursor = Cursors.Hand; } else { this.Cursor = Cursors.Default; this.colorTip.SetToolTip( this, "" ); this.colorTip.Active = false; } } }