• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Controls.Canvas类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Windows.Controls.Canvas的典型用法代码示例。如果您正苦于以下问题:C# Canvas类的具体用法?C# Canvas怎么用?C# Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Canvas类属于System.Windows.Controls命名空间,在下文中一共展示了Canvas类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Game

        public Game(UserControl userControl, Canvas drawingCanvas, Canvas debugCanvas, TextBlock txtDebug)
        {
            //Initialize
            IsActive = true;
            IsFixedTimeStep = true;
            TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 16);
            Components = new List<DrawableGameComponent>();
            World = new World(new Vector2(0, 0));
            _gameTime = new GameTime();
            _gameTime.GameStartTime = DateTime.Now;
            _gameTime.FrameStartTime = DateTime.Now;
            _gameTime.ElapsedGameTime = TimeSpan.Zero;
            _gameTime.TotalGameTime = TimeSpan.Zero;

            //Setup Canvas
            DrawingCanvas = drawingCanvas;
            DebugCanvas = debugCanvas;
            TxtDebug = txtDebug;
            UserControl = userControl;

            //Setup GameLoop
            _gameLoop = new Storyboard();
            _gameLoop.Completed += GameLoop;
            _gameLoop.Duration = TargetElapsedTime;
            DrawingCanvas.Resources.Add("gameloop", _gameLoop);
        }
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:26,代码来源:Game.cs


示例2: Draw

        public static void Draw(Canvas canvas, List<LinePoint> points, Brush stroke, bool clear = true)
        {
            if (clear)
            {
                canvas.Children.Clear();
            }

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            PathGeometry myPathGeometry = new PathGeometry();

            foreach (LinePoint p in points)
            {
                PathFigure myPathFigure = new PathFigure();
                myPathFigure.StartPoint = p.StartPoint;

                LineSegment myLineSegment = new LineSegment();
                myLineSegment.Point = p.EndPoint;

                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myLineSegment);

                myPathFigure.Segments = myPathSegmentCollection;

                myPathFigureCollection.Add(myPathFigure);
            }

            myPathGeometry.Figures = myPathFigureCollection;
            Path myPath = new Path();
            myPath.Stroke = stroke == null ? Brushes.Black : stroke;
            myPath.StrokeThickness = 1;
            myPath.Data = myPathGeometry;

            canvas.Children.Add(myPath);
        }
开发者ID:Eddie104,项目名称:Libra-CSharp,代码行数:34,代码来源:GraphicsHelper.cs


示例3: PlatformWpf

        public PlatformWpf()
            : base(null, true)
        {
            var app = new Application ();
            var slCanvas = new Canvas ();
            var win = new Window
            {
                Title = Title,
                Width = Width,
                Height = Height,
                Content = slCanvas
            };

            var cirrusCanvas = new CirrusCanvas(slCanvas, Width, Height);
            MainCanvas = cirrusCanvas;

            win.Show ();

            EntryPoint.Invoke (null, null);

            var timer = new DispatcherTimer ();
            timer.Tick += runDelegate;
            timer.Interval = TimeSpan.FromMilliseconds (1);

            timer.Start ();
            app.Run ();
        }
开发者ID:chkn,项目名称:cirrus,代码行数:27,代码来源:Bootstrap.cs


示例4: Visit

		public override void Visit(ExportContainer exportContainer){
			
			sectionCanvas = FixedDocumentCreator.CreateContainer(exportContainer);
			sectionCanvas.Name = exportContainer.Name;
			CanvasHelper.SetPosition(sectionCanvas,new Point(exportContainer.Location.X,exportContainer.Location.Y));
			PerformList(sectionCanvas,exportContainer.ExportedItems);
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:7,代码来源:WpfVisitor.cs


示例5: drawGridLines

        public void drawGridLines(Canvas gameCanvas, int gridStep, int gridLinesCount, int gridCirclesCount)
        {
            for (int i = 0; i < (gridLinesCount * 2); i++)
            {
                double angle = Math.PI / gridLinesCount * i;
                double length = gridStep * gridCirclesCount / 2;

                double X1 = 0;
                double Y1 = 0;
                double X2 = X1 - length * Math.Round(Math.Cos(angle), 2);
                double Y2 = Y1 - length * Math.Round(Math.Sin(angle), 2);

                Line gridLine = new Line()
                {
                    Name = "gridLine" + i.ToString(),
                    Stroke = Brushes.RoyalBlue,
                    StrokeThickness = 2,
                    X1 = X1,
                    Y1 = Y1,
                    X2 = X2,
                    Y2 = Y2
                };

                gridLines.Add(gridLine);
            }

            foreach (Line gridLine in gridLines)
            {
                gameCanvas.Children.Add(gridLine);
            }
        }
开发者ID:RomanV0703,项目名称:SnakesAndFoxes,代码行数:31,代码来源:DrawShapes.cs


示例6: GameTowerSelection

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="level">level data</param>
        /// <param name="x">horizontal coordinate of selected tile</param>
        /// <param name="y">vertical coordinate of selected tile</param>
        public GameTowerSelection(Level level, int x, int y)
        {
            InitializeComponent();

            // Set fields
            this.level = level;
            this.x = x;
            this.y = y;

            // Draw the cursor
            cursor = ControlManager.CreateCanvas(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\TowerHaven\\Marker", 8, 6, 8);
            nameGrid.Children.Add(cursor);

            // Find buildable towers that are affordable
            towers = level.GetBuildableTowers();
            int index = 0;
            foreach (Tower t in towers)
            {
                AddLabel(25, index, t.name, nameGrid);
                AddLabel(6, index, t.buildCost.ToString(), costGrid);
                AddLabel(6, index, t.range.ToString(), rangeGrid);
                AddLabel(6, index, t.damage.ToString(), damageGrid);
                AddLabel(6, index, t.status, statusGrid);
                index += 16;
            }
        }
开发者ID:Eniripsa96,项目名称:TowerHaven,代码行数:32,代码来源:GameTowerSelection.xaml.cs


示例7: ConsoleButtonControl

		public ConsoleButtonControl()
		{
			Container = new Canvas { Width = Width, Height = Height };

			ButtonConsole = new TiledImageButtonControl(
				"assets/ScriptCoreLib.Avalon.TiledImageButton/console.png".ToSource(),
				 Width, Height,
				 new TiledImageButtonControl.StateSelector
				 {
					 AsDisabled = s => s[0, 2],
					 AsEnabled = s => s[0, 0],
					 AsHot = s => s[0, 1],
					 AsPressed = s => s[0, 3]
				 }
			);
			ButtonConsole.Container.AttachTo(Container);


			ButtonConsole.Overlay.MouseLeftButtonUp +=
				delegate
				{
					if (!this.ButtonConsole.Enabled)
						return;

					if (this.Console != null)
						this.Console();
				};
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:28,代码来源:ConsoleButtonControl.cs


示例8: TestImplicitStyleRectangle_multipleImplicitStylesInVisualTree

		public void TestImplicitStyleRectangle_multipleImplicitStylesInVisualTree ()
		{
			Style rectStyle1 = new Style { TargetType = typeof (Rectangle) };
			Setter setter = new Setter (FrameworkElement.WidthProperty, 100.0);
			rectStyle1.Setters.Add (setter);

			Style rectStyle2 = new Style { TargetType = typeof (Rectangle) };
			setter = new Setter (FrameworkElement.HeightProperty, 100.0);
			rectStyle2.Setters.Add (setter);

			Rectangle r = new Rectangle ();
			r.Resources.Add (typeof (Rectangle), rectStyle1);

			Canvas c = new Canvas ();
			c.Resources.Add (typeof (Rectangle), rectStyle2);

			c.Children.Add (r);

			Assert.IsTrue (Double.IsNaN (r.Height), "1");

			CreateAsyncTest (c,  () => {
					Assert.AreEqual (100.0, r.Width, "2");
					Assert.IsTrue (Double.IsNaN (r.Height), "3");

					r.Resources.Remove (typeof (Rectangle));

					Assert.AreEqual (100.0, r.Height, "4");
					Assert.IsTrue (Double.IsNaN (r.Width), "5");
				});
		}
开发者ID:dfr0,项目名称:moon,代码行数:30,代码来源:StyleTest_Implicit.cs


示例9: MoonlightWidget

        public MoonlightWidget()
        {
            this.Build();

            silver = new GtkSilver(100, 100);
            silver.Transparent = true;
            canvas = new Canvas();
            canvas.Width = 100;
            canvas.Height = 100;
            canvas.Background = new SolidColorBrush(Colors.White);
            silver.Attach(canvas);

            //			Image image = new Image();
            //			image.Stretch = Stretch.Fill;
            //			image.Width = 100;
            //			image.Height = 100;
            //			Downloader downloader = new Downloader();
            //			downloader.Completed += delegate {
            //				image.SetSource(downloader, null);
            //			};
            //			downloader.Open("GET", new Uri("file:///home/ceronman/Escritorio/images/bigbrother.png"));
            //			downloader.Send();
            //
            //			canvas.Children.Add(image);

            this.Add(silver);
        }
开发者ID:mono,项目名称:lunareclipse,代码行数:27,代码来源:MoonlightWidget.cs


示例10: Wall

 public Wall(Canvas container, Point position, double width, double height) {
   this.container = container;
   this.position = position;
   this.width = width;
   this.height = height;
   this.image = new ImageBrush();
   Debug.WriteLine("IMG width: " + imageSource.PixelWidth + ", height: " + imageSource.PixelHeight);
   this.image.ImageSource = imageSource;
   this.image.Stretch = Stretch.None;
   transform = new TranslateTransform();
   transform.X = -this.position.X;
   transform.Y = -this.position.Y;
   st = new ScaleTransform();
   st.ScaleX = 1.55;
   st.ScaleY = 2;
   this.image.RelativeTransform = st;
   this.image.Transform = transform;
   this.imageContainer = new Canvas();
   this.imageContainer.Width = width;
   this.imageContainer.Height = height;
   this.imageContainer.Background = this.image;
   this.container.Children.Add(this.imageContainer);
   Canvas.SetLeft(this.imageContainer, this.position.X);
   Canvas.SetTop(this.imageContainer, this.position.Y);
   Canvas.SetZIndex(this.imageContainer, 2);
 }
开发者ID:serioja90,项目名称:labirynth,代码行数:26,代码来源:Wall.cs


示例11: VisualNode

        /// <summary>
        /// Initializes a new instance of the <see cref="VisualNode"/> class with random Position, speed and direction.
        /// </summary>
        /// <param name="rand">The rand.</param>
        /// <param name="canvas">The canvas.</param>
        public VisualNode(Random rand, Canvas canvas)
        {
            this.rand = rand;

            // choose a random position
            this.X = rand.Next(this.NodeSizeMax(), (int)canvas.Width - this.NodeSizeMax());
            this.Y = rand.Next(this.NodeSizeMax(), (int)canvas.Height - this.NodeSizeMax());

            this.CurrentX = this.X;
            this.CurrentY = this.Y;

            this.Connectedness = 0;

            // create ellipses that make the node, it's outline and 2 shadows
            this.Center = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(105, 255, 255, 255)) };
            this.Outline = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)) };
            this.Shadow1 = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)) };
            this.Shadow2 = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(60, 255, 255, 255)) };

            // add the shapes to the canvas UIElement
            canvas.Children.Add(this.Center);
            canvas.Children.Add(this.Outline);
            canvas.Children.Add(this.Shadow1);
            canvas.Children.Add(this.Shadow2);

            // set the ZIndex so the Center is in front of the outline and shadows
            Canvas.SetZIndex(this.Center, 10);
            Canvas.SetZIndex(this.Outline, 9);
            Canvas.SetZIndex(this.Shadow1, 8);
            Canvas.SetZIndex(this.Shadow2, 7);
        }
开发者ID:iangriggs,项目名称:alphalabs,代码行数:36,代码来源:VisualNode.cs


示例12: PreviewGrid

        public PreviewGrid(Picture picture)
            : base()
        {
            _displayPicture = picture;
            _viewPort = new ViewportControl();
            this.Children.Add(_viewPort);

            _viewPort.ManipulationStarted += OnViewportManipulationStarted;
            _viewPort.ManipulationDelta += OnViewportManipulationDelta;
            _viewPort.ManipulationCompleted += OnViewportManipulationCompleted;
            _viewPort.ViewportChanged += OnViewportChanged;

            ImageLoaded = false;

            _imageView = new Image();
            _bitmap = new BitmapImage();
            //_bitmap.SetSource(picture.GetImage());
            _imageView.Source = _bitmap;
            _imageView.Stretch = Stretch.Uniform;
            _imageView.RenderTransformOrigin = new Point(0, 0);

            _scaleTransform = new ScaleTransform();
            _imageView.RenderTransform = _scaleTransform;

            _imageHolderCanvas = new Canvas();
            _imageHolderCanvas.Children.Add(_imageView);

            _viewPort.Content = _imageHolderCanvas;

            //LoadImage();
        }
开发者ID:KayNag,项目名称:LumiaImagingSDKSample,代码行数:31,代码来源:PreviewGrid.cs


示例13: DrawCanvasLayout

        public static void DrawCanvasLayout(Canvas canvas)
        {
            CanvasDrawing.ClearCanvas("Line", canvas);
            CanvasDrawing.ClearCanvas("TextBlock", canvas);
            CanvasDrawing.ClearCanvas("Ellipse", canvas);
            CanvasDrawing.ClearCanvas("Arrow", canvas);

            double h = Math.Truncate(canvas.ActualHeight / 100);
            int heigth = (int)h;
            double w = Math.Truncate(canvas.ActualWidth / 100);
            int width = (int)w;

            for (int i = 0; i <= heigth; i++)
            {
                Point p1 = new Point(0, i * 100);
                Point p2 = new Point(canvas.ActualWidth, i * 100);
                CanvasDrawing.DrawLine(p1, p2, canvas);
            }

            for (int j = 0; j <= width; j++)
            {
                var p1 = new Point(j * 100, canvas.ActualHeight);
                var p2 = new Point(j * 100, 0);
                CanvasDrawing.DrawLine(p1, p2, canvas);
            }
            CanvasDrawing.DrawNumber(new Point(100, 100), "(100;100)", canvas);
        }
开发者ID:CyrilvonLutzow,项目名称:Csharp-WPF-Travelling-Salesman-problem,代码行数:27,代码来源:CanvasDrawing.cs


示例14: Lock

 public Lock(Ellipse ellipse, Canvas canvas, double width)
 {
     _ellipse = ellipse;
     _canvas = canvas;
     _width = width;
     Position = 0;
 }
开发者ID:rechc,项目名称:KinectMiniApps,代码行数:7,代码来源:Lock.cs


示例15: Graph

 private System.Windows.FrameworkElement Graph(double[] operands)
 {
     Grid g = new Grid();
     double max = operands[0];
     foreach (double d in operands)
     {
         max = Math.Max(max, d);
     }
     int rows = (int)max;
     int columns = operands.Length;
     for (int i = 0;i<columns;i++)
     {
         g.ColumnDefinitions.Add(new ColumnDefinition());
     }
     for (int i = 0; i < rows; i++)
     {
         g.RowDefinitions.Add(new RowDefinition());
     }
     for (int c = 0; c <columns; c++)
     {
         for (int r = (int)operands[c]; r >= 0; r--)
         {
             Canvas canvas = new Canvas();
             System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush();
             brush.Color = System.Windows.Media.Colors.Red;
             canvas.Background = brush;
             Grid.SetColumn(canvas, c);
             Grid.SetRow(canvas, rows-r);
             g.Children.Add(canvas);
         }
     }
     g.Width = 229;
     g.Height = 229;
     return g;
 }
开发者ID:chrisnicola,项目名称:MAFtoMEFSample,代码行数:35,代码来源:BasicVisualAddIn.cs


示例16: Circuit

        public Circuit(Canvas canvas)
        {
            this._canvas = canvas;
            _nearDist = new Vector(0,10);
            _farDist = new Vector(0,30);

            _imLtOff = new BitmapImage(new Uri(@"Images/12-LightOff.bmp", UriKind.Relative));
            _imLtOn = new BitmapImage(new Uri(@"Images/12-LightOn.bmp", UriKind.Relative));

            _imLamp.Source = _imLtOff;
            _lightOn = false;

            canvas.Children.Add(_imLamp);
            Canvas.SetLeft(_imLamp, 70.0);
            Canvas.SetTop(_imLamp, 5.0);

            _switch1 = new Switch(canvas, 150, 100);
            _switch1.evToggle += new EventHandler(switch_evToggle);
            _switch1.evSwitchMoved += new EventHandler(switch_evSwitchMoved);
            _switch2 = new Switch(canvas, 25, 100);
            _switch2.evToggle += new EventHandler(switch_evToggle);
            _switch2.evSwitchMoved += new EventHandler(switch_evSwitchMoved);

            _yNear = _switch1.Con2.Y + _nearDist.Y;
            _yFar = _switch1.Con2.X + _farDist.X;
            RouteWires(canvas);
        }
开发者ID:AlexJCarstensen,项目名称:Switch-I4GUI,代码行数:27,代码来源:Circuit.cs


示例17: ContentCardImage

        public ContentCardImage(Canvas parent_canvas, Color highlight_color, ExplorerContentImage explorer_image)
            : base(parent_canvas, highlight_color)
        {
            explorerImage = explorer_image;

            StackPanel background = new StackPanel();
            background.Orientation = Orientation.Vertical;
            background.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
            background.Margin = new Thickness(5);

            Image image = explorerImage.getImage();
            image.MaxWidth = 300;
            image.MaxHeight = 400;
            image.Margin = new Thickness(0, 0, 0, 5);
            background.Children.Add(image);

            Label caption = new Label();
            caption.Content = explorerImage.getName();
            caption.FontSize = 20;
            caption.MaxWidth = 300;
            caption.FontWeight = FontWeights.Bold;
            background.Children.Add(caption);

            setContent(background);
        }
开发者ID:MikeOrtman,项目名称:MultitouchExplorer,代码行数:25,代码来源:ContentCardImage.cs


示例18: build

        public async Task<bool> build(int time, int x, int y, Canvas canvas)
        {
            state = 0;
            System.Diagnostics.Debug.WriteLine("La construction du batiment " + name + " a commencé !");

            //creation of the image of the building in construction
            Image image = new Image
            {
                Width = 50,
                Height = 50,
                Name = this.name,
                Source = new BitmapImage(new Uri(imageBeingBuilt, UriKind.Absolute)),
            };
            Canvas.SetTop(image, y);
            Canvas.SetLeft(image, x);
            indexCanvas = canvas.Children.Add(image);

            await Task.Delay(TimeSpan.FromSeconds(time));   //construction of the building
            state = 1;
            System.Diagnostics.Debug.WriteLine("Le batiment " + name + " est construit !");

            //modification of the image: the building is now built
            image.Source = new BitmapImage(new Uri(imageBuilt, UriKind.Absolute));
            return true;
            
    }
开发者ID:TerisseNicolas,项目名称:Archip3l-WPF,代码行数:26,代码来源:Building.cs


示例19: ItemFlyInAndOutAnimations

 public ItemFlyInAndOutAnimations()
 {
     // construct a popup, with a Canvas as its child
       _popup = new Popup();
       _popupCanvas = new Canvas();
       _popup.Child = _popupCanvas;
 }
开发者ID:Kelin-Hong,项目名称:JobHub_WP,代码行数:7,代码来源:MetroInMotion.cs


示例20: SilverlightRenderContext

 /// <summary>
 /// Initializes a new instance of the <see cref="SilverlightRenderContext" /> class.
 /// </summary>
 /// <param name="canvas">The canvas.</param>
 public SilverlightRenderContext(Canvas canvas)
 {
     this.canvas = canvas;
     this.Width = canvas.ActualWidth;
     this.Height = canvas.ActualHeight;
     this.RendersToScreen = true;
 }
开发者ID:Cheesebaron,项目名称:oxyplot,代码行数:11,代码来源:SilverlightRenderContext.cs



注:本文中的System.Windows.Controls.Canvas类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Controls.CheckBox类代码示例发布时间:2022-05-26
下一篇:
C# Controls.Button类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap