Using the first WP program in C #

Source: Internet
Author: User

Today we use C # to complete the first Hello World program, but to make the program look less monotonous, the code for automatic discoloration is added.

First, let's put out the program.

When you click Start, Hello World will automatically change color.

It's easier to use here.

The main point of knowledge is the use of delegates.

Throughout the discoloration process, it is not possible to do so in the UI thread, which blocks the UI thread, causing the lag, which is not the effect we want, and we should use the delegate to do

Paste the code below

 //Delegate Objectdelegatetest Delegateobject; Delegate voidDelegateTest (inti); /// <summary>        ///button click event/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidButton_Click (Objectsender, RoutedEventArgs e) {Delegateobject=SetColor; Thread Thread=NewThread (Changecolorthread); Thread.          Start (); }        /// <summary>        ///Modify a color thread/// </summary>         Public voidChangecolorthread () { for(inti =0; I < -; i++)            {                //Invoke Delegate                 This.                Dispatcher.begininvoke (Delegateobject, i); //change once in a secondThread.Sleep ( +); }        }         Public voidSetColor (inti) {Random R=NewRandom (); //take a random number            intCol = R.next (0,5); //call method to update different colors based on different numbersTitle.foreground =NewSolidColorBrush (Getcolorvalue (col)); }         Public voidUpdateColor () {//Cycle 100 times             for(inti =0; I < -; i++)            {                 This.                Dispatcher.begininvoke (Delegateobject, i); Thread.Sleep ( +); //Sleep 1 seconds            }        }        /// <summary>        ///This method can be used to get the color/// </summary>        /// <param name= "i" ></param>        /// <returns></returns>         PublicSystem.Windows.Media.Color Getcolorvalue (inti) {Switch(i) { Case 0:                    returnColors.blue;  Case 1:                    returnColors.brown;  Case 2:                    returnColors.cyan;  Case 3:                    returnColors.green;  Case 4:                    returncolors.red; default:                    returnColors.orange; }                     }

Detailed code has been posted two, the content is relatively simple, I personally like to use C # to do development, because C # development speed, VS is known as the universe's first IDE, has a powerful function, can let developers have higher development speed.

Using the first WP program in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.