C#:下面程序用vs2012编译时出现 当前上下文中不存在名称lblShow,怎么回事
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Threading.Ta...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Test : Form
{
private void btnMp3_Click(object sender, EventArgs e)
{
Mp3 m = new Mp3();
if (m is IUsb)
{
IUsb iu = (IUsb)m;
lblShow.Text = iu.TransData("计算机","MP3设备");
}
}
private void btnMobile_Click(object sender,EventArgs e)
{
Mobile mob =new Mobile();
IUsb iu=mob as IUsb;
if(iu!=null) lblShow.Text=iu.TransData("计算机","手机");
IBluetooth ib=mob as IBluetooth;
if(ib != null) lblShow.Text += "\n"+ib.TransData("手机","计算机");
lblShow.Text+="\n"+mob.Call("父亲");
}
}
interface IUsb
{
int MaxSpeed{get;}
string TransData(string from,string to);
}
interface IBluetooth
{
int MaxSpeed{get;}
string TransData(string from,string to);
}
public class Mp3:IUsb
{
public int MaxSpeed
{
get{return 480;}
}
public string TransData(string from,string to)
{
return string.Format("数据传输:从{0}到{1}",from,to);
}
}
public abstract class Phone
{
public abstract string Call(string name);
}
public class Mobile : Phone ,IUsb,IBluetooth
{
int IUsb.MaxSpeed
{
get{return 480;}
}
string IUsb.TransData(string from,string to)
{
return string.Format("USB数据传输:从{0}到{1}",from,to);
}
int IBluetooth.MaxSpeed
{
get{return 64;}
}
string IBluetooth.TransData(string from,string to)
{
return string.Format("Bluetooth数据传输:从{0}到{1}",from,to);
}
public override string Call(string name)
{
return string.Format("和{0}通话中...",name);
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Test : Form
{
private void btnMp3_Click(object sender, EventArgs e)
{
Mp3 m = new Mp3();
if (m is IUsb)
{
IUsb iu = (IUsb)m;
lblShow.Text = iu.TransData("计算机","MP3设备");
}
}
private void btnMobile_Click(object sender,EventArgs e)
{
Mobile mob =new Mobile();
IUsb iu=mob as IUsb;
if(iu!=null) lblShow.Text=iu.TransData("计算机","手机");
IBluetooth ib=mob as IBluetooth;
if(ib != null) lblShow.Text += "\n"+ib.TransData("手机","计算机");
lblShow.Text+="\n"+mob.Call("父亲");
}
}
interface IUsb
{
int MaxSpeed{get;}
string TransData(string from,string to);
}
interface IBluetooth
{
int MaxSpeed{get;}
string TransData(string from,string to);
}
public class Mp3:IUsb
{
public int MaxSpeed
{
get{return 480;}
}
public string TransData(string from,string to)
{
return string.Format("数据传输:从{0}到{1}",from,to);
}
}
public abstract class Phone
{
public abstract string Call(string name);
}
public class Mobile : Phone ,IUsb,IBluetooth
{
int IUsb.MaxSpeed
{
get{return 480;}
}
string IUsb.TransData(string from,string to)
{
return string.Format("USB数据传输:从{0}到{1}",from,to);
}
int IBluetooth.MaxSpeed
{
get{return 64;}
}
string IBluetooth.TransData(string from,string to)
{
return string.Format("Bluetooth数据传输:从{0}到{1}",from,to);
}
public override string Call(string name)
{
return string.Format("和{0}通话中...",name);
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
} 展开
3个回答
展开全部
lblshow就是你页面上的一个textbox控件,你想要把你的内容显示到哪个控件里,你直接把那个控件改为lblshow就可以了涩
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
删掉定义就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询