/// <summary> /// Raises event 'ChangeValue' /// </summary> protected virtual void OnChangeValue() { if (ChangeValue != null) { ChangeValue.Invoke(this, System.EventArgs.Empty); } }
protected override void OnPaint(PaintEventArgs e) { Rectangle rect = ClientRectangle; Graphics g = e.Graphics; Brush brush = new SolidBrush(Color.Red); ProgressBarRenderer.DrawHorizontalBar(g, rect); rect.Inflate(-4, -4); if (Value > 0) { // As we doing this ourselves we need to draw the chunks on the progress bar Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height); g.FillRectangle(brush, clip); ProgressBarRenderer.DrawHorizontalChunks(g, clip); } // Set the Display text (Either a % amount or our custom text string text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText; using (Font f = new Font(FontFamily.GenericSerif, 8)) { SizeF len = g.MeasureString(text, f); // Calculate the location of the text (the middle of progress bar) // Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2))); Point location = new Point(Convert.ToInt32(((Width / 2) - len.Width / 2) + 5), Convert.ToInt32((Height / 2) - len.Height / 2)); // The commented-out code will centre the text into the highlighted area only. This will centre the text regardless of the highlighted area. // Draw the custom text g.DrawString(text, f, Brushes.Black, location); } ChangeValue?.Invoke(this, e); }
public void AddResourcesValue(int _resourcesShift) { resourcesCount += _resourcesShift; changeValue.Invoke(); }