#endregion // ToolTip
#region TrackBar
- private void DrawTrackBar_Vertical (Graphics dc, Rectangle area, TrackBar tb,
+ private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
float ticks, int value_pos, bool mouse_value) {
float pixel_len;
float pixels_betweenticks;
const int space_from_right = 8;
- const int space_from_left = 8;
+ const int space_from_left = 8;
+ Rectangle area = tb.ClientRectangle;
switch (tb.TickStyle) {
case TickStyle.BottomRight:
}
pixel_len = thumb_area.Height - 11;
- pixels_betweenticks = pixel_len / ticks;
+ pixels_betweenticks = pixel_len / ticks;
+
+ thumb_area.X = thumb_pos.X;
+ thumb_area.Y = channel_startpoint.Y;
+ thumb_area.Width = thumb_pos.Height;
/* Draw ticks*/
- if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
- ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
-
- for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
- if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
- area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
- else
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
- area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
+ Region outside = new Region (area);
+ outside.Exclude (thumb_area);
+
+ if (outside.IsVisible (clip_rectangle)) {
+ if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
+ ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
+
+ for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
+ if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
+ area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
+ else
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
+ area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
+ }
+ }
+
+ if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
+ ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
+
+ pixel_len = thumb_area.Height - 11;
+ pixels_betweenticks = pixel_len / ticks;
+
+ for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
+ if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
+ area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
+ else
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
+ area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
+ }
}
}
-
- if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
- ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
-
- pixel_len = thumb_area.Height - 11;
- pixels_betweenticks = pixel_len / ticks;
-
- for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
- if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
- area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
- else
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
- area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
- }
- }
+
}
/*
- Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
*/
- private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb,
+ private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
float ticks, int value_pos, bool mouse_value) {
Point toptick_startpoint = new Point ();
float pixel_len;
float pixels_betweenticks;
const int space_from_right = 8;
- const int space_from_left = 8;
+ const int space_from_left = 8;
+ Rectangle area = tb.ClientRectangle;
switch (tb.TickStyle) {
case TickStyle.BottomRight:
pixels_betweenticks = pixel_len / ticks;
/* Draw ticks*/
- if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
- ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
-
- for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
- if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
- area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
- else
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
- area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
+ thumb_area.Y = thumb_pos.Y;
+ thumb_area.X = channel_startpoint.X;
+ thumb_area.Height = thumb_pos.Height;
+ Region outside = new Region (area);
+ outside.Exclude (thumb_area);
+
+ if (outside.IsVisible (clip_rectangle)) {
+ if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
+ ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
+
+ for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
+ if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
+ area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
+ else
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
+ area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
+ }
}
- }
-
- if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
- ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
-
- for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
- if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
- area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
- else
- dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
- area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
- }
- }
+
+ if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
+ ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
+
+ for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
+ if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
+ area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
+ else
+ dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
+ area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
+ }
+ }
+ }
}
public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
Rectangle area;
Rectangle thumb_pos = tb.ThumbPos;
Rectangle thumb_area = tb.ThumbArea;
-
+
if (tb.thumb_pressed) {
value_pos = tb.thumb_mouseclick;
mouse_value = true;
mouse_value = false;
}
- area = tb.paint_area;
+ area = tb.ClientRectangle;
if (tb.thumb_pressed == true) {
br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
/* Control Background */
if (tb.BackColor == DefaultControlBackColor) {
- dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area);
+ dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), clip_rectangle);
} else {
- dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), area);
+ dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
}
}
if (tb.Orientation == Orientation.Vertical) {
- DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area,
+ DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
br_thumb, ticks, value_pos, mouse_value);
} else {
- DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area,
+ DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
br_thumb, ticks, value_pos, mouse_value);
}
private int smallChange;
private int largeChange;
private Orientation orientation;
- private TickStyle tickStyle;
- internal Rectangle paint_area = new Rectangle ();
+ private TickStyle tickStyle;
private Rectangle thumb_pos = new Rectangle (); /* Current position and size of the thumb */
private Rectangle thumb_area = new Rectangle (); /* Area where the thumb can scroll */
internal bool thumb_pressed = false;
tickStyle = TickStyle.BottomRight;
smallChange = 1;
largeChange = 5;
- mouse_clickmove = false;
- SizeChanged += new System.EventHandler (OnResizeTB);
+ mouse_clickmove = false;
MouseDown += new MouseEventHandler (OnMouseDownTB);
MouseUp += new MouseEventHandler (OnMouseUpTB);
MouseMove += new MouseEventHandler (OnMouseMoveTB);
if (value < 0)
throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
- largeChange = value;
- Refresh ();
+ largeChange = value;
}
}
throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
if (smallChange != value) {
- smallChange = value;
- Refresh ();
+ smallChange = value;
}
}
}
if (ValueChanged != null)
ValueChanged (this, new EventArgs ());
- Refresh ();
+ Invalidate (thumb_area);
}
}
}
protected override bool IsInputKey (Keys keyData)
{
- return false;
+ return base.IsInputKey (keyData);
}
protected override void OnBackColorChanged (EventArgs e)
{
-
+ base.OnBackColorChanged (e);
}
protected override void OnHandleCreated (EventArgs e)
- {
+ {
+ base.OnHandleCreated (e);
+
if (AutoSize)
if (Orientation == Orientation.Horizontal)
Size = new Size (Width, 40);
else
Size = new Size (50, Height);
-
- UpdateArea ();
+
UpdatePos (Value, true);
}
public void SetRange (int minValue, int maxValue)
{
Minimum = minValue;
- Maximum = maxValue;
-
- Refresh ();
+ Maximum = maxValue;
}
public override string ToString()
#endregion Public Methods
#region Private Methods
-
- private void UpdateArea ()
- {
- paint_area.X = paint_area.Y = 0;
- paint_area.Width = Width;
- paint_area.Height = Height;
- }
-
+
private void UpdatePos (int newPos, bool update_trumbpos)
{
if (newPos < minimum){
private void LargeIncrement ()
{
UpdatePos (position + LargeChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
private void LargeDecrement ()
{
UpdatePos (position - LargeChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
private void SmallIncrement ()
{
UpdatePos (position + SmallChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
private void SmallDecrement ()
{
UpdatePos (position - SmallChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
- private void Draw ()
+ private void Draw (Rectangle clip)
{
- ThemeEngine.Current.DrawTrackBar(DeviceContext, this.ClientRectangle, this);
+ ThemeEngine.Current.DrawTrackBar (DeviceContext, clip, this);
}
private void OnMouseUpTB (object sender, MouseEventArgs e)
thumb_pressed = false;
holdclick_timer.Enabled = false;
this.Capture = false;
- Refresh ();
+ Invalidate (thumb_area);
}
}
this.Capture = true;
thumb_pressed = true;
thumb_mouseclick = e.X;
- Refresh ();
+ Invalidate (thumb_area);
}
else {
- if (paint_area.Contains (point)) {
+ if (ClientRectangle.Contains (point)) {
if (e.X > thumb_pos.X + thumb_pos.Width)
LargeIncrement ();
else
LargeDecrement ();
- Refresh ();
+ Invalidate (thumb_area);
fire_timer = true;
mouse_clickmove = true;
}
this.Capture = true;
thumb_pressed = true;
thumb_mouseclick = e.Y;
- Refresh ();
+ Invalidate (thumb_area);
}
else {
- if (paint_area.Contains (point)) {
+ if (ClientRectangle.Contains (point)) {
if (e.Y > thumb_pos.Y + thumb_pos.Height)
LargeIncrement ();
else
LargeDecrement ();
- Refresh ();
+ Invalidate (thumb_area);
fire_timer = true;
mouse_clickmove = true;
}
if (thumb_pressed) {
if (orientation == Orientation.Horizontal){
- if (paint_area.Contains (e.X, thumb_pos.Y))
+ if (ClientRectangle.Contains (e.X, thumb_pos.Y))
thumb_mouseclick = e.X;
}
else {
- if (paint_area.Contains (thumb_pos.X, e.Y))
+ if (ClientRectangle.Contains (thumb_pos.X, e.Y))
thumb_mouseclick = e.Y;
}
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
}
- private void OnResizeTB (object sender, System.EventArgs e)
- {
- if (Width <= 0 || Height <= 0)
- return;
-
- UpdateArea ();
- }
-
+
private void OnPaintTB (PaintEventArgs pevent)
{
if (Paint != null) {
if (Width <= 0 || Height <= 0 || Visible == false)
return;
- /* Copies memory drawing buffer to screen*/
- UpdateArea ();
- Draw ();
- pevent.Graphics.DrawImage (ImageBuffer, 0, 0);
+ /* Copies memory drawing buffer to screen */
+ Draw (pevent.ClipRectangle);
+ pevent.Graphics.DrawImage (ImageBuffer, pevent.ClipRectangle, pevent.ClipRectangle, GraphicsUnit.Pixel);
}
private void OnKeyDownTB (KeyEventArgs e) \r
{
switch (e.KeyCode) { \r
- case Keys.Up:
+
+ case Keys.Down:
case Keys.Right:
SmallIncrement ();
break;
-
- case Keys.Down:
+
+ case Keys.Up:
case Keys.Left:
SmallDecrement ();
break;
+
+ case Keys.PageUp:
+ LargeDecrement ();
+ break;
+
+ case Keys.PageDown:
+ LargeIncrement ();
+ break;
+
+ case Keys.Home:
+ Value = Minimum;
+ break;
+
+ case Keys.End:
+ Value = Maximum;
+ break;
default:
break;
LargeDecrement ();
}
- Refresh ();
+ Invalidate (thumb_area);
\r
} \r
}