本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
}
示例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;
}
示例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);
}
示例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");
});
}
示例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;
}
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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;
}