public virtual void DrawPanel(StatusBarDrawItemEventArgs drawEventArgs) { Graphics g = drawEventArgs.Graphics; switch (Alignment) //判断文本的对其方式. { case HorizontalAlignment.Left: sFormat.Alignment = StringAlignment.Near; break; case HorizontalAlignment.Center: sFormat.Alignment = StringAlignment.Center; break; case HorizontalAlignment.Right: sFormat.Alignment = StringAlignment.Far; break; } g.DrawString(Text, drawEventArgs.Font, SystemBrushes.ControlText, drawEventArgs.Bounds, sFormat); DrawBorder(drawEventArgs); }
//При перерисовке в StatusBar private void StatusBar_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { Graphics G = StatusBar.CreateGraphics(); //Объект для рисования прямоугольников в строке состояния //Подписи для обозначения выбранных цветов G.DrawString("Цвет 1:", new Font(this.Font, FontStyle.Regular), new SolidBrush(Color.Black), statusBarPanelCursor.Width + 5, 7); G.DrawString("Цвет 2:", new Font(this.Font, FontStyle.Regular), new SolidBrush(Color.Black), statusBarPanelCursor.Width + 5 + statusBarPanelColor1.Width, 7); int range = 50; //Перемення для расположения прямоугольников //Рисование индикаторов цвета G.FillRectangle(new SolidBrush(LineColor), Rectangle.FromLTRB(StatusBar.Panels[0].Width + range, 2, StatusBar.Panels[0].Width + range + 20, 22)); G.DrawRectangle(new Pen(Color.Black, 1), Rectangle.FromLTRB(StatusBar.Panels[0].Width + range, 2, StatusBar.Panels[0].Width + range + 20, 22)); G.FillRectangle(new SolidBrush(BackgroundColor), Rectangle.FromLTRB(StatusBar.Panels[0].Width + StatusBar.Panels[1].Width + range, 2, StatusBar.Panels[0].Width + StatusBar.Panels[1].Width + range + 20, 22)); G.DrawRectangle(new Pen(Color.Black, 1), Rectangle.FromLTRB(StatusBar.Panels[0].Width + StatusBar.Panels[1].Width + range, 2, StatusBar.Panels[0].Width + StatusBar.Panels[1].Width + range + 20, 22)); //вывод толщины линии statusBarPanelWidth.Text = LineWidth.ToString(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the DrawItem Event from the parent bar /// </summary> /// <param name="sender"></param> /// <param name="sbdevent"></param> /// ------------------------------------------------------------------------------------ private void HandleDrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { if (sbdevent.Panel != this) { return; } Rectangle rect = sbdevent.Bounds; if (Application.RenderWithVisualStyles) { rect.Width = rect.Width - SystemInformation.Border3DSize.Width; } if (m_text.Trim() != string.Empty) { sbdevent.Graphics.FillRectangle(m_backBrush, rect); } using (StringFormat sf = new StringFormat()) { sf.Alignment = StringAlignment.Center; Rectangle centered = rect; centered.Offset(0, (int)(rect.Height - sbdevent.Graphics.MeasureString(m_text, sbdevent.Font).Height) / 2); using (SolidBrush brush = new SolidBrush(sbdevent.ForeColor)) { sbdevent.Graphics.DrawString(m_text, sbdevent.Font, brush, centered, sf); } } }
private void sb_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { if (sbdevent.Panel == this) { StringFormat sf = new StringFormat(); if (this.Alignment == HorizontalAlignment.Left) { sf.Alignment = StringAlignment.Near; } else if (this.Alignment == HorizontalAlignment.Center) { sf.Alignment = StringAlignment.Center; } else if (this.Alignment == HorizontalAlignment.Right) { sf.Alignment = StringAlignment.Far; } sf.LineAlignment = StringAlignment.Center; Brush foreBrush; if (_foreColor != Color.Empty) { foreBrush = new SolidBrush(_foreColor); } else { foreBrush = new SolidBrush(sbdevent.ForeColor); } Brush backBrush; if (_backColor != Color.Empty) { backBrush = new SolidBrush(_backColor); } else { backBrush = new SolidBrush(sbdevent.BackColor); } Font fnt; if (_font != null) { fnt = _font; } else { fnt = sbdevent.Font; } sbdevent.Graphics.FillRectangle( backBrush, sbdevent.Bounds); sbdevent.Graphics.DrawString( this.Text, fnt, foreBrush, sbdevent.Bounds, sf); foreBrush.Dispose(); backBrush.Dispose(); } }
//绘制面板的边框. protected virtual void DrawBorder(StatusBarDrawItemEventArgs drawEventArgs) { drawEventArgs.Graphics.DrawRectangle(SystemPens.ControlDark, new Rectangle(drawEventArgs.Bounds.X, drawEventArgs.Bounds.Y, drawEventArgs.Bounds.Width - 1, drawEventArgs.Bounds.Height - 1)); }
private void statusBar1_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { Graphics g = statusBar1.CreateGraphics(); g.FillRectangle(new SolidBrush(primColorDialog.Color), 100, 2, sbdevent.Panel.Width, statusBar1.Height); g.FillRectangle(new SolidBrush(secondColorDialog.Color), 150, 2, sbdevent.Panel.Width, statusBar1.Height); g.Dispose(); }
// The status bar is being redrawn. private void progressBar_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { if (progressBarPanel >= 0) { progressBar.Location = new System.Drawing.Point((sbdevent.Bounds.X - 1), (sbdevent.Bounds.Y - 1)); progressBar.Size = new System.Drawing.Size((sbdevent.Bounds.Width + 2), (sbdevent.Bounds.Height + 2)); progressBar.Show(); } }
private void UpdateShieldState(StatusBarDrawItemEventArgs sbdevent) { Bitmap img = (Bitmap)((ImageHandler)fController.GetShieldImage()).Handle; if (img != null) { sbdevent.Graphics.DrawImage(img, sbdevent.Bounds.Left, sbdevent.Bounds.Top); } }
protected override void OnDrawItem(StatusBarDrawItemEventArgs sbdievent) { if (sbdievent.Panel is AxStatusBarPanel) { ((AxStatusBarPanel)sbdievent.Panel).DrawPanel(sbdievent); } else { base.OnDrawItem(sbdievent); } }
public void Ctor_Graphics_Font_Rectangle_Int_DrawItemState_StatusBarPanel_Color_Color(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state, StatusBarPanel panel, Color foreColor, Color backColor) { var e = new StatusBarDrawItemEventArgs(graphics, font, rect, index, state, panel, foreColor, backColor); Assert.Equal(graphics, e.Graphics); Assert.Equal(font, e.Font); Assert.Equal(rect, e.Bounds); Assert.Equal(index, e.Index); Assert.Equal(state, e.State); Assert.Equal(panel, e.Panel); Assert.Equal((state & DrawItemState.Selected) == DrawItemState.Selected ? SystemColors.HighlightText : foreColor, e.ForeColor); Assert.Equal((state & DrawItemState.Selected) == DrawItemState.Selected ? SystemColors.Highlight : backColor, e.BackColor); }
/// <summary> /// Draws the status bar /// </summary> /// <param name="sender">The control that caused it to draw again</param> /// <param name="sbdevent">The draw event</param> private void sb_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { //Find the appropriate panel if (sbdevent.Panel == this) { //Now use GDI to draw the progress bar int barWidth = (int)(value * (double)(sbdevent.Bounds.Width - 2) / (double)(maximum - minimum)); sbdevent.Graphics.FillRectangle(brush, sbdevent.Bounds.X + 1, sbdevent.Bounds.Y + 1, barWidth, sbdevent.Bounds.Height - 2); } }
public void ParentDrawItemHandler(object sender, StatusBarDrawItemEventArgs sbdevent) { // Only add this once to the parent's control container if (isAdded == false) { this.Parent.Controls.Add(this.progressBar); this.isAdded = true; } // Get the bounds of this panel and copy to the progress bar's bounds if (sbdevent.Panel == this) { progressBar.Bounds = sbdevent.Bounds; } }
public void StatusBarDrawItemEventArgs_Ctor_Graphics_Font_Rectangle_Int_DrawItemState_StatusBarPanel_Color_Color(Font font, Rectangle rect, int index, DrawItemState state, StatusBarPanel panel, Color foreColor, Color backColor, Color expectedForeColor, Color expectedBackColor) { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var e = new StatusBarDrawItemEventArgs(graphics, font, rect, index, state, panel, foreColor, backColor); Assert.Same(graphics, e.Graphics); Assert.Same(font, e.Font); Assert.Equal(rect, e.Bounds); Assert.Equal(index, e.Index); Assert.Equal(state, e.State); Assert.Same(panel, e.Panel); Assert.Equal(expectedForeColor, e.ForeColor); Assert.Equal(expectedBackColor, e.BackColor); } }
protected override void OnDrawItem(StatusBarDrawItemEventArgs e) { if (e.Panel.GetType().ToString().EndsWith("StatusBarPanelEx")) { StatusBarPanelEx ProgressPanel = (StatusBarPanelEx)e.Panel; //if this panel style!=ProgressBar? dont draw if (!(ProgressPanel.Style.ToString().EndsWith("ProgressBar"))) { return; } //draw if progress bar if (ProgressPanel.Value > ProgressPanel.Minimum) { int NewWidth = (int)(((double)ProgressPanel.Value / (double)ProgressPanel.Maximum) * (double)ProgressPanel.Width); Rectangle NewBounds = e.Bounds; //select brush type Brush PaintBrush; if (ProgressPanel.Style == StatusBarPanelStyleEx.SmoothProgressBar) { PaintBrush = new SolidBrush(ProgressPanel.ForeColor); } else { PaintBrush = new HatchBrush(ProgressPanel.HatchedProgressBarStyle, ProgressPanel.ForeColor, this.Parent.BackColor); } NewBounds.Width = NewWidth; e.Graphics.FillRegion(PaintBrush, new Region(NewBounds)); PaintBrush.Dispose(); } else { base.OnDrawItem(e); } } else { base.OnDrawItem(e); } }
/// <summary> /// /// </summary> /// <remarks>Getting things set up to actually draw in any custom status panel is surprisingly /// difficult. The first problem is, until some magical point, we cannot even figure out who are parent is. /// Apart from that, we cannot even find out what our boundary rectangle is. we can find out /// the boundary rectangle only when our parent tells us to draw. /// kept the nature of this progress bar is that it actually wants to draw on its own agenda, not on the parent's. /// Thus, it is up to some other code to somehow get this event to fire so that we can figure out our boundary. /// </remarks> /// <param name="sender"></param> /// <param name="sbdevent"></param> public void OnDrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { CheckDisposed(); if (sbdevent.Panel == this) { m_bounds = sbdevent.Bounds; // if we are using visual styles, the progress bar will sometimes overlap the border, so we reduce // the size of the progress bar a little if (Application.RenderWithVisualStyles) { m_bounds.Width = m_bounds.Width - SystemInformation.Border3DSize.Width; } // System.Diagnostics.Debug.WriteLine(""); // System.Diagnostics.Debug.WriteLine("SetBounds"); } }
/// <summary> /// /// </summary> /// <remarks>Getting things set up to actually draw in any custom status panel is surprisingly /// difficult. The first problem is, until some magical point, we cannot even figure out who are parent is. /// Apart from that, we cannot even find out what our boundary rectangle is. we can find out /// the boundary rectangle only when our parent tells us to draw. /// kept the nature of this progress bar is that it actually wants to draw on its own agenda, not on the parent's. /// Thus, it is up to some other code to somehow get this event to fire so that we can figure out our boundary. /// </remarks> /// <param name="sender"></param> /// <param name="sbdevent"></param> public void OnDrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { // It has proved difficult to dispose of all the panels of a status bar without something // at the system level trying to draw one that has already been disposed. The simplest // solution is just to ignore attempts to draw disposed ones. if (IsDisposed) { return; } if (sbdevent.Panel == this) { m_bounds = sbdevent.Bounds; // if we are using visual styles, the progress bar will sometimes overlap the border, so we reduce // the size of the progress bar a little if (Application.RenderWithVisualStyles) { m_bounds.Width = m_bounds.Width - SystemInformation.Border3DSize.Width; } // System.Diagnostics.Debug.WriteLine(""); // System.Diagnostics.Debug.WriteLine("SetBounds"); } }
// Draw the panel. private void DrawCustomStatusBarPanel(object sender, StatusBarDrawItemEventArgs e) { // Draw a blue background in the owner-drawn panel. e.Graphics.FillRectangle(Brushes.AliceBlue, e.Bounds); // Create a StringFormat object to align text in the panel. StringFormat textFormat = new StringFormat(); // Center the text in the middle of the line. textFormat.LineAlignment = StringAlignment.Center; // Align the text to the left. textFormat.Alignment = StringAlignment.Far; // Draw the panel's text in dark blue using the Panel // and Bounds properties of the StatusBarEventArgs object // and the StringFormat object. e.Graphics.DrawString(e.Panel.Text, StatusBar1.Font, Brushes.DarkBlue, new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), textFormat); }
protected override void OnDrawItem(StatusBarDrawItemEventArgs e) { if (e.Panel is EAPStatusBarProgressPanel) { Rectangle rect = new Rectangle(0, 0, e.Bounds.Width - 4, e.Bounds.Height - 3); EAPStatusBarProgressPanel panel = (EAPStatusBarProgressPanel)e.Panel; float fPercent = (float)panel.Value * (float)100.0 / ((float)(panel.MaxValue - panel.MinValue)); Bitmap bmp = new Bitmap(e.Bounds.Width, e.Bounds.Height); Graphics g = Graphics.FromImage(bmp); string strPercent = panel.Prefix + string.Format("{0:" + panel.DisplayFormat + "}" + panel.Suffix, fPercent); float xOffSet = ((float)panel.Value * (float)rect.Width) / (float)(panel.MaxValue - panel.MinValue); RectangleF rcFill = new RectangleF(rect.X, rect.Y, xOffSet, rect.Height); RectangleF rcEmpty = new RectangleF(xOffSet, rect.Y, rect.Width - xOffSet, rect.Height); g.FillRectangle(new SolidBrush(panel.CompletedColor), rcFill); g.FillRectangle(new SolidBrush(panel.EmptyColor), rcEmpty); g.DrawLines(new Pen(panel.BorderColor), new Point[] { new Point(rect.Left, rect.Top), new Point(rect.Right, rect.Top), new Point(rect.Right, rect.Bottom), new Point(rect.Left, rect.Bottom), new Point(rect.Left, rect.Top) }); g.DrawString(strPercent, this.Font, new SolidBrush(panel.ForeColor), rect, GetStringFormat(panel.TextAlign)); e.Graphics.DrawImage(bmp, e.Bounds.Left + 1, e.Bounds.Top + 1); bmp.Dispose(); g.Dispose(); } else { base.OnDrawItem(e); } }
private void OnDrawItem(object sender, StatusBarDrawItemEventArgs e) { if (e.Panel == iconPanel) { e.Graphics.DrawImage(GetIconImage(currentLevel), e.Bounds.Left + 2, e.Bounds.Top, 16, 16); } else if (e.Panel == progressPanel && progressPanel.Width > 1) { e.Graphics.DrawRectangle(panelBorderPen, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1); e.Graphics.FillRectangle(progressBrush, e.Bounds.Left + 3, e.Bounds.Top + 3, GetProgressWidth(e.Bounds.Width) - 6, e.Bounds.Height - 6); } else if (e.Panel == locationPanel && locationPanel.Text.Length > 0) { e.Graphics.DrawRectangle(panelBorderPen, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1); e.Graphics.DrawString(locationPanel.Text, Font, panelFontBrush, e.Bounds.Left + 2, e.Bounds.Top + 2); } else if (e.Panel == sizePanel && sizePanel.Text.Length > 0) { e.Graphics.DrawRectangle(panelBorderPen, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1); e.Graphics.DrawString(sizePanel.Text, Font, panelFontBrush, e.Bounds.Left + 2, e.Bounds.Top + 2); } }
/// <summary> /// Owner-Draw Event /// </summary> /// <param name="sender"></param> /// <param name="sbdevent"></param> private void Parent_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { if (sbdevent.Panel == this) { sbdevent.DrawBackground(); if (_currentPosition != _startPoint) { if ((_currentPosition <= _endPoint) || (this.AnimationStyle == ProgressDisplayStyle.Infinite)) { Rectangle bounds = sbdevent.Bounds; float percent = ((float)_currentPosition / ((float)_endPoint - (float)_startPoint)); switch (this.AnimationStyle) { case ProgressDisplayStyle.LeftToRight: { bounds.Width = (int)(percent * (float)sbdevent.Bounds.Width); break; } case ProgressDisplayStyle.RightToLeft: { bounds.Width = (int)(percent * (float)sbdevent.Bounds.Width); bounds.X += sbdevent.Bounds.Width - bounds.Width; break; } case ProgressDisplayStyle.BottomToTop: { bounds.Height = (int)(percent * (float)sbdevent.Bounds.Height); bounds.Y += sbdevent.Bounds.Height - bounds.Height; break; } case ProgressDisplayStyle.TopToBottom: { bounds.Height = (int)(percent * (float)sbdevent.Bounds.Height); break; } case ProgressDisplayStyle.Infinite: { bounds.Height = (int)(percent * (float)sbdevent.Bounds.Height); bounds.Y += (sbdevent.Bounds.Height - bounds.Height) / 2; bounds.Width = (int)(percent * (float)sbdevent.Bounds.Width); bounds.X += (sbdevent.Bounds.Width - bounds.Width) / 2; break; } } // draw the progress bar sbdevent.Graphics.FillRectangle(_progressBrush, bounds); if (this.ShowText) { // draw the text on top of the progress bar sbdevent.Graphics.DrawString((percent * 100).ToString(), _textFont, _textBrush, sbdevent.Bounds); } } } } }
protected void barStatus_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// statusbardrawitemeventhandler.BeginInvoke(sender, sbdevent, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this StatusBarDrawItemEventHandler statusbardrawitemeventhandler, Object sender, StatusBarDrawItemEventArgs sbdevent, AsyncCallback callback) { if (statusbardrawitemeventhandler == null) { throw new ArgumentNullException("statusbardrawitemeventhandler"); } return(statusbardrawitemeventhandler.BeginInvoke(sender, sbdevent, callback, null)); }
protected override void OnDrawItem(StatusBarDrawItemEventArgs sbdevent) { try { base.OnDrawItem(sbdevent); // Create a StringFormat object to align text in the panel. StringFormat sf = new StringFormat(); // Format the String of the StatusBarPanel to be centered. sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; StatusBarPanel panel = (StatusBarPanel)sbdevent.Panel; if (panel.Alignment == HorizontalAlignment.Center) { sf.Alignment = StringAlignment.Center; } else if (panel.Alignment == HorizontalAlignment.Left) { sf.Alignment = StringAlignment.Near; } else { sf.Alignment = StringAlignment.Far; } if (panel == _CenterImagePanel) { Rectangle rect = sbdevent.Bounds; Graphics g = sbdevent.Graphics; lock (this) { g.FillRectangle(this.backBrush, sbdevent.Bounds.X - 2, sbdevent.Bounds.Y, sbdevent.Bounds.Width + 2, sbdevent.Bounds.Height); //g.DrawRectangle(SystemPens.ControlDark,rect); g.DrawString("F L E X C O L L A B", this.textFont, textBrush, sbdevent.Bounds, sf); } } else if (panel == _RightMessagePanel) { Rectangle rect = sbdevent.Bounds; Graphics g = sbdevent.Graphics; lock (this) { g.FillRectangle(this.backBrush, sbdevent.Bounds.X - 2, sbdevent.Bounds.Y, sbdevent.Bounds.Width + 2, sbdevent.Bounds.Height); g.DrawString(_RightMessagePanel.Text, this.textFont, textBrush, sbdevent.Bounds, sf); } comboMood.Left = sbdevent.Bounds.Left + 100; Brush _pen; int cor = 100; if (_RightMessagePanel.Text.Trim() == "Connected") { _pen = new SolidBrush(Color.Green); //WebMeeting.Client.ClientUI.getInstance().NetworkStatus(false); } else { _pen = new SolidBrush(Color.Red); //WebMeeting.Client.ClientUI.getInstance().NetworkStatus(true); cor = 120; } lock (this) { g.FillEllipse(_pen, this.Right - cor, 3, 14, 14); g.DrawString("", this.textFont, textBrush, comboMood.Left - 5, comboMood.Top + 10, sf); } } else if (panel == _RightImagePanel) { Rectangle rect = sbdevent.Bounds; Graphics g = sbdevent.Graphics; //g.FillRectangle(this.backBrush,sbdevent.Bounds.X -2,sbdevent.Bounds.Y,sbdevent.Bounds.Width+2,sbdevent.Bounds.Height); //g.DrawRectangle(SystemPens.ControlDark,rect); //System.Drawing.Pen _pen=new Pen(Color.Red); //g.DrawEllipse(_pen,0,0,10,10); } else { //synchButton.Left = sbdevent.Bounds.Right - (synchButton.Width); Rectangle rect = sbdevent.Bounds; Graphics g = sbdevent.Graphics; lock (this) { g.DrawString(panel.Text, this.textFont, this.textBrush, sbdevent.Bounds, sf); } } } catch (Exception ex) { Trace.WriteLine("Exception at the place of status bar ondraw:" + ex.ToString()); ex = ex; } }
private void Entry_manager_FE_Being_Processed(object sender, StatusBarDrawItemEventArgs sbdevent) { throw new NotImplementedException(); }
private void ProgressStatus_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { progressBar.Location = new Point(sbdevent.Bounds.X, sbdevent.Bounds.Y); progressBar.Size = new Size(sbdevent.Bounds.Width, sbdevent.Bounds.Height); progressBar.Show(); }
private void StatusBar_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent) { UpdateShieldState(sbdevent); }