当前位置: 首页>>代码示例>>C#>>正文


C# Controls.Canvas类代码示例

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


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


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