Single Column, Singleton Mode
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Runtime. Remoting. Services;
Using System. Text;
Using System. Text. RegularExpressions;
Using System. Threading. Tasks;
Using System. Windows. Forms;
Namespace Day10_0200 Singleton
{
Public partial class FrmPlay: Form
{
Public static FrmPlay OnlyOneForm;
// 1. construct private
Private FrmPlay ()
{
InitializeComponent ();
}
Public string path;
Private void FrmPlay_Load (object sender, EventArgs e)
{
}
Public void PlaySong ()
{
Player1.URL = path;
}
// Static method
Public static FrmPlay GetInstance ()
{
If (OnlyOneForm = null)
{
OnlyOneForm = new FrmPlay ();
Return OnlyOneForm;
}
Else
{
Return OnlyOneForm;
}
}
}
}
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;
Using System. Windows. Forms;
Namespace Day10_0200 Singleton
{
Public partial class FrmList: Form
{
Public FrmList ()
{
InitializeComponent ();
}
Private void FrmList_Load (object sender, EventArgs e)
{
// Select the entire row
DgvList. SelectionMode = maid mode. FullRowSelect;
// Bind dgv and ContextMenuStrip
DgvList. ContextMenuStrip = cms_list;
List <Song> list = new List <Song> ();
Song s1 = new Song ("001", "Beijing", "D :\\ song \ .mp3 .mp3 ");
Song s2 = new Song ("002", "Beijing", "D :\\ song \ Wu yuyun-life Tree ");
Song s3 = new Song ("003", "Beijing", "D :\\ song \ battle Changsha-Beijing music-pure music version ");
List. Add (s1 );
List. Add (s2 );
List. Add (s3 );
DgvList. DataSource = list;
}
Private void play ToolStripMenuItem_Click (object sender, EventArgs e)
{
FrmPlay frm = FrmPlay. GetInstance ();
Frm. path = dgvList. SelectedRows [0]. Cells [2]. Value. ToString ();
Frm. Show ();
Frm. PlaySong ();
}
}
}