private void button1_Click(object sender, EventArgs e) { BaseShape f = null; switch (comboBox1.SelectedIndex) { case 0: f = new BaseTriangle(float.Parse(txtWidth.Text), float.Parse(txtHeight.Text)); break; case 1: f = new BaseRectangle(float.Parse(txtWidth.Text), float.Parse(txtHeight.Text)); break; case 2: f = new BaseSector(float.Parse(txtWidth.Text), int.Parse(txtHeight.Text)); break; default: break; } var p = new ConcreteParameters(float.Parse(txtX.Text), float.Parse(txtY.Text), int.Parse(txtAngle.Text)); var c = new ConcreteShape(f, p); ResultLabel.Text = c.ToString() + "\n" + c.GetMaxDistance(new PointF(0, 0)).ToString(); }
public static System.Drawing.RectangleF GetRectangleF(BaseRectangle rectangle) { return(new System.Drawing.RectangleF( (float)(rectangle.TopLeft.X), (float)(rectangle.TopLeft.Y), (float)(rectangle.Width), (float)(rectangle.Height))); }
static void Main(string[] args) { BaseRectangle rectangle = new BaseRectangle(20, 10); Console.WriteLine(rectangle.ToString()); Console.WriteLine(rectangle.Area); Console.WriteLine(rectangle.Center.ToString()); Console.ReadKey(); }
private void DisplayRectangles() { decoratorContent.Children.Clear(); randomNumber = new Random(); chartreuseBrush = new SolidColorBrush(Colors.Chartreuse); IBaseRectangle baseRect = new BaseRectangle(); // The base component interface AddRectangleToStackPanel( baseRect, "The base component interface" ); // The base component interface through the Stroke Decorator // with a Chartreuse stroke of random thickness AddRectangleToStackPanel( new StrokeDecorator(baseRect, chartreuseBrush, randomNumber.Next(10)), "Stroke Decorator adding a chartreuse stroke of random thickness" ); // The base component interface through the Fill Decorator // with a random fill color AddRectangleToStackPanel( new FillDecorator(baseRect, RandomColorBrush()), "Fill Decorator adding a random fill color" ); // The base component interface // through the Stroke Decorator with a random stroke of random thickness // through the Fill Decorator with a random fill color AddRectangleToStackPanel( new FillDecorator(new StrokeDecorator(baseRect, RandomColorBrush(), randomNumber.Next(10)), RandomColorBrush()), "Stroke Decorator with random color of random thickness, passed through Fill Decorator with random fill color" ); // The base component // through the Fill Decorator with a random fill color // through the Stroke Decorator with a random stroke of random thickness FillDecorator fillDecorator = new FillDecorator(new BaseRectangle(), RandomColorBrush()); AddRectangleToStackPanel( new StrokeDecorator(fillDecorator, RandomColorBrush(), randomNumber.Next(10)), "Explicitely initiated Fill Decorator with random fill color, passed through Stroke Decorator with random color and random thickness" ); // The base component interface // through the Stroke Decorator // with a random stroke color and stroke thickness of 5 AddRectangleToStackPanel( new StrokeDecorator(baseRect, RandomColorBrush(), 5), "" ); }
public static Rectangle GetWithBaseRectangle(BaseRectangle baseRectangle) { return(new Rectangle(baseRectangle.TopLeft, baseRectangle.Width, baseRectangle.Height)); }