本程序是关于一个简易的播放器。
这是初始化设计时的代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;namespace movie
{
public partial class Form1 : Form
{ string uu="0"; public Form1()
{
InitializeComponent();
RegistryKey xx = Registry.LocalMachine;
RegistryKey xx1 = xx.OpenSubKey("SOFTWARE", true);
string ss = "";
foreach (string site in xx1.GetSubKeyNames())
if (site == "ww")
{
ss = "AA";
RegistryKey xx2 = xx1.OpenSubKey("ww", true);
foreach (string tt in xx2.GetValueNames())
listBox1.Items.Add(tt);
break;
}
if (ss != "AA")
{
xx1.CreateSubKey("ww");
}
xx.Close(); if (listBox1.Focused == false)
{
delmovie.Enabled = false;
upmovie.Enabled = false;
downmovie.Enabled = false;
}
else
{
downmovie.Enabled = true;
upmovie.Enabled = true;
downmovie.Enabled = true;
}
} private void addmovie_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";
openFileDialog1.ShowDialog();
RegistryKey xx = Registry.LocalMachine;
RegistryKey xx1 = xx.OpenSubKey("SOFTWARE", true);
RegistryKey xx2 = xx1.OpenSubKey("ww", true);
xx2.SetValue(openFileDialog1.FileName, openFileDialog1.FileName, RegistryValueKind.String);
xx.Close(); listBox1.Items.Add(openFileDialog1.FileName);
} private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
upmovie.Enabled = true;
downmovie.Enabled = true;
delmovie.Enabled = true;
if (uu == "0")
axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
else
{
uu = "0";
axWindowsMediaPlayer1.URL = "";
}
axWindowsMediaPlayer1.Ctlcontrols.stop();
} private void delmovie_Click(object sender, EventArgs e)
{
if (axWindowsMediaPlayer1.URL == listBox1.SelectedItem.ToString())
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
axWindowsMediaPlayer1.URL = "";
axWindowsMediaPlayer1.Update();
}
RegistryKey xx = Registry.LocalMachine;
RegistryKey xx1 = xx.OpenSubKey("SOFTWARE", true);
RegistryKey xx2 = xx1.OpenSubKey("ww", true);
xx2.DeleteValue(listBox1.SelectedItem.ToString());
xx.Close();
uu = "1";
listBox1.Items.Remove(listBox1.SelectedItem);
listBox1.Update();
} private void downmovie_Click(object sender, EventArgs e)
{
/**
//定义一个变量,作移位用
int index_1 = 1;
//将当前条目的文本以及值都保存到一个临时变量里面
ListItem lt = new ListItem(listBox1.SelectedItem.Text, listBox1.SelectedValue);
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Text = listBox1.Items[listBox1.SelectedIndex + index].Text;
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Value = listBox1.Items[listBox1.SelectedIndex + index].Value;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Text = lt.Text;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
//把鼠标指针放到移动后的那项上
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
*/
} private void upmovie_Click(object sender, EventArgs e)
{
/*
//定义一个变量,作移位用
int index_1 = -1;
//将当前条目的文本以及值都保存到一个临时变量里面
ListItem lt = new ListItem(listBox1.SelectedItem.Text, listBox1.SelectedValue);
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Text = listBox1.Items[listBox1.SelectedIndex + index].Text;
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Value = listBox1.Items[listBox1.SelectedIndex + index].Value;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Text = lt.Text;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
//把鼠标指针放到移动后的那项上
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
*/
}
}
}问题1: string uu="0";此语句为什么在这个位置,uu是什么意思?
问题2: if (listBox1.Focused == false)这是什么意思?listbox的属性中没有focused,请问这是怎么回事?
麻烦高手不吝告知!
这是初始化设计时的代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;namespace movie
{
public partial class Form1 : Form
{ string uu="0"; public Form1()
{
InitializeComponent();
RegistryKey xx = Registry.LocalMachine;
RegistryKey xx1 = xx.OpenSubKey("SOFTWARE", true);
string ss = "";
foreach (string site in xx1.GetSubKeyNames())
if (site == "ww")
{
ss = "AA";
RegistryKey xx2 = xx1.OpenSubKey("ww", true);
foreach (string tt in xx2.GetValueNames())
listBox1.Items.Add(tt);
break;
}
if (ss != "AA")
{
xx1.CreateSubKey("ww");
}
xx.Close(); if (listBox1.Focused == false)
{
delmovie.Enabled = false;
upmovie.Enabled = false;
downmovie.Enabled = false;
}
else
{
downmovie.Enabled = true;
upmovie.Enabled = true;
downmovie.Enabled = true;
}
} private void addmovie_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";
openFileDialog1.ShowDialog();
RegistryKey xx = Registry.LocalMachine;
RegistryKey xx1 = xx.OpenSubKey("SOFTWARE", true);
RegistryKey xx2 = xx1.OpenSubKey("ww", true);
xx2.SetValue(openFileDialog1.FileName, openFileDialog1.FileName, RegistryValueKind.String);
xx.Close(); listBox1.Items.Add(openFileDialog1.FileName);
} private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
upmovie.Enabled = true;
downmovie.Enabled = true;
delmovie.Enabled = true;
if (uu == "0")
axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
else
{
uu = "0";
axWindowsMediaPlayer1.URL = "";
}
axWindowsMediaPlayer1.Ctlcontrols.stop();
} private void delmovie_Click(object sender, EventArgs e)
{
if (axWindowsMediaPlayer1.URL == listBox1.SelectedItem.ToString())
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
axWindowsMediaPlayer1.URL = "";
axWindowsMediaPlayer1.Update();
}
RegistryKey xx = Registry.LocalMachine;
RegistryKey xx1 = xx.OpenSubKey("SOFTWARE", true);
RegistryKey xx2 = xx1.OpenSubKey("ww", true);
xx2.DeleteValue(listBox1.SelectedItem.ToString());
xx.Close();
uu = "1";
listBox1.Items.Remove(listBox1.SelectedItem);
listBox1.Update();
} private void downmovie_Click(object sender, EventArgs e)
{
/**
//定义一个变量,作移位用
int index_1 = 1;
//将当前条目的文本以及值都保存到一个临时变量里面
ListItem lt = new ListItem(listBox1.SelectedItem.Text, listBox1.SelectedValue);
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Text = listBox1.Items[listBox1.SelectedIndex + index].Text;
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Value = listBox1.Items[listBox1.SelectedIndex + index].Value;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Text = lt.Text;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
//把鼠标指针放到移动后的那项上
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
*/
} private void upmovie_Click(object sender, EventArgs e)
{
/*
//定义一个变量,作移位用
int index_1 = -1;
//将当前条目的文本以及值都保存到一个临时变量里面
ListItem lt = new ListItem(listBox1.SelectedItem.Text, listBox1.SelectedValue);
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Text = listBox1.Items[listBox1.SelectedIndex + index].Text;
//被选中的项的值等于上一条或下一条的值
listBox1.Items[listBox1.SelectedIndex].Value = listBox1.Items[listBox1.SelectedIndex + index].Value;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Text = lt.Text;
//把被选中项的前一条或下一条的值用临时变量中的取代
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
//把鼠标指针放到移动后的那项上
listBox1.Items[listBox1.SelectedIndex].Value = lt.Value;
*/
}
}
}问题1: string uu="0";此语句为什么在这个位置,uu是什么意思?
问题2: if (listBox1.Focused == false)这是什么意思?listbox的属性中没有focused,请问这是怎么回事?
麻烦高手不吝告知!
问题2 if (listBox1.Focused == false) 如果焦点不再listBox1上面。listbox的属性中有focused,你可以看vs代码的智能提示。