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);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。