Mobile Development (List controls used)

Source: Internet
Author: User

This article mainly introduces a list control written by a foreign cool. I think it is often used in Mobile development, and we can modify it to what we need. As the Department has a new technical need for research, it is too late. Please forgive me.

Add the control code first, and then introduce the control usage in detail. Fontlist.zip

The Control is divided into two parts. The OwnerDrawnListBox inherits the Control and re-encapsulate the events and attributes, and then the FontListBox inherits the Control and reshapes the Control. Therefore, when using this control, please combine the painting background in the previous article, because the control also needs to use the painting background and image. Since there is a list page, there must be a lower-level menu. Therefore, the information stored in the list must not only the information displayed in the list, but must be supported by objects, do not forget to use it.

Here is a brief introduction to FontListBox.

Set the height of each row in the list, which is changed based on the font size.

This. ItemHeight = (int) (g. MeasureString ("template", new Font ("Tahoma", 12, FontStyle. Regular). Height * 2 );

Different icons are displayed based on the type of the object array. If you do not have this requirement, you can delete it, just draw the text. An icon is drawn here, and a title text is given to describe the content of the current list. You can draw it by yourself as needed.

Code
If (ParentType! = Null)
{
Switch (ParentType)
{
Case "Mesh ":
ParentType = "icon_06 ";
Break;
// Case "poloshirt ":
// ParentType = "t ";
// Break;
// Case "Pants ":
// ParentType = "k ";
// Break;
Default:
Break;
}
Bmp = AlphaImage. CreateFromFile (path + @ "\ Resources \" + ParentType + ". png ");
ImgIconRect = new Rectangle (DRAW_OFFSET + 3, itemTop + 2, 36, 35 );
Bmp. Draw (gOffScreen, imgIconRect );
GOffScreen. DrawString (MeshPicInfo) this. Items [n]). Title, font, new SolidBrush (fontColor), DRAW_OFFSET + 55, itemTop + 12 );
// GOffScreen. DrawString (InfoClass) this. Items [n]). Author, font, new SolidBrush (fontColor), this. Width-70, itemTop + 7 );
}
Else
{
GOffScreen. DrawString (MeshPicInfo) this. Items [n]). Title, font, new SolidBrush (fontColor), DRAW_OFFSET + 5, itemTop + 7 );
// GOffScreen. DrawString (InfoClass) this. Items [n]). Author, font, new SolidBrush (fontColor), this. Width-70, itemTop + 7 );
}

Replace the object name with your own object name.

The following describes how to load and refresh controls. Declare a global FontListBox object and list object in the corresponding form, and then load the control and delegate events.

Code
Private void FrmImageList_Load (object sender, EventArgs e)
{
Fb = new FontListBox ();
InitDataList ();

Fb. Dock = DockStyle. Fill;
Fb. SysColor = SystemColors. MenuText;
Fb. Parent = this;
// Fb. Focus ();
This. Controls. Add (fb );
Fb. Selected + = new SelItemInfo (fb_Selected );
Fb. MovedOn + = new SelItemInfo (fb_MovedOn );
}

Void fb_MovedOn (MeshPicInfo info, bool othSel)
{
Mesh = info;
}

Void fb_Selected (MeshPicInfo info, bool othSel)
{
Mesh = info;
FrmImageView frmImageView = new FrmImageView (mesh );
FrmImageView. Show ();
This. Hide ();
}

Initialization list:

Code
/// <Summary>
/// List Initialization
/// </Summary>
Private void InitDataList ()
{
// Obtain all objects
Fb. ParentType = "Mesh ";
MeshPicInfo [] all_file = Program. all_file;
If (! Directory. Exists (Program. _ SyncPath ))
{
Return;
}
String [] files = Directory. GetFiles (Program. _ SyncPath );

Foreach (MeshPicInfo picInfo in all_file)
{
Foreach (string str in files)
{
If (picInfo. Title = str. Substring (str. LastIndexOf (@ "\") + 1 ))
{
Fb. Items. Add (picInfo );
}
}
}
If (fb. Items. Count! = 0)
{
Fb. SelectedIndex = 0;
Mesh = (MeshPicInfo) fb. Items [fb. SelectedIndex];
}
}

After completing the preceding steps, the list is displayed in your form. This control supports both touch and keyboard operations. You can rewrite the event to double-click or right-click, the scroll bar is automatically displayed when the list is too long. In general, it is better. Finally, you need to pay attention to refreshing the list. You can only manually remove the control and re-load it, which is inefficient. You also need to find a way to improve it, as shown below:

 

Code
/// <Summary>
/// Refresh the list
/// </Summary>
Public void FBRefresh ()
{
This. Controls. Remove (fb );

Fb = new FontListBox ();
Fb. Dock = DockStyle. Fill;
Fb. SysColor = SystemColors. MenuText;
Fb. Parent = this;
Fb. Focus ();
This. Controls. Add (fb );
Fb. Selected + = new SelItemInfo (fb_Selected );
Fb. MovedOn + = new SelItemInfo (fb_MovedOn );
// Obtain all objects
Fb. ParentType = "Mesh ";
MeshPicInfo [] all_file = Program. all_file;
If (! Directory. Exists (Program. _ SyncPath ))
{
Return;
}
String [] files = Directory. GetFiles (Program. _ SyncPath );

Foreach (MeshPicInfo picInfo in all_file)
{
Foreach (string str in files)
{
If (picInfo. Title = str. Substring (str. LastIndexOf (@ "\") + 1 ))
{
Fb. Items. Add (picInfo );
}
}
}
If (fb. Items. Count! = 0)
{
Fb. SelectedIndex = 0;
Mesh = (MeshPicInfo) fb. Items [fb. SelectedIndex];
}
}

Finally, I would like to show several different list charts. I hope your software will become more practical and beautiful.

 

 

 

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.