c# 怎么截图用@

This site in other countries/regions:如何用c#做一个秒表?_c#吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:51,070贴子:
如何用c#做一个秒表?收藏
各位大侠,小弟请教一个问题:
设计一个windows窗体,当Form打开时即开始运行秒表,代码应该怎么写啊?
大侠帮帮忙啊,谢谢!!!
快试试吧,可以对自己使用挽尊卡咯~◆◆
使用time控件
新建工程 添加2个按钮设置标签按钮1为"开始"按钮2为"清零" 增加一个Timer控件 设置Interval=10 一个Label控件 字体那些你自己喜欢而定 双击控件 复制以下代码覆盖如果需要改动或者其他什么 可以留言(开始按钮点击了自动变换成"暂停" 如果不是你所想要 可以修改 多添加一个按钮)using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.Fnamespace WindowsFormsApplication1{&&&& public partial class Form1 : Form&&&& {&&&&&&&& public Form1()&&&&&&&& {&&&&&&&&&&&& InitializeComponent();&&&&&&&& }System.DateTime TimeP = new System.DateTime(0);private void button1_Click_1(object sender, EventArgs e){&&&& if (button1.Text == "开始")&&&& { &&&&&&&& timer1.Start(); &&&&&&&& button1.Text = "暂停"; &&&& } &&&& else { &&&&&&&& timer1.Stop(); &&&&&&&& button1.Text = "开始"; &&&& } }private void timer1_Tick_1(object sender, EventArgs e){&&&& TimeP = TimeP.AddSeconds(+1); &&&& label1.Text = TimeP.ToString("HH:mm:ss"); }private void button2_Click_1(object sender, EventArgs e){&&&& if (timer1.Enabled) { &&&&&&&& timer1.Stop(); &&&& } &&&& TimeP = new System.DateTime(0); &&&& label1.Text = TimeP.ToString("HH:mm:ss"); &&&& button1.Text = "开始"; } &&&& }}
快试试吧,可以对自己使用挽尊卡咯~◆◆
“WindowsFormsApplication1.Form1”不包含“timer1_Tick”的定义,并且找不到可接受类型为“WindowsFormsApplication1.Form1”的第一个参数的扩展方法“timer1_Tick”(是否缺少 using 指令或程序集引用?)
D:\Administrator\Visual Studio 2008\Projects\Catch_Time\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
WindowsFormsApplication1
是不是把timer1_Tick改成timer1.Tick
this.timer1.Interval = 10;
this.timer1.Tick += new System.EventHandler(this.timer1.Tick);
事件“System.Windows.Forms.Timer.Tick”只能出现在 += 或 -= 的左边
WindowsFormsApplication1
TIMER可以实现。但是我更推荐另起一个新的线程进行单独的计时。具体可百度 线程。
using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.Fusing System.Dnamespace biao{
public partial class miaobiao : Form
public miaobiao()
InitializeComponent();
Timer time = new Timer();
static int count = 1;
private void Form1_Load(object sender, EventArgs e)
btnAdd.Enabled =
button2.Enabled =
button3.Enabled =
private void btnAdd_Click(object sender, EventArgs e)
string[] arry = { (count++).ToString(), string.Format("{0}:{1}:{2}:{3}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)};
dataGridView1.Rows.Add(arry);
void time_Tick(object sender, EventArgs e)
label2.Text = string.Format("{0}:{1}:{2}:{3}",ts.Hours,ts.Minutes,ts.Seconds,ts.Milliseconds);
private void button1_Click(object sender, EventArgs e)
sw = new Stopwatch();
time.Tick += new EventHandler(time_Tick);
time.Interval =1;
sw.Start();
time.Start();
btnAdd.Enabled =
button2.Enabled =
button3.Enabled =
private void button2_Click(object sender, EventArgs e)
sw.Stop();
time.Stop();
label2.Text = string.Format("{0}:{1}:{2}:{3}",0,0,0,0);
dataGridView1.Rows.Clear();
count = 1;
private void button3_Click(object sender, EventArgs e)
if (button3.Text=="暂停")
sw.Stop();
time.Stop();
button3.Text = "继续";
sw.Start();
time.Start();
button3.Text = "暂停";
虽不明,但觉厉。
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或如何:使用 foreach 访问集合类(C# 编程指南)
此文章由人工翻译。 将光标移到文章的句子上,以查看原文。
如何:使用 foreach 访问集合类(C# 编程指南)
Visual Studio 2013
该示例定义了字符串 tokenizer 类。
此示例描述的是仅当您无法使用泛型集合类时才采用的推荐做法。
T& 的类型安全的泛型集合类,请参见。
在该示例中,以下代码段使用 Tokens 类通过“ ”和“-”分隔符将句子“This is a sample sentence.”分成若干标记。
该代码然后使用 foreach 语句显示这些标记。
Tokens f = new Tokens("This is a sample sentence.", new char[] {' ','-'});
// Display the tokens.
foreach (string item in f)
System.Console.WriteLine(item);
在内部,Tokens 类使用数组存储这些标记。
和 ,所以代码示例使用了数组的枚举方法(、、 和 ),而不是在 Tokens 类中定义这些方法。
方法定义包括在该示例中,以明确如何定义它们以及每个定义的内容。
using System.C
// Declare the Tokens class. The class implements the IEnumerable interface.
public class Tokens : IEnumerable
private string[]
Tokens(string source, char[] delimiters)
// The constructor parses the string argument into tokens.
elements = source.Split(delimiters);
// The IEnumerable interface requires implementation of method GetEnumerator.
public IEnumerator GetEnumerator()
return new TokenEnumerator(this);
// Declare an inner class that implements the IEnumerator interface.
private class TokenEnumerator : IEnumerator
private int position = -1;
public TokenEnumerator(Tokens t)
// The IEnumerator interface requires a MoveNext method.
public bool MoveNext()
if (position & t.elements.Length - 1)
position++;
return true;
return false;
// The IEnumerator interface requires a Reset method.
public void Reset()
position = -1;
// The IEnumerator interface requires a Current method.
public object Current
return t.elements[position];
// Test the Tokens class.
static void Main()
// Create a Tokens instance.
Tokens f = new Tokens("This is a sample sentence.", new char[] {' ','-'});
// Display the tokens.
foreach (string item in f)
System.Console.WriteLine(item);
/* Output:
来与 foreach 兼容。
成员,则可与 foreach 结合使用。
更为具体地定义 Current 的返回类型。
这会提供类型安全。
例如,可更改上述示例中的以下行。
// Change the Tokens class so that it no longer implements IEnumerable.
public class Tokens
// Change the return type for the GetEnumerator method.
public TokenEnumerator GetEnumerator()
// Change TokenEnumerator so that it no longer implements IEnumerator.
public class TokenEnumerator
// Change the return type of method Current to string.
public string Current
由于 Current 返回字符串,因此编译器能够检测何时在 foreach 语句中使用了不兼容的类型,如以下代码所示。
// Error: Cannot convert type string to int.
foreach (int item in f)
的缺点是:集合类不再与其他公共语言运行时语言的 foreach 语句或等效语句交互。
您对此内容的反馈非常重要。请告诉我们您的想法。
更多反馈?
1500 个剩余字符
我们非常感谢您的反馈。
开发人员中心c#中委托怎么用_百度知道
c#中委托怎么用
家好.Invoke(a);发现这样可以的这样又提示错误了还有Action a = 加个方法又不行了.Invoke(delegate() { });我一直搞不太懂C#的委托Action a = delegate() { };我做了个试验
提问者采纳
匿名方法只是纯粹描述了一个方法.Invoke(new Action(delegate() { / 一些代码}); {&#47,比如。委托可以通过匿名方法来构造。控件调用Invoke方法;/&#47,你还可以用Lambda表达式来表示匿名函数;另外,传送的应该是一个委托:Action a = new Action(() =&gt: 一些代码 }))委托和匿名方法还是有区别的。委托是一个Delegate类型的托管对象
提问者评价
其他类似问题
按默认排序
其他2条回答
&#47。2;} public void AgentDemo2(string s){
Console,就可以按照顺序连续的调用多个方法.WriteLine(&&#47,这样只会out最后一个方法的值;//&#47:&quot,我们可以使用这个委托了(调用一个委托);&
private delegate void OutMessage(string msg);/msg&quot:方法函数可以是类成员函数,参数列表要相同; + msg + &
//summary&gt,一个类静态函数作为代理方
#endregion公用的方法
#region私用的字段
&#47:[public/
deleStaticMeth(&quot.Demo,一个类.Delegate{
/&public void AgentDemo1(string str){
Console.ShowMessage):DelegateName instanceDemo = new DelegateName(AgentDemo);&#47,代码如下;private] delegate returnType delegateName(paramtype param1:[public/&gt,我们还有另的选择;summary&gt,应该用void。终于说完了;/ namespace Vparam name=&& namespace Visen,我是这样认为的;&#47、(paramtype param1,谢谢;param&);/&#47.Dsummary&gt,实用点来讲,instanceDemo相当于C里的一个函数指针;summary&/
#endregion私有的字段
}} 下面是代理方:”),也可以这样说;
public Agent()
#endregion空的构造函数
#region显示一条信息到控制台, int age)前面加了一个delegate的关键字。其实单独的说委托的应用好像有点牵强;multiDemo += new MultiDelegate(AgentDemo2); delegate instance deleStaticMeth&int age = 20.WriteLine(&/这时要说到一致了,含委托方,目的是帮助理解委托的过程;/
singleDele(&param&gt。 4,会执行AgentDemo函数,望大家知悉;&#47,我称它为委托方,当你确定要处理一件事;&lt。
//&#47,请大家批评指正,对应为添加或去掉一个方法●
多点委托不可以定义有返回值;/private是限定词;):public delegate string DelegateDemo(当instanceDemo执行时。这里要注意的有几点;/
MultiDele += new OutMessage(Agent。好像不是很好理解,委托更多的是在事件中的应用: delegate instance deleStaticMeth Method ShowMsummary&gt,你想要吃饭.委托概述委托是C#中新加入的一个类型;/ StartUp 委托演示中的程序入口, age);/
/instanceDemo(name,可以考虑用委托;/summary&gt,其中很多地方都经不起推敲;比如我们如上定义了一个委托: delegate instance singleDele static Method SShowM定义一个委托类型的对象
OutMessage singleDele = new OutMessage(&lt.D/&#47,叫个回锅肉饭(定义了一个委托)你决定找常去的那家叫做A的饭店(实例化一个委托)你打电话给A饭店(委托调用)A饭店给你做好了你的回锅肉饭(代理函数工作)饭来了,如果需要调用多个方法;&#47,只要和委托的签名相同就可以了,我来解释一下;
public void ShowMessage(string msg)
Csummary&gt。举个例子来说明下:this is AgentDemo1mutliDemo test :public string AgentDemo(string name,下面我们来用创建一个函数;&#47.WriteLine(s + “this is AgentDemo2&#92,你计划找个饭店.SShowMessage);&&lt.委托的理解首先申明;param name=&quot。 有错的地方;/&定义一个委托类型
[STAThread]
static void Main(string[] args)
#endregion显示一条信息到控制台, int age){string rev = “”.D + msg + & 输出的结果应该是;//);&} MultiDelegate multiDemo = new MultiDelegate(AgentDemo1),可以考虑使用委托, int age);),private&#47,可以把它想作一个和Class类似的一种类型,-=这样的运算符;&#47,也可以是一个静态成员,需要两个步骤;\定义一个多点委托
OutMessage MultiDele = new OutMessage(应用程序的主入口点,首先你要定义一个委托;summary&gt: this is a MultiDele static Method SShowM显示一条信息到控制台,我们可以让一个委托中包含多个方法,接下来创建一个DelegateDemo的实例;static Method SShowMessage out,一个类静态函数作为代理方
&#47.SShowMessage);&#47,如下,返回值要分别和returnT&
OutMessage deleStaticMeth = new OutMessage(Agent。说了这么多可能看起来还是不是很好理解。看下面的例子,returnType是一个返回类型;n&quot,你可以创建一个或多个该委托的实例,真好.WriteLine(& this is a MultiDele&quot,…)一致:public delegate void MultiDelegate(string name);/multiDemo(“multiDemo test ,你可以写任何一个你喜欢的名字,其实就是在函数 string DelegateDemo(summary&gt,否则你的编译会返回一个错误●
多点委托不建议你的参数列表中有OUT的类型;显示一条信息到控制台,所以如果要使用多点委托;
&#47,一个类成员函数作为代理方
/summary&gt:This is a delegate demo Method ShowM/protected&#47:this is AgentDemo2 可以看到我们一次显示的调用一个委托.Read(),即MethodName方法要和delegateName的签名一致;
&#47: this is a MultiDele 可见,和使用类相似;/
class StartUp
#region公用的方法
#region应用程序的主入口点;&#47。言归正传;/显示信息&
/&#47,委托定义就是在一个函数定义中间加入一个delegate的关键词:& delegate instance singleDele&quot,其他的值会丢失;This is a delegate demo&#92。它的作用类似于你申明一个类; Agent 类为委托者的代理方;);空的构造函数
&#47:string name = “cshape”,一个类静态函数作为代理方
#endregion公用的方法
}}输出为;&#47,这样我们一次显示调用委托;);msg&quot.Delegate{
//&#47,使用一个委托时.一个委托的例子我用两个类来做这个例子。定义一个委托的语法是这样的,public ClassName instancename = new ClassName(…);protected/\/
&#47,这里有个要注意的地方;/
MultiDele(&quot,即AgentDemo和声明委托时的DelegateDemo(我们姑且将delegate去掉)这两个函数的返回值,就是说MethodName的参数列表;protected/summary&gt,因为无法处理多个方法的返回值。
/…summary&n&quot,delegate是申明一个委托的关键词;/n&quot,一个类成员函数作为代理方
#region显示一条信息到控制台。
/&#47,需要多次显示的调用这个委托,不知道看的人明不明白;
&#47,就像是定义一个类一样;
public static void SShowMessage(string msg)
Console,处理委托者委托的事务;显示内容&summary&
//&lt,现在这个指针指向AgentDemo的函数入口地址,paramtype param1…这个是参数列表:using S&#47。接下来;&
#endregion显示一条信息到控制台;n”);/&&lt,这只是我举的一个例子,delegateName是一个你给委托起的名字.Agent ag = new Agent(),它顺序的(按照你添加方法的顺序)执行了方法AgentDemo1和AgentDemo2,看起来好像有点怪怪的:public class ClassName {…}创建一个委托的实例:using S&#47,但是自己又不会做(委托方不知道实现细节);然后,但又不能确定处理方法时;&#47。3,一个类我称它为代理方,…)这是我自己写的。5;
#endregion应用程序的主入口点;&#47.ShowMessage);Method ShowMessage out.WriteLine(str + “this is AgentDemo1&#92。什么是签名一致;&#47,一个类成员函数作为代理方
&#47!这样可以么;summary&gt,就不多说了.多点委托前面提到的委托都只包含对一个方法的调用;}这个函数是做参数传递给一个DelegateDemo实例的;&private] delegateName deleInstanceName = new delegateName(MethodName)这个类似于实例化一个类;
public class Agent
#region公用的方法
#region空的构造函数
&#47,就写法来说.委托的使用时机当你需要把一个方法传送给其他方法时:multiDemo test :●
委托支持 +=;&#471
这个问题很经典,等待高手解答。
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁有在论坛看见一帖,《》
Insus.NET的解决方法,是使用工厂方法来处理,可以创建一个工厂接口,然后每个方法设计为一个工厂类,并实现工厂接口。
工厂接口:
IGetFactory
using System.Collections.G
using System.L
using System.W
/// &summary&
/// Summary description for IGetFactory
/// &/summary&
namespace Insus.NET
public interface IGetFactory
string GetResult();
Get工厂类:
GetFactory
using System.Collections.G
using System.L
using System.W
/// &summary&
/// Summary description for GetFactory
/// &/summary&
namespace Insus.NET
public class GetFactory : IGetFactory
public GetFactory()
// TODO: Add constructor logic here
public string GetResult()
return "get";
GetTest类:
GetTestFactory
using System.Collections.G
using System.L
using System.W
/// &summary&
/// Summary description for GetTestFactory
/// &/summary&
namespace Insus.NET
public class GetTestFactory : IGetFactory
public GetTestFactory()
// TODO: Add constructor logic here
public string GetResult()
return "gettest";
以及GetSet类:
GetSetFactory
using System.Collections.G
using System.L
using System.W
/// &summary&
/// Summary description for GetSetFactory
/// &/summary&
namespace Insus.NET
public class GetSetFactory : IGetFactory
public GetSetFactory()
// TODO: Add constructor logic here
public string GetResult()
return "getset";
因此你的代码最终变为:
using System.Collections.G
using System.L
using System.W
using System.Web.UI;
using System.Web.UI.WebC
using Insus.NET;
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
public string Exec(string mothedName)
string ret = "";
//switch (mothedName)
case "get":
ret = get();
case "get1":
ret = gettest();
case "testget":
ret = getrset();
IGetFactory get = new GetTestFactory();
//这里是实现工厂类
ret = get.GetResult();
//public string get()
return "get";
//public string gettest()
return "gettest";
//public string getrset()
return "getset";
15:50修改补充如下:上面的最终代码,无传入参数mothedName,怎样办,我们可以虑一下反射,如果改为反射击,那传入的参数需要规范一下方可以:"get" &&"Get"; "get1" &&"GetTest""testget" && "GetSet"&这样一改之后,就可以使用反射语法了,可以把
IGetFactory get = new GetTestFactory();
//这里是实现工厂类
改为(下面是asp.net的应用):
Reflection
IGetFactory get = (IGetFactory)Assembly.Load("App_Code").CreateInstance("Insus.NET." + mothedName + "Factory");
如果在非asp.net下,可以把"App_Code"改为"程序集名称":
IGetFactory get = (IGetFactory)Assembly.Load("程序集名称").CreateInstance("Insus.NET." + mothedName + "Factory");
阅读(...) 评论()

我要回帖

更多关于 怎么截图 的文章

 

随机推荐