Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

C# WPF Beginner Here

$
0
0

Hey guys!

I got an exercise from my teacher which is: Write a program to draw a star. Let the user determine R, G and B values via text boxes so your program is able to draw the star in any color!

I have this code and it draws a star, but I don't know how to get the numbers from the TextBoxes to replace the R, G and B.

        public MainWindow()
        {
            InitializeComponent();

            Line myLine = new Line();
            myLine.Stroke = new SolidColorBrush(Color.FromRgb(r, g, b));
            myLine.StrokeThickness = 2;
            myLine.X1 = 200;
            myLine.Y1 = 1;
            myLine.X2 = 80;
            myLine.Y2 = 350;
            caPaper.Children.Add(myLine);

            Line mLine = new Line();
            mLine.Stroke = new SolidColorBrush(Color.FromRgb(r, g, b));
            mLine.StrokeThickness = 2;
            mLine.X1 = 200;
            mLine.Y1 = 1;
            mLine.X2 = 320;
            mLine.Y2 = 350;
            caPaper.Children.Add(mLine);

            Line vLine = new Line();
            vLine.Stroke = new SolidColorBrush(Color.FromRgb(r, g, b));
            vLine.StrokeThickness = 2;
            vLine.X1 = 1;
            vLine.Y1 = 120;
            vLine.X2 = 320;
            vLine.Y2 = 350;
            caPaper.Children.Add(vLine);

            Line bLine = new Line();
            bLine.Stroke = new SolidColorBrush(Color.FromRgb(r, g, b));
            bLine.StrokeThickness = 2;
            bLine.X1 = 399;
            bLine.Y1 = 120;
            bLine.X2 = 80;
            bLine.Y2 = 350;
            caPaper.Children.Add(bLine);

            Line nLine = new Line();
            nLine.Stroke = new SolidColorBrush(Color.FromRgb(r, g, b));
            nLine.StrokeThickness = 2;
            nLine.X1 = 1;
            nLine.Y1 = 120;
            nLine.X2 = 399;
            nLine.Y2 = 120;
            caPaper.Children.Add(nLine);


        }

        private void txtR_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void txtG_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void txtB_TextChanged(object sender, TextChangedEventArgs e)
        {
           
        }


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>