微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight 布局面板加控件方法


Silverlight 布局面板加控件方法 

添加文字方法

 TextBlock txt = new TextBlock();
                    txt.Text = tmc;
                    txt.FontSize = 12;
                    txt.Foreground = t_brush;
                    txt.FlowDirection = FlowDirection.LeftToRight;
                    //  
                    double tt_angle = this.GetAngle(eb,ee);
                    double t_angle = tt_angle;
                    t_angle = t_angle * 180.0 / this.PI;
                    if (t_angle >= 360)
                    {
                        t_angle -= 360;
                    }
                    t_angle = 360 - t_angle;  //修正用于顺时针rotate方向
                    //RotateTransform  //SkewTransform
                    RotateTransform rt = new RotateTransform();
                    rt.Angle = t_angle;  //顺时针rotate方向
                    rt.CenterX = 0; 
                    rt.CenterY = 0; 
                    txt.RenderTransform = rt;
                    txt.RenderTransformOrigin = new Point(t_atP.X,t_atP.Y);
                    //
                    txt.SetValue(Canvas.LeftProperty,t_atP.X);
                    txt.SetValue(Canvas.TopProperty,t_atP.Y);
                    //
                    this.cRoot.Children.Add(txt);
                    //----

添加直线的方法

Brush t_brush=new SolidColorBrush(this.LineColor);
            //
            double p_sx = this.wfView.MapToScreen_X((double)rt_t.SX);
            double p_sy = this.wfView.MapToScreen_Y((double)rt_t.SY);
            //
            double p_ex = this.wfView.MapToScreen_X((double)rt_t.EX);
            double p_ey = this.wfView.MapToScreen_Y((double)rt_t.EY);
            //
            PointD eb = new PointD();
            eb.X = (double)rt_t.SX;
            eb.Y = (double)rt_t.SY;
            PointD ee = new PointD();
            ee.X = (double)rt_t.EX;
            ee.Y = (double)rt_t.EY;
            //画线(用面对象只添加两个点来完成)
            polygon t_line = new polygon();  
            //            
            t_line.Points.Add(new Point(p_sx,p_sy));
            t_line.Points.Add(new Point(p_ex,p_ey));
            //
            t_line.Points.Add(new Point(p_sx,p_sy));
            //
            //t_line.strokeThickness = 2;
            //t_line.Opacity = 0.5;
            //t_line.Width = 2;
            t_line.stroke = t_brush;
            t_line.Fill = t_brush;
            //
            this.cRoot.Children.Add(t_line);  


添加图片和矩形框的方法

BitmapImage img = new BitmapImage();
                    img.CreateOptions = BitmapCreateOptions.None;
                    string path = "/AppSilverlight;component/WorkFlowNodeImageDir/png/" + t;
                    Stream s = Application.GetResourceStream(new Uri(path,UriKind.Relative)).Stream;
                    img.SetSource(s);
                    //
                    Image ui_img = new Image();
                    ui_img.source = img;
                    //计算节点左上角坐标
                    double top_x = (int)p_x;
                    top_x = top_x - img.PixelWidth / 2;
                    double top_y = (int)p_y;
                    top_y = top_y - img.PixelHeight / 2;
                    //
                    ui_img.SetValue(Canvas.LeftProperty,top_x);
                    ui_img.SetValue(Canvas.TopProperty,top_y);
                    this.cRoot.Children.Add(ui_img);
                    //
                    //画节点外边框
                    {                        
                        Rectangle rect = new Rectangle();
                        rect.stroke = t_Brush;
                        rect.Fill = new SolidColorBrush(Colors.Transparent);
                        rect.SetValue(Canvas.LeftProperty,top_x);
                        rect.SetValue(Canvas.TopProperty,top_y);
                        rect.Width = img.PixelWidth;
                        rect.Height = img.PixelHeight;
                        this.cRoot.Children.Add(rect);                        
                    }
                }
                //添加节点名称
                {   //画节点名称
                    string actmc = rt_act.ACTMC;
                    TextBlock txt = new TextBlock();                   
                    txt.Text = actmc;
                    txt.FontSize = 12;
                    txt.Foreground = t_Brush; 
                    char[] longLine = actmc.tochararray();
                    //修正节点名称显示位置
                    double t_txtLen = longLine.Length / 2.0;
                    t_txtLen = t_txtLen * txt.FontSize;
                    //
                    double x = p_x - t_txtLen;
                    double y = p_y + 24 + 0;
                    txt.SetValue(Canvas.LeftProperty,x);
                    txt.SetValue(Canvas.TopProperty,y);
                    //
                    this.cRoot.Children.Add(txt);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐