Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What controls in C# can achieve the same effect as QQ displaying friends?
What controls in C# can achieve the same effect as QQ displaying friends?
I will do a project similar to QQ. It's a third-party control that needs to be downloaded, but it's not in VS. It's called sidebar. After downloading, the first step is to add the control to the toolbox. Add a tab to the toolbox, right-click, add an item, and then select the DLL file you just downloaded.

The following are the properties of the control.

ImageList This is bound to the ImageList control, and the serial number of ImageList is directly used when displaying the avatar.

Right-click menu of ItemContextMenuStrip subitem

Viw display style

The sidebar has groups before members, so you need to add several groups and methods to the sidebar.

Sidebar. AddGroup ("this is the name of the group")

After you have a group, you should add members and methods to it.

Sidebar 1.groups [I]. Items.add ("member name",12); The following 12 is the serial number of the picture bound by this member (avatar, with a picture avatar like QQ in front).

Right-click the subproject to display the menu. Like ListView, sideBar also has the function of HitTest, but it is very different to use, and can be realized as follows:

Point p = sidewalk1. PointToClient(mouse position);

if (e.Button == MouseButtons。 Right)

{

if (sideBar 1。 SeletedItem! = null & amp& ampsideBar 1。 SeletedItem.HitTest (p.X,p.Y) == true)

{

contextMenuStrip 1。 Display (mouse position);

}

}

This will complete the sidebar setup.

- .

Application and related design of sidebar control in MyQQ

First, import a package using Aptech. UI;

In the loading event of the form:

Private void frmMain_Load (object sender, EventArgs e)

{

//Call ShowPersonalInfo () method to display personal avatar information.

ShowPersonalInfo();

//Divide into three groups in the sidebar control.

SbFriends。 Add group ("QQ friends");

SbFriends。 AddGroup ("stranger");

SbFriends。 Add group ("QQ group");

//Call the ShowFriendsList () method to display friends.

ShowFriendsList();

}

Of course, remember to drag an ImageList control into the form and rename it ilFaces (the sidebar is renamed sbfriends); Select ilFaces in the ImageList property of the sidebar. And import some. Ico file of ilFaces.

//User-defined ShowFriendList () method.

public void ShowFriendsList()

{

//Clear buddy group elements

sbFriends。 groups[0]. items . clear();

attempt

{

//Create a connection object

SqlConnection sqlConn = new SqlConnection(" server =。 ; Database = myqqtrusted _ connection = true ");

//Create a command object

SqlCommand sqlComm = new SqlCommand(" select NickName,FaceId,FriendId from Users,Friends where Friends。 HostId = "+RecordUserId.loginId+"and users. Id = friend. FriendId”,sqlConn);

sqlConn。 open();

//Execute the query command

SqlDataReader reader = sqlComm。 ExecuteReader();

And (readers. Read())

{

//instantiating the SbItem object requires a string and an integer seat parameter.

sb item item = new sb item((string)reader[" NickName "],(int)reader[" FaceId "]);

//Assign the searched friend account to the Tag tag of the item.

Project. tag =(int)reader[" FriendId "];

//Add the project object to the buddy group.

sbFriends。 groups[0]. items . add(item);

}

Readers. close();

//Close the connection

sqlConn。 close();

}

Catch (exception ex)

{

MessageBox。 Display (for example. Message);

}

}

The Tag tag of the item object is skillfully used here. How to get the data in the tag? Let's define a method to demonstrate the flexible application of data stored in tags:

//Judge whether it has been displayed as a friend.

private bool HasShowFriend(int friendId)

{

bool result = false

for(int I = 0; I<2; i++)

{

for(int j = 0; j & ltsbFriends。 groups[I]. items . count; j++)

{

If (conversion. ToInt32(sbFriends。 Group [i]. Item [j]. Tag) == friendId)

{

Result = true;

}

}

}

Return the result;

Hope useful to you