如何控制 TEXTBOX 控件的背景颜色显示长度..
如一个数值为70%
控件背景颜色 70%黑色 30%白色值为50%
控件背景颜色 50%黑色 50%白色
尝试过 两个TEXTBOX 叠落在一起.改变上层控件的宽度来控制.. 但是LABEL 控件透明属性太难设置了..

解决方案 »

  1.   

    .TextBoxCss
    {
    border-right: #7b9ebd 1px solid;
    border-top: #7b9ebd 1px solid;
    border-left: #7b9ebd 1px solid;
    border-bottom: #7b9ebd 1px solid;
    onblur:expression(onblur=function(){this.style.borderColor='#7b9ebd';this.style.backgroundColor=''});
    onfocus:expression(onfocus=function(){this.style.borderColor='#993366';this.style.backgroundColor='#ffffcc';});

    }引用这个CS,,自己改颜色
      

  2.   

    C#组件设计技术兼谈带百分比进度条组件TSmartProgressBar的实现
      

  3.   

    .... 越说越难了...
    我刚开始是 两个textbox 一个是现实字符信息.. 一个是带背景色改变宽度来实现百分比,这种方法调控件透明比较困难
      

  4.   

    稍微写了一下,不知道是不是这样的效果:
    public class MyTextBox:TextBox
    {
    public MyTextBox()
    {
    this.SetStyle(ControlStyles.AllPaintingInWmPaint
    | ControlStyles.OptimizedDoubleBuffer
    | ControlStyles.ResizeRedraw
    | ControlStyles.UserPaint, true);
    this.UpdateStyles(); this.MinValue = 0;
    this.MaxValue = 100;
    } public int MinValue { get; set; }
    public int MaxValue { get; set; }
    double value; protected override void WndProc(ref System.Windows.Forms.Message m)
    {
    switch (m.Msg)
    {
    case 0X0102:
    if ((int)m.WParam == 46)
    {
    if (this.Text.Contains("."))
    return;
    }
    else if ((int)m.WParam != 8 && !char.IsNumber((char)m.WParam))
    {
    return;
    }
    break;
    case 15:
    this.Invalidate();
    break;
    } base.WndProc(ref m);
    } protected override void OnTextChanged(EventArgs e)
    {
    if (this.Text.Trim().Length == 0)
    return; this.value = double.Parse(this.Text);
    } protected override void OnLostFocus(EventArgs e)
    {
    base.OnLostFocus(e); if (this.Text.Trim().Length == 0)
    this.Text = "0";
    } protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e); if (!DesignMode)
    e.Graphics.FillRectangle(new Pen(Color.FromArgb(210, 220, 235)).Brush, 1, 1, this.Width*(int)value/(MaxValue-MinValue), this.Height-6);
    e.Graphics.DrawString(this.Text, this.Font, Brushes.Black, 1, 2);
    }
    }