110,536
社区成员
发帖
与我相关
我的任务
分享
class UMScrollBar:System.Windows.Forms.Control
{
private int Alpha = 125;
private System.ComponentModel.Container compents = new Container();
Color drawColor;
Pen borderPen;
SolidBrush fillBrush;
public UMScrollBar()
{
SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);
base.CreateControl();
this.BackColor = System.Drawing.Color.FromArgb(180, 180, 180);
this.Width = 6;
drawColor = Color.FromArgb(this.Alpha, this.BackColor);
borderPen = new Pen(drawColor, 0);
fillBrush = new SolidBrush(drawColor);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (compents != null)
compents.Dispose();
}
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawRectangle(borderPen, 0, 0, this.Size.Width, this.Size.Height);
e.Graphics.FillRectangle(fillBrush, 0, 0, this.Size.Width, this.Size.Height);
base.OnPaint(e);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //0x20; // 开启 WS_EX_TRANSPARENT,使控件支持透明
//cp.ExStyle |= 0x02000000;
return cp;
}
}
public void ReCalcHeight(int ContainerHeight,int ContentHeight)
{
float scale = (float)ContainerHeight / (float)ContentHeight;
this.Height = (int)(scale * ContainerHeight);
ReVisible(ContainerHeight, this.Visible);
}
public void ReCalcLocation(int ContentTop,int ContainerHeight,int ContentHeight)
{
float scale = (float)ContainerHeight / (float)ContentHeight;
this.Top = 0- (int)(ContentTop * scale);
}
public void ReVisible(int ContainerHeight,bool bVisible)
{
this.Visible = bVisible;
if (this.Height == ContainerHeight)
this.Visible = false;
}
}