A query condition interface with the C # language to expand and unwind features _c# tutorial

Source: Internet
Author: User

First of all, a simple application scenario, there is a C # client query interface, the above placed query conditions, the bottom of the query results. Because of the fact that the query condition may take up several rows, you want to leave the main query criteria on the screen by default, and have an expand/close feature on the right.

When the interface is closed:

Expansion-time Interface:

The first way I implemented this is to place a linklabel on the interface, set the mouse click event for this LinkLabel, and adjust the height property of the panel where the query condition is located.

The C # code is as follows:

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
namespace satyrandnymph {public partial class Formmethod1:form {//Close up State when panel height Private const int heightwhenfold = 50;
LinkLabel display text Private const string descriptionwhenfold = "Expand" When the state is closed;
Panel height Private const int Heightwhenexpand = 85 in expanded state;
LinkLabel display text Private const string Descriptionwhenexpand = "Close Up" when expanding state; <summary>///Form Constructor///</summary> public FormMethod1 () {InitializeComponent ();//constructor to adjust the panel to a closed state ln
Kcontrolheight.text = Descriptionwhenfold;
Pnlqueryconds.height = Heightwhenfold; ///<summary>///LinkLabel Click event///</summary>///<param name= "sender" ></param>///<param N
Ame= "E" ></param> private void Lnkcontrolheight_linkclicked (object sender, LinkLabelLinkClickedEventArgs e) { Adjusts the height of the panel and LinkLabel display text according to the display text as expanded/closed (lnkcontrOlheight.text = = descriptionwhenfold) {lnkcontrolheight.text = Descriptionwhenexpand; pnlqueryconds.height =
Heightwhenexpand;
else if (Lnkcontrolheight.text = = Descriptionwhenexpand) {lnkcontrolheight.text = Descriptionwhenfold;
Pnlqueryconds.height = Heightwhenfold; }
}
}
}

But I don't think it's perfect: each time you use it, you need to create a linklabel, and the code for each page is different, because the identifier for the parent container is different.

To address these two issues, I designed a custom control to facilitate subsequent development efforts.

The control is named Heightcontroller, and the interface is as follows:

The custom control contains only one Linklabel,autosize property that is set to the False,dock property is set to the Full,textalign property is set to Middleleft.

The C # code is as follows:

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Drawing;
Using System.Data;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms; namespace satyrandnymph {///<summary>///expand/Close Controller///</summary> public partial class Heightcontroller:us Ercontrol {///<summary>///expand/Close Controller///</summary> public Heightcontroller () {InitializeComponent ();} pri vate void Heightcontroller_load (object sender, EventArgs e) {//Designer mode does not trigger expansion/collection, or it can cause interference to the design work if (!this. DesignMode) {//Adjust expansion/collection if (Controllerstatus = = Controllerstatusenum.fold) {FOLD ();} else if (Controllerstatus = = Cont
Rollerstatusenum.expand) {EXPAND ();}} }///<summary>///controller status///</summary> private Controllerstatusenum _controllerstatus = Controllerstatusenu
M.fold; <summary>///Controller Status///</summary> [System.ComponentModel.Description ("Controller State")] public Controllerstatusenum Controllerstatus {get {return _controllerstatus;} sET {_controllerstatus = value;}}
<summary>///Parent Container expand///</summary> public void Expand () {controllerstatus = Controllerstatusenum.expand; if (this. Parent!= null) {this.
Parent.height = Heightwhenexpand;
} this.lnkHeightController.Text = Descriptionwhenexpand;  The///<summary>///parent container is closed///</summary> public void Fold () {controllerstatus = Controllerstatusenum.fold; if (This. Parent!= null) {this.
Parent.height = Heightwhenfold;
} this.lnkHeightController.Text = Descriptionwhenfold;
}///<summary>///height///</summary> private int _heightwhenfold = 50;
<summary>///height///</summary> [defaultvalue] [System.ComponentModel.Description ("lifting height")] public int Heightwhenfold {get {_heightwhenfold;} set {_heightwhenfold = value;}}///<summary>///is closed
Display text///</summary> private String _descriptionwhenfold = "expand"; <summary>///display text///</summary> [System.ComponentModel.Description ("CollectShow text ")] public string Descriptionwhenfold {get {return _descriptionwhenfold;} set {_descriptionwhenfold = value;}}
<summary>///when expanded///</summary> private int _heightwhenexpand = 85;
<summary>///height///</summary> [defaultvalue] [System.ComponentModel.Description ("expand height")] public int Heightwhenexpand {get {_heightwhenexpand;} set {_heightwhenexpand = value;}}///<summary>/
Display text///</summary> private string _descriptionwhenexpand = "Close Up" when expanded; <summary>///display text///</summary> [System.ComponentModel.Description (Show text when expanded)] public string Descriptionwhenexpand {get {return _descriptionwhenexpand;} set {_descriptionwhenexpand = value;}}///&LT;SUMMARY&G
T Click LinkLabel text///</summary>///<param name= "sender" ></param>///<param name= "E" ></ param> private void Lnkheightcontroller_linkclicked (object sender, LinkLabelLinkClickedEventArgs e) {if (this. Parent!=NULL) {int height = this.
Parent.height;
Determines whether the parent container should be closed or expanded if (Controllerstatus = = Controllerstatusenum.fold) {Expand ()} or else {FOLD ()}}, depending on the height of the parent container. }
}
}

When you use this control, drag the control directly into the panel or other container where you want to change the height.

You need to set the following 5 items in the control's properties before use:

The attributes are described below:

1, Controllerstatus, is an enumeration that contains expand and fold two choices that determine whether the query condition is expanded or closed when the form is opened.

2, Descriptionwhenexpand, when the query condition area is in the expanded state, the controller display text

3, Descriptionwhenfold, when the query condition area is in a closed state, the controller display text

4, Heightwhenexpand, query condition area in the expanded state height

5, Heightwhenfold, the query condition area is in a closed state when the height

The Heightcontroller control uses the following effects:

When the interface is closed:

Expansion-time Interface:

Demo Program Download Address:

Link: http://pan.baidu.com/s/1jHSvVee Password: QFP7

The above is a small set to introduce the use of C # language to implement the query conditions of the interface to expand and resume the function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.