public void UpdateRuler() { TimeCode startTimeCode = (TimeCode)m_TimeStart.TimeOfDay; TimeCode endTimeCode = (TimeCode)m_TimeRecord.TimeOfDay; if (endTimeCode < startTimeCode) { endTimeCode += TimeCode.tcDay; } Graphics gp = this.CreateGraphics(); int widthTotal = (int)((endTimeCode - startTimeCode).ToLong() * m_RulerUnit / m_RulerSpacing.ToLong()) + (int)Math.Ceiling(gp.MeasureString("00:00:00", m_RulerFont).Width); if (widthTotal <= this.Width) { hScroll.Visible = false; hScroll.Value = 0; pnClip.Height = this.Height - pnRuler.Height; pnRecord.Height = pnPreview.Height = pnPlay.Height = pnClip.Height + 10; } else { pnClip.Height = this.Height - pnRuler.Height - hScroll.Height; pnRecord.Height = pnPreview.Height = pnPlay.Height = pnClip.Height + 10; hScroll.Visible = true; } if (widthTotal < this.Width) { widthTotal = this.Width; endTimeCode.FromFrame(widthTotal * m_RulerSpacing.ToLong() / m_RulerUnit); endTimeCode += startTimeCode; } if (hScroll.Visible) { TimeCode tcAdd = new TimeCode(); tcAdd.FromFrame((int)((hScroll.Value * widthTotal / hScroll.Maximum) * m_RulerSpacing.ToLong() / m_RulerUnit)); startTimeCode += tcAdd; m_TimeRulerBegin = m_TimeStart.AddMilliseconds(tcAdd.ToLong() * 40); } else { m_TimeRulerBegin = m_TimeStart; } m_TimeRulerEnd = m_TimeRulerBegin.AddMilliseconds(this.Width * m_RulerSpacing.ToLong() * 40 / m_RulerUnit); Bitmap bmp = new Bitmap(pnRuler.Width, pnRuler.Height); gp = Graphics.FromImage(bmp); gp.Clear(pnRuler.BackColor); if (m_TimeMarkIn <= m_TimeMarkOut) { if (((m_TimeRulerBegin <= m_TimeMarkIn && m_TimeMarkIn <= m_TimeRulerEnd) || ((m_TimeRulerBegin <= m_TimeMarkOut && m_TimeMarkOut <= m_TimeRulerEnd))) || (m_TimeMarkIn <= m_TimeRulerBegin && m_TimeRulerEnd <= m_TimeMarkOut)) { int xB = 0, xE = 0; if (m_TimeMarkIn <= m_TimeRulerBegin) { xB = 0; } else { xB = (int)(((TimeCode)(m_TimeMarkIn - m_TimeRulerBegin)).ToLong() * m_RulerUnit / m_RulerSpacing.ToLong()); } if (m_TimeRulerEnd <= m_TimeRulerBegin) { xE = 0; } else { xE = (int)(((TimeCode)(m_TimeMarkOut - m_TimeRulerBegin)).ToLong() * m_RulerUnit / m_RulerSpacing.ToLong()); } gp.FillRectangle(Brushes.Yellow, xB, 0, xE - xB, pnRuler.Height); } } else { if (m_TimeRulerBegin <= m_TimeMarkIn && m_TimeMarkIn <= m_TimeRulerEnd) { int xB = 0; if (m_TimeMarkIn <= m_TimeRulerBegin) { xB = 0; } else { xB = (int)(((TimeCode)(m_TimeMarkIn - m_TimeRulerBegin)).ToLong() * m_RulerUnit / m_RulerSpacing.ToLong()); } gp.FillRectangle(Brushes.Yellow, xB, 0, 1, pnRuler.Height); } } int maxWidth = this.Width - (int)Math.Ceiling(gp.MeasureString("00:00:00", m_RulerFont).Width); TimeCode tcCur = startTimeCode.Celling(); while (tcCur.ToLong() % m_RulerSpacing.ToLong() != 0) { tcCur += TimeCode.tcSec; } Pen pen = new Pen(Brushes.Black); // Vẽ dòng kẻ dưới gp.DrawLine(pen, 0, bmp.Height - 1, bmp.Width, bmp.Height - 1); // Vẽ vạch nhỏ trước vạch đầu tiên tcCur -= m_RulerSpacing; for (int i = (int)((tcCur.ToLong() - startTimeCode.ToLong()) * m_RulerUnit / m_RulerSpacing.ToLong()); i <= this.Width; i += m_RulerUnit) { // Vẽ vạch int xB = i, yB = pnRuler.Height; gp.DrawLine(pen, xB, yB, xB, yB - 10); // Vẽ time code if (tcCur.hour > 23) { tcCur.hour -= 24; } string tc = tcCur.ToHDString(); tc = tc.Substring(0, m_LengthRulerText); gp.DrawString(tc, m_RulerFont, Brushes.Black, xB - 7, yB - 12 - gp.MeasureString(tc, m_RulerFont).Height); tcCur += m_RulerSpacing; // Vẽ vạch nhỏ for (int j = 1; j < 10; j++) { int xN = i + j * m_RulerUnit / 10, yN = pnRuler.Height; gp.DrawLine(pen, xN, yN, xN, yN - 5); } } gp.Dispose(); pnRuler.BackgroundImage = bmp; }