• WPF Slider Tickbar 中显示数值


    class CustomTickBar : TickBar
    {
     protected override void OnRender(System.Windows.Media.DrawingContext dc)
     {
      double num = this.Maximum - this.Minimum;
      double y = this.ReservedSpace * 0.5;
      FormattedText formattedText = null;
      double x = 0;
      for(double i = 0; i <= num; i += this.TickFrequency)
      {
       formattedText = new FormattedText(i.ToString(), FlowDirection.LeftToRight, 
        new Typeface("Verdana"), 8, Brushes.Black);
       if(this.Minimum == i)
        x = 0;
       else
        x += this.ActualWidth / (num / this.TickFrequency) ;
    
    if (i == this.Maximum)
                    {
                        x = x - 5;//减去5,防止最后数字不显示
                    } 
    
       dc.DrawText(formattedText, new Point(x, 10)); 
      }
     }
    }
    public class CustomTickBar:TickBar
    {
        protected override void OnRender(DrawingContext dc)
        {
            Size size = new Size (base.ActualWidth,base.ActualHeight);
    
            int tickCount = (int)((this.Maximum - this.Minimum) / this.TickFrequency)+1;
    
            if ((this.Maximum - this.Minimum) % this.TickFrequency == 0)
    
                tickCount -= 1;
    
            Double tickFrequencySize;
    
            // Calculate tick's setting
    
            tickFrequencySize = (size.Width * this.TickFrequency / (this.Maximum - this.Minimum));
    
            string text = "";
    
            FormattedText formattedText = null;
    
            double num = this.Maximum - this.Minimum;
    
            int i = 0;
    
            // Draw each tick text
    
            for (i = 0;i <= tickCount;i++)
            {
                text = Convert.ToString (Convert.ToInt32 (this.Minimum + this.TickFrequency * i),10);
    
                //g.DrawString(text, font, brush, drawRect.Left + tickFrequencySize * i, drawRect.Top + drawRect.Height/2, stringFormat);
    
                formattedText = new FormattedText (text,CultureInfo.GetCultureInfo ("en-us"),FlowDirection.LeftToRight,new Typeface ("Verdana"),8,Brushes.Black);
    
                dc.DrawText (formattedText,new Point ((tickFrequencySize * i),30));
            }
    
        }
    }
    public class CustomTickBar : TickBar
        {
            protected override void OnRender(DrawingContext dc)
            {
                Size size = new Size(base.ActualWidth, base.ActualHeight); 
                int tickCount = (int)((this.Maximum - this.Minimum) / this.TickFrequency) + 1;
                if ((this.Maximum - this.Minimum) % this.TickFrequency == 0)
                    tickCount -= 1;
                Double tickFrequencySize; 
                // Calculate tick's setting 
                tickFrequencySize = (size.Width * this.TickFrequency / (this.Maximum - this.Minimum));
                string text = ""; 
                FormattedText formattedText = null; 
                double num = this.Maximum - this.Minimum; 
                int i = 0; 
                // Draw each tick text 
                for (i = 0; i <= tickCount; i++)
                {
                    text = Convert.ToString(Convert.ToInt32(this.Minimum + this.TickFrequency * i), 10);
                    //g.DrawString(text, font, brush, drawRect.Left + tickFrequencySize * i, drawRect.Top + drawRect.Height/2, stringFormat);
                    formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 8, Brushes.Black);
    
                    double x = tickFrequencySize * i;
                    double y = 5;
                    if (i == this.Maximum)
                    {
                        x = x - 5;
                    }
                    Pen pen = new Pen(Brushes.Red,2);
                    dc.DrawLine(pen, new Point(x+2, 0), new Point(x+2,y));
                    dc.DrawText(formattedText, new Point(x, y));
                }
    
            }
        }
  • 相关阅读:
    Android控件显示和隐藏
    Android Viewpager+Fragment实现滑动标签页
    Android中的color使用
    Android自定义Button按钮显示样式
    Android通过Intent传递对象
    Android中AsyncTask的使用
    iOS,推送通知
    UIWebView与JS的交互
    iOS蓝牙中的进制转换,数据格式转换
    Core Graphics 定制UIVIew 处理图片
  • 原文地址:https://www.cnblogs.com/tianciliangen/p/7411885.html