Easily produce imitation Outlook interface in C #
Lishui Auto Transport Group Co., Ltd. Information Center
I don't know when to start, many software began to imitate the Outlook interface, the most typical qq often used, I have been searching for a long time, I didn't find a few satisfying controls, simply, I wrote one, very Simple and practical, taken out to share.
New project, you may wish to name myoutlookface, put a Panel control to the container as a container, name: PANFUNMAIN, set the dock attribute to LEFT (or Righ), set the BorderStyle property to fixed3D, add an imagelist control, set it Imagesize is "32, 32" and add several icons to it.
Add N buttons to PANFUNMAIN (n = 3 in this example, which is used to display a few groups) and N ListView controls (showing specific content in a group), with its default name, pay attention to the number of ListView controls must be The number of buttons controls is the same, all of the LageList property of each ListView control, select the first listView control, select the first listView control, in the properties window, select Items, and click the little button on the right "
", A dialog will pop up, add a few members here, and specify the Text property and the ImageIndex property, the same, for the second, three listView specify the items member.
In order to achieve automatic hidden, add a timer, the last layout is as follows:
The above insert operation is basically basic, such as not special instructions, use its default value, and details are not described here.
In this article, the method of playing sound will be mentioned. To reasonable use of resources, the file output path must be modified, select the menu "Item" → "Properties", which will pop up the next dialog box, in "Configure (C)" Select All Configurations, then set the "Generation" item of Configuration Properties, fill in "Output /" in the output path on the right, so that whether it is compiled into a Release file or a debug file, the output executable file will Put it under the Output folder in the current project (this file will be created automatically).
At this point, the interface arrangement is basically completed, switched to the code window, add several variables:
///
/// Record the button used in the current function panel
/// summary>
Private arraylist arrfunbutton = new arraylist ();
///
/// Record the listView used in the current function panel
/// summary>
Private arraylist arrfunlistView = new arraylist ();
///
/// Functional panel width
/// summary>
PRIVATE INT M_NPANFUNWIDTH = 100;
// Width after the function panel hides
PRIVATE INT M_NPANFUNHIDEWIDTH = 2;
When we click on a button, you must display the listView corresponding to the button, and adjust the position of the button, so manually write a function:
// Function button Click the effects
Private void btnfun_click (object sender, system.eventargs e) {
Button btnnow = sender as button;
IF (btnnow == null)
Return;
/ / Click the button index in the array
Int nindex = this.Arrfunbutton.indexof (btnnow);
// Top the top of the button
For (INT i = 1; i <= nindex; i )
{
Button btn = arrfunbutton [i] as budton;
btn.top = ((Button) arrfunbutton [i-1]). Bottom;
Btn.ancy = system.windows.Forms.Anchorstyles.LINDOWS.FORMS.ANCHORSTYLES.TOP;
}
/ / Down the following button
For (int i = arrfunbutton.count-1; i> nindex; i -)
{
Button btn = arrfunbutton [i] as budton;
IF (i == arrfunbutton.count-1) // last one
btn.top = this.panfunmain.height-btn.Height-4;
Else
BTN.TOP = ((Button) arrfunbutton [i 1]). Top-btn.height;
Btn.anchor = system.windows.forms.Anchorstyles.Left | System.Windows.Forms.Anchorstyles.bottom;
}
// Display the corresponding listview
For (int i = 0; I { Listview LSV = ArrfunlistView [i] as listview; // Current button corresponding to ListView IF (i == nindex) { LSV.LEFT = 0; Lsv.width = btnnow.width; LSV.TOP = btnnow.bottom; IF (nindex == arrfunlistView.count-1) // last one Lsv.height = this.panfunmain.height-btnnow.bottom-4; Else Lsv.height = (arrfunbutton [i 1] as button) .top-btnnow.bottom // Display the current listView IF (! lsv.visible) Lsv.visible = true; } Else // Hide Other ListView { IF (lsv.visible) Lsv.visible = false; } } } When we double-click the ListView icon, the application will handle according to the specific item you double-click, such as the "Send Message" dialog box in QQ, we just simply prompt a sentence, which one you double click, for this It is also manually added a function: / / Double-click ListView and execute the operation according to the current item Private void LSVFUN_DOUBLECLICK (Object Sender, System.EventArgs E) { / / Double-click to execute a function Listview lsv = sender as listview; IF (LSV == NULL) Return; IF (lsw.selecteditems.count == 0) Return; ListviewItem item = lsv.selectedItems [0]; MessageBox.show ("You double click:" item.text); } In this example, the automatic hidden function is set, hidden (width npanfunhidewidth), if the mouse is moved on this toolbar (that is, all the contents in this example), the tool bar is displayed, therefore, manually add A mouse mobile event response function: Private Void FunlistView_mousemove (Object Sender, System.Windows E) { IF (this.panfunmain.width == m_npanfunhidewidth) { This.PanFunmain.width = m_npanfunwidth; THIS.TIMER1.ENABLED = TRUE; } } In order to reach an automatic hidden purpose, we set a memory that constantly detect the current mouse position. If it is not in the toolbar, set the tool broadband to npanfunhidewidth, it plays a hidden role, of course, cannot be set to 0, otherwise the mouse If you can't move it, you can't show it. Add the response code of the timer: Private void Timer1_Tick (Object Sender, System.EventArgs E) { // The current function panel is displayed IF (this.panfunmain.width == m_npanfunwidth) { / / Check if the cursor position is in the panel Point p1 = this.panfunmain.pointtoscreen (new point (0,0)); Point P2 = this.panfunmain.pointtoscreen (PanFunmain.right, Panfunmain.Bottom); Point pcur = Cursor.position; // Current mouse cursor location IF (pcur.x { // Hide PanFunmain This.PanFunmain.width = m_npanfunhidewidth; this.timer1.enabled = false; } } // if } The front is ready to work, add a function, combine the above code as a specific button and the listView control: /// /// Initialization Function Panel /// summary> Private vidinfun () { / / Set the position and broadband of the function panel This.PanFunmain.width = m_npanfunwidth; THIS.PANFUNMAIN.DOCK = DOCKSTYLE.LEFT; // Record the function button Arrfunbutton.add (this.button1); Arrfunbutton.Add (this.button2); Arrfunbutton.Add (this.button3); // Record the listView in the function panel, pay attention to the button above ArrfunlistView.Add (this.listview1); ArrfunlistView.Add (this.listview2); ArrfunlistView.Add (this.listview3); INT ncount = arrfunbutton.count; // Arrange the position of each function button and the attribute of ListView For (int i = ncount-1; i> = 0; I -) { Button btn = arrfunbutton [i] as budton; btn.width = this.panfunmain.width-4; btn.left = 0; // Click the button's clicked event and the specific code btn.click = new system.eventhandler (btnfun_click); IF (i == 0) { btn.top = 0; Btn.anchor = anchorstyles.left | anchorstyles.top; } Else { IF (i == ncount-1) btn.top = this.panfunmain.height-btn.Height-4; Else BTN.TOP = (Arrfunbutton [i 1] as button) .top-btn.height; Btn.anchor = anchorstyles.left | anchorstyles.bottom } // When the mouse moves on the button, it is also judged whether the current toolbar is hidden. btn.mousemove = new mouseeventhandler (funlistView_mousemove); // Set the AnchR property of ListView Listview LSV = ArrfunlistView [i] as listview; IF (LSV! = NULL) { Lsv.anchor = anchorstyles.left | anchorstyles.top | Anchorstyles.right | anchorstyles.bottom; // Hide Function ListView Lsv.visible = false; // Set the listView Double-click Event Lsv.doubleClick = New EventHandler (LSVFUN_DOUBLECLICK); Lsv.mousemove = new mouseeventhandler (funlistView_mousemove); } // pan } // for int I / / Put the first function button points (Arrfunbutton [0] as button) .PerformClick (); // Don't forget to open the scheduler THIS.TIMER1.ENABLED = TRUE; } Finally, add Form1's LOAD event response function to initialize the toolbar: Private Void Form1_Load (Object Sender, System.EventArgs E) { THIS.INITPANFUN (); } Now run, is the effect is very good? When you click the button, you will display different packets. When the mouse leaves the left side, the tool is automatically hidden. When you move on the left, the tool automatically appears. After you click on the ListView icon, you will pop up a dialog, tell you which one ,As shown below: By setting the PANFUNMAIN's Dock property, this toolbar can be made in the left or right of the window, and the versatility of the code in this case is strong (of course, if you can make a control better), it is easy to copy to new In the software, the above automatic hide is mimic QQ, we can also do more like QQ, when the user has a group of packet buttons, play a sound, if you have QQ, put it in the Sound folder under the installation path Folder.wav sound files Copy to the Output folder of this project (that is, this project EXE file output path), where the code of playing / stop sound is as follows: [DLLIMPORT ("Winmm.dll")] Public Static Extern long mcIndstring (String LPSTRCOMMAND, STRING LPSTRRETURnstring, long length, long hwndcallback); /// /// Play a music file /// summary> /// Music file name param> Private void playmusic (String p_filename) { Try { McISendstring (@ "close" p_filename, "" / * 34 space * /, 0, 0); McIndstring (@ "open" p_filename, "" / * 34 space * /, 0, 0); McIndString (@ "play" p_filename, "" / * 34 space * /, 0, 0); } Catch { } } /// /// Stop current music play /// summary> /// Music file name param> Private void stopmusic (String p_filename) { Try { McIndstring (@ "close" p_filename, "", 0, 0); } Catch {} Due to the use of the API function, don't forget to add an application in the front door: Using system.Runtime.InteropServices; Of course, in order to play the sound, add the following two sentences in the Private Void Btnfun_Click (Object Sender, System.EventArgs E): // Play the sound, because there may be space in the file path, therefore, the file should be generated with quotation marks. String strfilename = "/" " Application.startuppath " // folder.wav " " / "" This.Playmusic (StrfileName); Run again, is it more cool?