دورد
من یک مدیا پلیر با یک لیست باکس ساختم
داخل لیست باکس اسم چندتا فیلم هست
بعد می خوام مثلا داخل لیست باکس روی دشنه که کلیک می کنی مدیا پلیر فیلم دشنه رو نشون بده
اگه کسی میدونه کدش چی هست ممنون میشم راهنمایی کنه
Printable View
دورد
من یک مدیا پلیر با یک لیست باکس ساختم
داخل لیست باکس اسم چندتا فیلم هست
بعد می خوام مثلا داخل لیست باکس روی دشنه که کلیک می کنی مدیا پلیر فیلم دشنه رو نشون بده
اگه کسی میدونه کدش چی هست ممنون میشم راهنمایی کنه
باید فیلم رو جایی داشته باشی و با استفاده از ایندکس های لیست باکست یه if , else بنویسی و تو هر if مربوطه ادرس فیلمت رو بدی .
ببینید من این کد رو مینویسم داخل دکمه ولی هیچ عملی انجام نمیده
string str;
str=listBox1.Items
[listBox1.SelectedIndex].ToString();
switch(str)
{
case "Deshneh":
wmp.URL="F:\The Secret\TheSecret2.wmv"
break;
}
نمیدونم منظورت رو دقیق متوجه شدم یا نه، کد زیر رو امتحان کن ببین به کارت میاد؟ (در مورد همون مثال بالا)
System.Diagnostics.Process.Start("wmplayer.exe", "F:\\The Secret\\TheSecret2.wmv");
فکر کنم اگه برنامت رو بذاری دوستان راحت تر بتونن راهنماییت بکنننقل قول:
می خوام داخل لیست باکس رو اسامی هر فیلمی که کلیک کنی مدیا پلیر پخش کنه یعنی داخل خود برنامه نه اینکه ویندوز مدیا پلیر رو باز کنه
کد شما درسته به شرطی که از دو تا / استفاده کنی و اونو داخل رویداد SelectedIndexChanged مربوط به ListBox بنویسی:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string str;
str=listBox1.Items[listBox1.SelectedIndex].ToString();
switch(str)
{
case "s":
wmp.URL="D:\\My Film\\s.wmv";
break;
case "o":
wmp.URL = "D:\\My Film\\o.wmv";
break;
case "E":
wmp.URL = "D:\\My Film\\E.wmv";
break;
case "E1":
wmp.URL = "D:\\My Film\\E1.wmv";
break;
case "M":
wmp.URL = "D:\\My Film\\M.wmv";
break;
}
}
واقعا ممنونم درست شد
فقط یه سوال دیگه البته ببخشید
داخل treeview باید چجوری بنویسم چون با treeview کار نکردم یه خورده مشکله واسم
privatevoid treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string strFilmName;
string strFilmDirectory;
strFilmName=treeView1.SelectedNode.Text;
strFilmDirectory = treeView1.SelectedNode.Parent.Text;
wmp.URL = "D:\\" + strFilmDirectory + "\\" + strFilmName + ".wmv";
}
ضمیمه 68481
ممنون ولی اگه میشه یکم بیشتر توضیح بدین آخه من می خوام از طریق switch case اضافه کنم
شرمنده اینهمه سوال می کنم آخه من تازه دارم با C# کار می کنم مخصوصا TreeView واسه همین واسم مشکله
{
string strFilmName;
string strFilmDirectory;
strFilmName=treeView1.SelectedNode.Text;
strFilmDirectory = treeView1.SelectedNode.Parent.Text;
wmp.URL = "D:\\" + strFilmDirectory + "\\" + strFilmName + ".wmv";
}
privatevoid treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string str;
str = treeView1.SelectedNode.Text;
switch (str)
{
case"s":
wmp.URL = "d:\\My Film\\s.wmv";
break;
case"o":
wmp.URL = "d:\\My Film\\o.wmv";
break;
case"E":
wmp.URL = "d:\\My Film\\E.wmv";
break;
case"E1":
wmp.URL = "d:\\My Film\\E1.wmv";
break;
case"M":
wmp.URL = "d:\\My Film\\M.avi";
break;
}
}
واقعا ممنونم
درست شد