WM has about (4): Processing screen Rotation

Source: Internet
Author: User

WM has about (4): Processing screen Rotation

 

Written by Allen Lee

 

If the user rotates the screen ......

First, run the application.Program:

Figure 1

Then, rotate the screen:

Figure 2

Oh, "next time" is congested, and the screen also shows a scroll bar. However, there are still many blank areas on the screen that are not used. What should I do?

 

Controls supporting screen Rotation

Previously, patterns & pactices provided a mobile client software factory with an orientationaware control to help us deal with this situation. Clarius Consulting now provides an orientation aware control component specifically designed to address this problem. Next we will discuss how to use Community edition to solve this problem.

After the orientation aware control component is installed, an orientation aware control is displayed in the Add new item dialog box:

Figure 3

Select this item, give it a name, and click Add. You will get a blank control design interface. Copy the monthcalendar control and two label controls on homeform to homecontrol, adjust their positions to center them:

Figure 4

Right-click the blank area of the Control and select rotate:

Figure 5

The control design interface will be rotated:

Figure 6

The figure after running is actually figure 2. Now let's re-adjust the items on the control:

Figure 7

It should be noted that the size of the control is set to the same as that of homeform, and the vertical and horizontal correspond respectively. Then, rotate the control back, add it to homeform, and set its dock attribute to fill:

Figure 8

Alas, it's a little unsightly. I don't know if it works like this? Okay. Let's take a look:

Figure 9

Figure 10

Well, the processing is pretty good, although the scroll bar still appears in the landscape screen. Note: currently, homecontrol is only an empty shell, so all functions previously implemented will not work on it. Of course, this includes "next time", but it will not be displayed.

 

Put the business logicCodeSeparated

Currently, the user interface code and the business logic code are entangled, homeform. the code in CS is more than four hundred lines, which will undoubtedly cause problems for future maintenance (although I am not planning to maintain this demonstration program, I 'd like to talk about it, haha, next, we will try to separate the user interface code into homecontrol, and the business logic code will create a new datemanager class for storage.

The datemanager class will be responsible for date access, file management, and prediction logic, while homecontrol will be responsible for Dingding date updates, "Next" updates, and obtaining the date selected by the user on monthcalendar.

First, file management, homeform. methods such as initializefile, getpinneddatesfilepath, getexcludeddatesfilepath, getincludeddatesfilepath, and getfilepath in CS can be directly copied to the datemanager class. initializefile is called in the constructor of the DATEM, to create a file to store the date.

Next is the date access, homeform. in CS, methods such as loaddates, savedates, loadpinneddates, packages, loadincludeddates, saveincludeddates, volumes, and volumes can be directly copied to the datemanager class. However, since the datemanager class is user interface neutral, therefore, you need to provide the load and save methods for calling related forms/controls:

Code 1

The last is the "Next" prediction, homeform. the calculatenexttime, calculatenextsaturday, applysion Sion, applyexclusion, and applyadjustment methods in CS can be directly copied to the datemanager class. In addition, we need to convert the calculatenexttime method into a public method so that homecontrol.

Slow down! How do I add a date? Oh, I almost forgot ~~~ We know that datemanager does not need to worry about whether you are adding a weekend. Its task is to add a set of dates you have given it to the corresponding set, so we can implement the pin, include, and exclude methods in this way:

Code 2

Wait! How can I get the pinned date to be displayed on monthcalendar? You only need to provide a pinneddates attribute:

Code 3

 

Separate user interface code

We know that homecontrol is responsible for displaying the pinned date, updating "Next", and sending a notification when the user selects the date. For the first two, we only need to provide two attributes:

Code 4

For the subsequent responsibilities, we need to provide a selecteddateschanged event, which will add the judgment logic for the weekend Based on the datechanged event of the monthcalendar control. To implement this event, we need to create a selecteddateseventargs class:

Code 5

The calculateweekend and calculaterange methods are directly copied from homeform. CS. With these preparations, we can start to implement the selecteddateschanged event:

Code 6

What's worse? By the way, it is the configuration information settings. Copy the setupoptions method in homeform. CS and change it to a public method.

Finally, we started to sort out homeform. CS. First, when the application starts, we need to set the homecontrol configuration information and call the load method of datemanager:

Code 7

When the Deactivate event of the main form is triggered and you click the Save menu item, call the Save method of datemanager:

Code 8

When the activated event of the main form is triggered, the "Next" on homecontrol is updated ":

Code 9

When you modify the configuration information through optionform, call the setupoptions method of homecontrol to read the configuration information:

Code 10

When you make a choice on monthcalendar in homecontrol, we will save the date selected by the user to a private variable, then, set the Enable attribute of the pin, include, and exclude menu items based on the arepast attribute of selecteddateseventargs:

Code 11

When you click the pin, include, and exclude menu items, the corresponding datemanager method is called for processing:

Code 12

Finally, other codes in homeform. CS, including the auxiliary methods and controls on the original user interface, must be deleted.

Now, it's time to run the application and see if it has been changed:

Figure 11

Oh, the dingtalk date is not displayed! No problem. You only need to assign the value of the pinneddates attribute of datemanager to the datasource attribute of homecontrol when the activated event of the main form is triggered and the user clicks the pin menu item. Run the application again and it will be normal this time (strange, why is there an extra scroll bar in Figure 10? Is it because the original controls on the form have not been deleted before ?) :

Figure 12

Figure 13

 

What else do you want?

I still want to try data binding, but it does not seem necessary now. At present, this application can basically be applied, so the next step is how to deploy it on the device. Next, we will explore how to develop an installation package for this application.

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.