當前位置: 首頁>>代碼示例>>C#>>正文


C# Shapes.Rectangle類代碼示例

本文整理匯總了C#中System.Windows.Shapes.Rectangle的典型用法代碼示例。如果您正苦於以下問題:C# Rectangle類的具體用法?C# Rectangle怎麽用?C# Rectangle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Rectangle類屬於System.Windows.Shapes命名空間,在下文中一共展示了Rectangle類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Meter8

        public Meter8()
        {
            var borderBrush = new LinearGradientBrush();
            borderBrush.StartPoint = new Point();
            borderBrush.EndPoint = new Point(1d, 1d);
            borderBrush.GradientStops.Add(new GradientStop() { Color = Colors.White, Offset = 0d });
            borderBrush.GradientStops.Add(new GradientStop() { Color = Colors.White, Offset = 0.4999d });
            borderBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(0xff, 0x84, 0x7B, 0x6C), Offset = 0.5d });
            borderBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(0xff, 0x84, 0x7B, 0x6C), Offset = 1d });
            var border = new Rectangle();
            border.Fill = borderBrush;
            //border.Stroke = new SolidColorBrush(Colors.Black);
            //border.StrokeThickness = 1d;

            var background = new Rectangle();
            background.Fill = new SolidColorBrush(Color.FromArgb(0xff, 0xAD, 0xA7, 0x9D));
            background.Margin = new Thickness(4d);

            var grid = new Grid();
            grid.Children.Add(border);
            grid.Children.Add(background);
            grid.Children.Add(_canvas);
            grid.Children.Add(_calibrationCanvas);

            this.Content = grid;

            _label.Text = Value.ToString();
            _label.Foreground = new SolidColorBrush(ForeColor);

            _pointLine.Stroke = new SolidColorBrush(Colors.Red);
            _pointLine.StrokeThickness = 2d;
            this.SizeChanged += Meter_SizeChanged;
        }
開發者ID:Jitlee,項目名稱:MonitorProject,代碼行數:33,代碼來源:Meter8.cs

示例2: WatchViewFullscreen

        public WatchViewFullscreen()
        {
            InitializeComponent();

            MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(view_MouseButtonIgnore);
            MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(view_MouseButtonIgnore);
            MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(view_MouseRightButtonUp);
            PreviewMouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(view_PreviewMouseRightButtonDown);

            MenuItem mi = new MenuItem();
            mi.Header = "Zoom to Fit";
            mi.Click += new RoutedEventHandler(mi_Click);

            MainContextMenu.Items.Add(mi);

            System.Windows.Shapes.Rectangle backgroundRect = new System.Windows.Shapes.Rectangle();
            Canvas.SetZIndex(backgroundRect, -10);
            backgroundRect.IsHitTestVisible = false;
            BrushConverter bc = new BrushConverter();
            Brush strokeBrush = (Brush)bc.ConvertFrom("#313131");
            backgroundRect.Stroke = strokeBrush;
            backgroundRect.StrokeThickness = 1;
            SolidColorBrush backgroundBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(250, 250, 216));
            backgroundRect.Fill = backgroundBrush;

            inputGrid.Children.Add(backgroundRect);
        }
開發者ID:romeo08437,項目名稱:Dynamo,代碼行數:27,代碼來源:WatchViewFullscreen.xaml.cs

示例3: boardCanvas_MouseDown

        public void boardCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            boardCanvas.CaptureMouse();
            sP = e.GetPosition(boardCanvas);
            newAtr.Color = (Color)colorStroke.SelectedColor;
            newAtr.Height = newAtr.Width = slider.Value;
            boardCanvas.DefaultDrawingAttributes = newAtr;

            if (tempTool == pencilImage.Name || tempTool == eraserImage.Name || tempTool == circleImage.Name || tempTool == rectangleImage.Name)
            {

               if (tempTool == circleImage.Name)
                {
                    ellipse = new Ellipse();
                }
                else if (tempTool == rectangleImage.Name)
                {
                    rect = new Rectangle();
                }
            }
            else if (tempTool == lineImage.Name)
            {
                line_C = new Line();
            }

            else if (tempTool == textBoxImage.Name) {
                tB = new TextBox();
            }

            //eP = new Point(0, 0);
        }
開發者ID:asadnadeem93,項目名稱:Collaboard,代碼行數:31,代碼來源:boardPage.xaml.cs

示例4: Create

        public static Uri Create(string filename, string text, SolidColorBrush backgroundColor, double textSize, Size size)
        {
            var background = new Rectangle();
            background.Width = size.Width;
            background.Height = size.Height;
            background.Fill = backgroundColor;

            var textBlock = new TextBlock();
            textBlock.Width = 500;
            textBlock.Height = 500;
            textBlock.TextWrapping = TextWrapping.Wrap;
            textBlock.Text = text;
            textBlock.FontSize = textSize;
            textBlock.Foreground = new SolidColorBrush(Colors.White);
            textBlock.FontFamily = new FontFamily("Segoe WP");

            var tileImage = "/Shared/ShellContent/" + filename;
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
                bitmap.Render(background, new TranslateTransform());
                bitmap.Render(textBlock, new TranslateTransform() { X = 39, Y = 88 });
                var stream = store.CreateFile(tileImage);
                bitmap.Invalidate();
                bitmap.SaveJpeg(stream, (int)size.Width, (int)size.Height, 0, 99);
                stream.Close();
            }
            return new Uri("ms-appdata:///local" + tileImage, UriKind.Absolute);
        }
開發者ID:halllo,項目名稱:DailyQuote,代碼行數:29,代碼來源:LockScreenImage.cs

示例5: Brique

        //Constructeur
        public Brique(Grid parent, double posX, double posY, bool cassable)
        {
            //Création de l'ellipse
            this._forme = new Rectangle();

            //Ajout au parent
            parent.Children.Add(this._forme);

            //Taille de la Brique
            this._forme.Height = 20;
            this._forme.Width = 60;

            //Position de la Brique
            this._forme.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this._forme.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this._forme.Margin = new System.Windows.Thickness(posX, posY, 0, 0);

            this.Cassable = cassable;

            //Couleur de la Brique
            //Couleur de fond
            Thread.Sleep(1);
            Random R = new Random(unchecked((int)DateTime.Now.Ticks));
            SolidColorBrush couleurFond = new SolidColorBrush();
            byte Red = (byte)(R.Next(253) + 1);
            byte Green = (byte)(R.Next(253) + 1);
            byte Blue = (byte)(R.Next(253) + 1);
            //Noire si incassable
            couleurFond.Color = cassable ? Color.FromRgb(Red, Green, Blue) : Color.FromRgb(0, 0, 0);
            this._forme.Fill = couleurFond;
            //Couleur de bordure
            SolidColorBrush couleurBord = new SolidColorBrush();
            couleurBord.Color = Color.FromRgb(255, 255, 255);
            this._forme.Stroke = couleurBord;
        }
開發者ID:mbonitho,項目名稱:ClockTwo,代碼行數:36,代碼來源:Brique.cs

示例6: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            Body = GetTemplateChild(BodyName) as Grid;
            Slider = GetTemplateChild(SliderName) as SuperSlider;

            if (Thumb == null)
                Thumb = new ColorSliderThumb();

            SelectedColor = GetTemplateChild(SelectedColorName) as Rectangle;
            
            SizeChanged += UserControl_SizeChanged;

            if (Slider != null)
            {
                Slider.ValueChanged += Slider_ValueChanged;

                if (Color.A == 0 && Color.R == 0 && Color.G == 0 && Color.B == 0)
                    Color = System.Windows.Media.Color.FromArgb(255, 6, 255, 0);
                else
                    UpdateLayoutBasedOnColor();
            }

			IsEnabledVisualStateUpdate();
        }
開發者ID:sheeeng,項目名稱:wolwp,代碼行數:26,代碼來源:ColorSlider.cs

示例7: PerformCaptureAnimation

        private void PerformCaptureAnimation()
        {
            LoadingView.Text = "Processing ...";
            ShowLoadingView();

            curtain = new Rectangle();
            curtain.Fill = new SolidColorBrush(Colors.White);
            LayoutRoot.Children.Add(curtain);

            Storyboard animation = new Storyboard();
            Duration duration = new Duration(TimeSpan.FromSeconds(0.3));
            animation.Duration = duration;

            DoubleAnimation curtainAnimation = new DoubleAnimation();
            animation.Children.Add(curtainAnimation);
            curtainAnimation.Duration = duration;
            curtainAnimation.To = 0;
            curtainAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn };
            Storyboard.SetTarget(curtainAnimation, curtain);
            Storyboard.SetTargetProperty(curtainAnimation, new PropertyPath("Opacity"));

            animation.Completed += (sender, e) => {
                LayoutRoot.Children.Remove(curtain);
            };

            animation.Begin();
        }
開發者ID:powerytg,項目名稱:indulged-flickr,代碼行數:27,代碼來源:ProCamAnimation.cs

示例8: DragAdorner

        public DragAdorner(UIElement owner, UIElement adornElement, bool useVisualBrush, double opacity)
            : base(owner)
        {
            this.owner  = owner;

            if (useVisualBrush)
            {
                VisualBrush brush   = new VisualBrush(adornElement);
                Rectangle   rect    = new Rectangle();

                brush.Opacity       = opacity;
                rect.RadiusX        = 3;
                rect.RadiusY        = 3;
                rect.Width          = adornElement.DesiredSize.Width;
                rect.Height         = adornElement.DesiredSize.Height;

                this.XCenter        = adornElement.DesiredSize.Width / 2;
                this.YCenter        = adornElement.DesiredSize.Height / 2;

                rect.Fill = brush;

                this.child = rect;
            }
            else
            {
                this.child = adornElement;
            }
        }
開發者ID:cipjota,項目名稱:Chronos,代碼行數:28,代碼來源:DragAdorner.cs

示例9: Paper

        public Paper()
        {
            // paper properties
            Background = new SolidColorBrush(Colors.White);
            Cursor = Cursors.IBeam;

            // setup caret
            caret = new Rectangle();
            caret.Fill = new SolidColorBrush(Colors.Black);
            caret.Height = 12;
            caret.Width = 1;
            caret.Margin = new Thickness(-1, 0, 0, 0);

            // setup caret timer
            caretTimer = new DispatcherTimer();
            caretTimer.Interval = TimeSpan.FromSeconds(0.5);
            caretTimer.Tick += delegate { caret.Visibility = (caret.Visibility == Visibility.Visible || !ShowCaret) ? Visibility.Collapsed : Visibility.Visible; };
            caretTimer.Start();

            // setup highlighting indicies
            HighlightedBlocks = new List<Character>();
            HighlightFromIndex = new Index(0, 0);
            HighlightToIndex = new Index(0, 0);

            // events
            MouseLeftButtonDown += Paper_MouseLeftButtonDown;
            MouseLeftButtonUp += Paper_MouseLeftButtonUp;
        }
開發者ID:anaimi,項目名稱:codebox,代碼行數:28,代碼來源:Paper.cs

示例10: PictureTangle

        private void PictureTangle(string state, int row, int colume)
        {
            
            Rectangle rectangle = new Rectangle();
            rectangle.StrokeThickness = 3;
            rectangle.Stroke = Brushes.Black;
            rectangle.RadiusX = 30;
            rectangle.RadiusY = 30;
            rectangle.Width = 100;
            rectangle.Height = 80;

            Label label = new Label();
            label.Margin = new Thickness(0);
            label.Width = 100;
            label.Height = 80;
            label.Content = state;
            label.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
            label.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
            
            gridpic.Children.Add(rectangle);
            gridpic.Children.Add(label);

            Grid.SetRow(rectangle, row);
            Grid.SetColumn(rectangle, colume);

            Grid.SetRow(label, row);
            Grid.SetColumn(label, colume);
        }
開發者ID:ZhouLuhan,項目名稱:GraduateProject,代碼行數:28,代碼來源:MainWindow.xaml.cs

示例11: TestImplicitStyleRectangle_styleInRectangleDictionary

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

			Rectangle r = new Rectangle ();

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

			r.Resources.Add (typeof (Rectangle), rectStyle);

			Assert.AreEqual (100.0, r.Width, "2");

			CreateAsyncTest (r,  () => {
					Assert.AreEqual (100.0, r.Width, "3");

					//setter.Value = 200.0;
					//Assert.AreEqual (200.0, r.Width, "4");

					rectStyle.Setters.Remove (setter);

					Assert.AreEqual (100.0, r.Width, "5");
				});
		}
開發者ID:dfr0,項目名稱:moon,代碼行數:25,代碼來源:StyleTest_Implicit.cs

示例12: CriarProcesso

        //============== Funções ====================================
        public void CriarProcesso(double top, double left)
        {
            Rectangle rectangle;
            rectangle = new Rectangle();
            Canvas.SetTop(rectangle, top);
            Canvas.SetLeft(rectangle, left);
            rectangle.Fill = System.Windows.Media.Brushes.White;
            rectangle.Height = 20;
            rectangle.Width = 40;
            rectangle.StrokeThickness = 2;
            rectangle.Stroke = System.Windows.Media.Brushes.Gray;
            

            for (int i = 0; i < Processos.Count; i++)
            {
                if (Processos[i].Left == left && Processos[i].Top == top)
                {
                    Label lbl = new Label();
                    lbl.Content = "P" + Processos[i].ID;
                    Canvas.SetLeft(lbl, left + 10);
                    Canvas.SetTop(lbl, top - 2);

                    rectangle.Name = ("P" + Processos[i].ID);
                    Elementos.Add(rectangle);

                    Elementos.Add(lbl);

                    Processos[i].Texto = lbl;
                    break;
                }
            }

        }
開發者ID:marlonluft,項目名稱:DeadLockWPF,代碼行數:34,代碼來源:Funcoes.cs

示例13: DrawingArea_MouseDown

        private void DrawingArea_MouseDown(object sender, MouseButtonEventArgs e)
        {
            startingPoint = e.GetPosition(DrawingArea);
            if (currentState == drawingState.CreateNewBounds)
            {// Creating and tracking a new Rectangle
                toCreateRectangle = new System.Windows.Shapes.Rectangle();
                toCreateRectangle.Stroke = Brushes.Black;
                toCreateRectangle.Opacity = .25;
                toCreateRectangle.Fill = Brushes.RosyBrown;
                toCreateRectangle.StrokeThickness = 4;
                toCreateRectangle.MinWidth = 25;
                toCreateRectangle.MinHeight = 25;
                Canvas.SetLeft(toCreateRectangle, startingPoint.X);
                Canvas.SetTop(toCreateRectangle, startingPoint.Y);
                DrawingArea.Children.Add(toCreateRectangle);
            }
            if (currentState == drawingState.PanView)
            {
                HitTestResult result = VisualTreeHelper.HitTest(DrawingArea, startingPoint);
                if (result != null)
                {
                    if (result.VisualHit is Rectangle)
                    {
                        toCreateRectangle = (Rectangle)result.VisualHit;

                        double offSetX = Canvas.GetLeft(toCreateRectangle) - startingPoint.X;
                        double offSetY = Canvas.GetTop(toCreateRectangle) - startingPoint.Y;
                        startingPoint = new Point(offSetX, offSetY);
                    }
                }
            }
        }
開發者ID:Narucross,項目名稱:JFlor_Practices,代碼行數:32,代碼來源:MainWindow.xaml.cs

示例14: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            imagen = new BitmapImage(new Uri(System.IO.Directory.GetCurrentDirectory() + @"\Imagenes\imagen.jpg"));
            Rectangle rectangle = new Rectangle();
            rectangle.Width = 500;
            rectangle.Height = 500;
            rectangle.Fill = new ImageBrush(imagen);

            tablero = new Tablero(3, 3, imagen);

            foreach (Pieza p in tablero.Piezas)
            {
                Rectangle r = new Rectangle();
                r.Width = Canvas.Width / tablero.Filas;
                r.Height = Canvas.Height / tablero.Columnas;
                r.Fill = new ImageBrush(p.Imagen);
                r.Stroke = new SolidColorBrush(Colors.Black);
                r.StrokeThickness = 1;
                r.SetValue(Canvas.LeftProperty, Convert.ToDouble(p.Columna * (Canvas.Width / tablero.Filas)));
                r.SetValue(Canvas.TopProperty, Convert.ToDouble(p.Fila * (Canvas.Height / tablero.Columnas)));
                Canvas.Children.Add(r);
            }
        }
開發者ID:jpmermoz,項目名稱:EightPuzzle,代碼行數:25,代碼來源:MainWindow.xaml.cs

示例15: CreateWindowCommandRectangle

        /// <summary>
        /// Creates the window command rectangle.
        /// </summary>
        /// <param name="parentButton">The parent button.</param>
        /// <param name="style">The style.</param>
        /// <returns>Rectangle.</returns>
        public static Rectangle CreateWindowCommandRectangle(Button parentButton, string style)
        {
            Argument.IsNotNull(() => parentButton);
            Argument.IsNotNullOrWhitespace(() => style);

            var rectangle = new Rectangle
            {
                Width = 16d,
                Height = 16d,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Stretch = Stretch.UniformToFill
            };

            rectangle.SetBinding(Rectangle.FillProperty, new Binding("Foreground")
            {
                Source = parentButton
            });

            var application = Application.Current;
            if (application != null)
            {
                rectangle.OpacityMask = new VisualBrush
                {
                    //Stretch = Stretch.Fill,
                    Visual = application.FindResource(style) as Visual
                };
            }

            return rectangle;
        }
開發者ID:icygit,項目名稱:Orchestra,代碼行數:37,代碼來源:WindowCommandHelper.cs


注:本文中的System.Windows.Shapes.Rectangle類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。