单列
来源:互联网 发布:喜扑传奇翅膀升级数据 编辑:程序博客网 时间:2024/06/05 19:42
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_0100单例
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
Person p = Person.getInstance();
Person p2 = Person.getInstance();
MessageBox.Show((p == p2).ToString());
//让dgv可以整行选中
dgvList.SelectionMode=DataGridViewSelectionMode.FullRowSelect;
dgvList.ReadOnly = true;
//让dgv和右键菜单
dgvList.ContextMenuStrip = cmsList;
LoadData();
BindData();
}
private void BindData()
{
dgvList.DataSource = list;
}
List<Song> list = new List<Song>();
string leftPath = "C:\\song\\";
private void LoadData()
{
Song song1 = new Song();
song1.SongName = "不要太早遇到对的人 柠檬";
song1.SongPath = "不要太早遇到对的人 柠檬.mp3";
Song song2 = new Song();
song2.SongName = "妈妈";
song2.SongPath = "妈妈.mp3";
Song song3 = new Song();
song3.SongName = "所谓朋友";
song3.SongPath = "所谓朋友.mp3";
list.Add(song1);
list.Add(song2);
list.Add(song3);
}
private void 播放ToolStripMenuItem_Click(object sender, EventArgs e)
{
string rightPath = dgvList.SelectedRows[0].Cells[1].Value.ToString();
string fullPath = leftPath + rightPath;
Play p = Play.getInstance();
p.path = fullPath;
p.pp();
p.Show();
}
}
}
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Day10_0100单例
{
public partial class Play : Form
{
private Play()
{
InitializeComponent();
}
private static Play play=new Play();
public static Play getInstance()
{
return play;
}
public string path;
private void Play_Load(object sender, EventArgs e)
{
}
public void pp()
{
Player1.URL = path;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Day10_0100单例
{
public class Song
{
public string SongName { get; set; }
public string SongPath { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Day10_0100单例
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day10_0100单例
{
public class Person
{
//1.构造私有
private Person()
{
}
//饿汉模式 单例
// static Person p = new Person();
private static Person p;//懒汉模式
//2.共有方法
public static Person getInstance()
{
if (p==null)
{
p=new Person();
}
return p;
}
}
}
- 单列
- 单列
- 单列模式
- 单列模式
- 单列模式
- 单列模式
- 单列模式
- 单列模式
- 释放单列
- 单列模式
- 单列模式
- 单列模式
- 单列模式
- 单列模式
- 单列索引
- 单列模式
- 单列模式
- 单列模式
- C++调用Python浅析
- 读书笔记 effective c++ Item 25 实现一个不抛出异常的swap
- 2014年北京Itcast-IOS4期视频教程
- 打开word2010出现进度条的解决办法
- Codeforces Round #403 (Div. 2)B. The Meeting Place Cannot Be Changed
- 单列
- delphi ini文件的基础读写。
- css之vertical-align
- Thread线程-创建线程的3种方式
- MongoDB Java 笔记
- php网页模板设计
- iBET Sport Books Rebate 0.35% Bonus
- 转发和重定向的区别(简单解释)
- STM32F4修改晶振频率