/*
* 使用:工具箱,选择项,添加...直接拖动到界面即可
*
*/using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;namespace SetFormOpacity
{
public partial class TrackBar : UserControl
{
private int barValue = 0;
private int maxBarValue=150;
bool tracing = false; private Color darker1 = Color.Black;
private Color lighter1 = Color.FromArgb(221, 210, 227);
private Color darker2 = Color.Black;
private Color lighter2 = Color.FromArgb(238, 227, 242);
private Color dark = Color.FromArgb(0, 20, 255); Point lUpPoint;
Point mickeyMouse; Color trackerColor1;
Color trackerColor2; public int clientHeight;
private int clientWidth; public TrackBar()
{
InitializeComponent(); this.AutoScaleDimensions = new System.Drawing.SizeF(6, 13);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "TrackBar";
this.Size = new System.Drawing.Size(100, 38);
this.ResumeLayout(false);
trackerColor1 = darker1;
trackerColor2 = lighter1; clientHeight = this.ClientRectangle.Height;
clientWidth = this.ClientRectangle.Width; // maxBarValue = clientWidth - clientHeight / 2;
} public int BarValue
{
get
{
return barValue;
}
set
{
barValue = value;
}
} public int MaxBarValue
{
get
{
return maxBarValue;
}
set
{
maxBarValue = value;
}
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen blackPen = new Pen(Color.Black, 2);
Graphics g = e.Graphics;
// Rectangle outRect = new Rectangle(0, clientHeight / 4, clientWidth, clientHeight / 2);
// LinearGradientBrush brush = new LinearGradientBrush(outRect, darker1, lighter1,
// LinearGradientMode.Vertical);
// g.FillRectangle(brush, outRect);
// g.DrawRectangle(blackPen, outRect); Rectangle uInRect = new Rectangle(clientHeight / 8, 3 * clientHeight / 8, clientWidth - clientHeight / 4,
clientHeight / 8);
LinearGradientBrush brush2 = new LinearGradientBrush(uInRect, lighter1, darker1,
LinearGradientMode.Vertical);
g.FillRectangle(brush2, uInRect);
g.DrawRectangle(blackPen, uInRect); Rectangle dInRect = new Rectangle(clientHeight / 8, clientHeight / 2, clientWidth - clientHeight / 4,
clientHeight / 8);
LinearGradientBrush brush3 = new LinearGradientBrush(dInRect, darker1, lighter1,
LinearGradientMode.Vertical);
g.FillRectangle(brush3, dInRect);
g.DrawRectangle(blackPen, dInRect); //brush.Dispose();
brush2.Dispose();
brush3.Dispose();
blackPen.Dispose();
lUpPoint = new Point(clientHeight / 8 + barValue, clientHeight / 6);
// lUpPoint = new Point(10, 6);
DrawTracker(g, BarValue);
} private void DrawTracker(Graphics g, int nValue)
{
Rectangle rect = new Rectangle(clientHeight / 12 + nValue, 11,
clientHeight / 5, 2 * clientHeight / 5);
LinearGradientBrush brush = new LinearGradientBrush(rect, trackerColor1, trackerColor2,
LinearGradientMode.Vertical);
Pen blackPen = new Pen(Color.Black, 2);
g.FillRectangle(brush, rect);
g.DrawRectangle(blackPen, rect); brush.Dispose();
blackPen.Dispose();
}
private void TrackBar_MouseClick(object sender, MouseEventArgs e)
{
Cursor = Cursors.Default;
trackerColor1 = darker1;
trackerColor2 = lighter1;
tracing = false;
Invalidate();
}
private void TrackBar_MouseDown(object sender, MouseEventArgs e)
{
mickeyMouse = e.Location;
Rectangle rect = new Rectangle(lUpPoint.X, lUpPoint.Y, clientHeight / 4, 2 * clientHeight / 3);
if (rect.Contains(e.Location))
{
Cursor = Cursors.Hand;
trackerColor1 = darker2;
trackerColor2 = lighter2;
tracing = true;
Invalidate();
}
}
private void TrackBar_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && tracing)
{
Point mousePos = e.Location;
int temp = BarValue + (mousePos.X - mickeyMouse.X);
if (temp >= 0 && temp <= clientWidth - clientHeight / 2)
{
BarValue += (mousePos.X - mickeyMouse.X);
mickeyMouse.X = mousePos.X;
}
this.Invalidate();
}
}
private void TrackBar_MouseLeave(object sender, EventArgs e)
{
trackerColor1 = darker1;
trackerColor2 = lighter1;
Invalidate();
} private void TrackBar_SizeChanged(object sender, EventArgs e)
{
clientHeight = this.ClientRectangle.Height;
clientWidth = this.ClientRectangle.Width;
// maxBarValue = clientWidth - clientHeight / 2;
}
}
}我想用做电影的进度条。。但是TIMER控件控制不了。不能实现BARVALUE+1走动。。是不是少什么方法。。请大大帮忙看看。
* 使用:工具箱,选择项,添加...直接拖动到界面即可
*
*/using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;namespace SetFormOpacity
{
public partial class TrackBar : UserControl
{
private int barValue = 0;
private int maxBarValue=150;
bool tracing = false; private Color darker1 = Color.Black;
private Color lighter1 = Color.FromArgb(221, 210, 227);
private Color darker2 = Color.Black;
private Color lighter2 = Color.FromArgb(238, 227, 242);
private Color dark = Color.FromArgb(0, 20, 255); Point lUpPoint;
Point mickeyMouse; Color trackerColor1;
Color trackerColor2; public int clientHeight;
private int clientWidth; public TrackBar()
{
InitializeComponent(); this.AutoScaleDimensions = new System.Drawing.SizeF(6, 13);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "TrackBar";
this.Size = new System.Drawing.Size(100, 38);
this.ResumeLayout(false);
trackerColor1 = darker1;
trackerColor2 = lighter1; clientHeight = this.ClientRectangle.Height;
clientWidth = this.ClientRectangle.Width; // maxBarValue = clientWidth - clientHeight / 2;
} public int BarValue
{
get
{
return barValue;
}
set
{
barValue = value;
}
} public int MaxBarValue
{
get
{
return maxBarValue;
}
set
{
maxBarValue = value;
}
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen blackPen = new Pen(Color.Black, 2);
Graphics g = e.Graphics;
// Rectangle outRect = new Rectangle(0, clientHeight / 4, clientWidth, clientHeight / 2);
// LinearGradientBrush brush = new LinearGradientBrush(outRect, darker1, lighter1,
// LinearGradientMode.Vertical);
// g.FillRectangle(brush, outRect);
// g.DrawRectangle(blackPen, outRect); Rectangle uInRect = new Rectangle(clientHeight / 8, 3 * clientHeight / 8, clientWidth - clientHeight / 4,
clientHeight / 8);
LinearGradientBrush brush2 = new LinearGradientBrush(uInRect, lighter1, darker1,
LinearGradientMode.Vertical);
g.FillRectangle(brush2, uInRect);
g.DrawRectangle(blackPen, uInRect); Rectangle dInRect = new Rectangle(clientHeight / 8, clientHeight / 2, clientWidth - clientHeight / 4,
clientHeight / 8);
LinearGradientBrush brush3 = new LinearGradientBrush(dInRect, darker1, lighter1,
LinearGradientMode.Vertical);
g.FillRectangle(brush3, dInRect);
g.DrawRectangle(blackPen, dInRect); //brush.Dispose();
brush2.Dispose();
brush3.Dispose();
blackPen.Dispose();
lUpPoint = new Point(clientHeight / 8 + barValue, clientHeight / 6);
// lUpPoint = new Point(10, 6);
DrawTracker(g, BarValue);
} private void DrawTracker(Graphics g, int nValue)
{
Rectangle rect = new Rectangle(clientHeight / 12 + nValue, 11,
clientHeight / 5, 2 * clientHeight / 5);
LinearGradientBrush brush = new LinearGradientBrush(rect, trackerColor1, trackerColor2,
LinearGradientMode.Vertical);
Pen blackPen = new Pen(Color.Black, 2);
g.FillRectangle(brush, rect);
g.DrawRectangle(blackPen, rect); brush.Dispose();
blackPen.Dispose();
}
private void TrackBar_MouseClick(object sender, MouseEventArgs e)
{
Cursor = Cursors.Default;
trackerColor1 = darker1;
trackerColor2 = lighter1;
tracing = false;
Invalidate();
}
private void TrackBar_MouseDown(object sender, MouseEventArgs e)
{
mickeyMouse = e.Location;
Rectangle rect = new Rectangle(lUpPoint.X, lUpPoint.Y, clientHeight / 4, 2 * clientHeight / 3);
if (rect.Contains(e.Location))
{
Cursor = Cursors.Hand;
trackerColor1 = darker2;
trackerColor2 = lighter2;
tracing = true;
Invalidate();
}
}
private void TrackBar_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && tracing)
{
Point mousePos = e.Location;
int temp = BarValue + (mousePos.X - mickeyMouse.X);
if (temp >= 0 && temp <= clientWidth - clientHeight / 2)
{
BarValue += (mousePos.X - mickeyMouse.X);
mickeyMouse.X = mousePos.X;
}
this.Invalidate();
}
}
private void TrackBar_MouseLeave(object sender, EventArgs e)
{
trackerColor1 = darker1;
trackerColor2 = lighter1;
Invalidate();
} private void TrackBar_SizeChanged(object sender, EventArgs e)
{
clientHeight = this.ClientRectangle.Height;
clientWidth = this.ClientRectangle.Width;
// maxBarValue = clientWidth - clientHeight / 2;
}
}
}我想用做电影的进度条。。但是TIMER控件控制不了。不能实现BARVALUE+1走动。。是不是少什么方法。。请大大帮忙看看。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货