Winform Enterprise Application Framework Design [3] framework form design; dynamic creation menu;

Source: Internet
Author: User

If it weren't for my friend Joe = Joe doesn't die, I 'd like to talk about the domain-driven design ~

I will not find the first false statement about "congested entities" (at least ~ I writeArticleTime ~ My thoughts are wrong ~)

I personally do not like domain-driven design very much ~ I feel this kind of thinking (we will call it the idea for the time being ~ Although it has some existing principles and patterns)

Architects are required to go deep into the business field ~

However, it is often difficult to have in-depth exchanges with experts in the field in China ~

Domain Models and aggregation by architects are often different from actual situations ~

Even if the Division is good ~ New Businesses and changing businesses are also a headache for designers ~

In addition

It is difficult for designers to abstract a large and complex business into a domain model.

More complex models are often required to model real businesses.

-----------

Xuefly: add more content ~ Okay ~ More (more ?)~

Many of my friends, such as benfang's chest hair, are interested in the source code ~

I think you are all moles ~ This is not mature yet ~ Let's get it done ~ What do you mean ~

In the next chapter, I plan to write "Logon, pop-up screen, client data cache, and WCF security verification"

(TheseCodeNo shadow)

----------------------

Question 1: about debugging

If you are following my chapters for exercises ~

Then you may encounter a single-step debugging process from the client to the WCF end.

My WCF is a virtual directory of iis7.5 that is used directly.

A message is displayed before you step into the WCF.

Click [append] to debug it ~

Question 2: incomplete creation of dynamic WCF services

In the first article of this series, we used a large number of servicefactory to create services. This is not good.

I modified the code.

Please see here: http://www.cnblogs.com/liulun/archive/2011/11/29/2268337.html

 

Okay! Back to business

I. frame form

First look at the image

There are only four panels in charge of the frame form layout;

Top, bottom, left, right. (Extjs people prefer to say "East", "South", "West", and "North )-_-!

The top panel is used to store top menus)

The bottom panel is used to store status information and system versions.

The panel on the left is divided into two panels.

The above is the sub menu header.

Below is the sub menu

After you click a top menu, all the sub menus under the top menu appear in the sub menu.

Sub menu header is the name of the top menu.

(Because our top menu is not selected, a sub menu header is created here to let the user know which top menu he clicked, And the sub menu is selected)

The panel on the right is also divided into two panels

Above is tabs

Below is the child form

Tabs is used to store the title of the business form opened by the user. When the user clicks a tab, the form is activated (displayed in child form)

Child form is the business form currently being operated

(Examples are easy to understand)

There is a splitter in the middle of the left and right panel.

This splitter can be dragged to change the width of the left and right panel.

Note that

Drag the left panel into the form and set the dock left,

Drag another splitter into the form. It is a natural dock left,

Drag the panel on the right to the form and set the Dock Fill.

In this way, the splitter will work.

How to drag other panels to this form ~ I won't talk much about it.

Ii. dynamically create top menus

In the previous chapter, we successfully accessed WCF and obtained all the menus.

Now we are going to display the menu on the interface.

 
Private void mainform_load (Object sender, eventargs e) {If (! Utils. isindesignmode () {initmenu ();}}

Isindesignmode is used to determine whether the current form is in the design status.

(The design status will execute some code ~ If not ~ The form cannot be designed)

The Code is as follows ~

/// <Summary> /// determine whether the design status is correct /// </Summary> /// <returns> </returns> Public static bool isindesignmode () {bool returnflag = false; # If debug if (system. componentmodel. licensemanager. usagemode = system. componentmodel. licenseusagemode. designtime) {returnflag = true;} else if (system. diagnostics. process. getcurrentprocess (). processname. toupper (). equals ("devenv") {returnflag = true ;}# endif return returnflag ;}

Because menu creation ~ And response menu click events require a lot of code

We put these menu-related codes in a single partial class.

/// <Summary> /// menu cache /// </Summary> public list <menumodel> menus; /// <summary> /// initialization menu /// </Summary> private void initmenu () {preparemenus (); createtopmenu ();} /// <summary> /// obtain all menus from WCF /// </Summary> private void preparemenus () {var factory = new common. clientfactory <imenu> (); try {var client = factory. createclient (); menus = client. getallmenu ();} catch (exception ex) {utils. onexception (Ex);} factory. dispose ();}

As you can see ~ I have made some modifications to the preparemenus written in the previous chapter ~ These modifications serve the next chapter ~ Do not talk about it now

First look at createtopmenu

/// <Summary> /// create the top menu /// </Summary> private void createtopmenu () {var tmms = (from V in menus where v. parentid = guid. empty orderby v. ordernum select V ). tolist (); For (VAR I = 0; I <tmms. count; I ++) {var CTL = createonetopmenu (tmms [I], I); topmenup. controls. add (CTL );}} /// <summary> /// create a top menu /// </Summary> /// <Param name = "M"> </param> /// <Param name = "Index"> </param> // <returns> </returns> private control createonetopmenu (menumodel m, int index) {var TM = new label (); TM. width = 68; TM. height = 40; TM. TEXT = m. menuname; TM. textalign = contentalignment. middlecenter; TM. backcolor = color. transparent; TM. left = Index * 68 + Index * 12 + 12; TM. top = 9; TM. cursor = cursors. hand; TM. tag = m; TM. mouseenter + = new eventhandler (tm_mouseenter); TM. mouseleave + = new eventhandler (tm_mouseleave); TM. mouseup + = new mouseeventhandler (tm_mouseup); Return TM ;}

Yes! The top menu is a label!

After these labels are created, they are all placed in the topmenup panel.

This panel is the top panel.

TM. Left = Index * 68 + Index * 12 + 12;

The role of this sentence is to arrange these top-level menus in sequence ~ Avoid overwriting ~

In addition, I assigned the menumodel instance to the tag attribute of this label ~ Useful later

I have registered the same mouse, draw, and bullet events for these labels.

Now let's look at these events.

/// <Summary> /// move the mouse out of the top menu /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> void tm_mouseleave (Object sender, eventargs e) {var lB = sender as label; lb. backcolor = color. transparent; lb. forecolor = systemcolors. controltext ;} /// <summary> /// move the mouse over the top menu /// </Summary> /// <Param name = "sender"> </param> // <Param name = "E"> </param> void tm_mouseenter (Object sender, eventargs e) {var lB = sender as label; lb. backcolor = color. fromargb (INT) (byte) (77), (INT) (byte) (96), (INT) (byte) (130); lb. forecolor = color. white ;} /// <summary> /// the top menu is displayed with the mouse. /// </Summary> /// <Param name = "sender"> </param> // <Param name = "E"> </param> void tm_mouseup (Object sender, mouseeventargs e) {var lB = sender as label; var M = LB. tag as menumodel; createsubmenu (m );}

There is nothing special about the top menu to draw and draw

It only changes the background color and text color of the label.

Note: values of these colors ~ Should be put in the resource or cache ~

Hover the mouse over the event ~ This indicates that the customer clicked this lable.

We convert the tag attribute to menumodel.

Then, create a sub-menu.

3. dynamically create sub-menus

The Code is as follows:

/// <Summary> /// create a sub-menu /// </Summary> /// <Param name = "TM"> </param> private void createsubmenu (menumodel TM) {subheaderlb. TEXT = TM. menuname; submenup. controls. clear (); var smms = (from V in menus where v. parentid = TM. id orderby v. ordernum select V ). tolist (); For (VAR I = 0; I <smms. count; I ++) {var CTL = createonesubmenu (smms [I], I); submenup. controls. add (CTL );}} /// <summary> /// create a sub-menu /// </Summary> /// <Param name = "M"> </param> /// <Param name = "Index"> </param> // <returns> </returns> private control createonesubmenu (menumodel m, int index) {var Sm = new label (); SM. width = subheaderlb. width; SM. height = 27; SM. TEXT = m. menuname; SM. textalign = contentalignment. middlecenter; SM. backcolor = color. transparent; SM. top = Index * 27 + Index * 9 + 9; SM. left = 0; SM. anchor = (system. windows. forms. anchorstyles) (anchorstyles. top | anchorstyles. left | anchorstyles. right); SM. cursor = cursors. hand; SM. tag = m; SM. mouseenter + = new eventhandler (sm_mouseenter); SM. mouseleave + = new eventhandler (sm_mouseleave); SM. mouseup + = new mouseeventhandler (sm_mouseup); Return Sm ;}

Create Sub-menu and create top menu ~ The principle is the same.

Label is also used

SM. Anchor = (system. Windows. Forms. anchorstyles) (anchorstyles. Top | anchorstyles. Left | anchorstyles. Right );

The width of the menu varies according to the width of the left panel.

At the same time, you have registered the slide, slide, and bounce events for the mouse.

A pop-up event is an event where we dynamically create a business form.

In the next section, we will introduce

The code for sliding in and out is as follows:

/// <Summary> /// the sub-menu slides out /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> void sm_mouseleave (Object sender, eventargs e) {var lB = sender as label; lb. backcolor = color. transparent ;} /// <summary> /// submenu slides in /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> void sm_mouseenter (Object sender, eventargs e) {var lB = sender as label; lb. backcolor = systemcolors. info ;}

Strongly demanded again

Friends who like this article or who like me ~ Click to recommend ~ Click to recommend ~ Click to recommend ~ Click to recommend ~

 

 

 

 

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.