问题1:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication11
{
class Myclass
{
public static void ff()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
}
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 40);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
请教各位大哥:
class Myclass
{
public static void ff()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
}这个类是我自己写的类,是不是自己写的类一般都放在 namespace WindowsApplication11 的下面
(也就是我放的位置),还是可以根据不同的情况,放在不同的 地方呢?
问题2:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication13
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 56);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
/*
static void Main()
{
Application.Run(new Form1());
}
*/ class hello
{
public static void Main()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
} private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
我用
class hello
{
public static void Main()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
}代替:static void Main()
{
Application.Run(new Form1());
}
可是编译时出现了如下错误:
C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WindowsApplication12\Form1.cs(81): Attribute 'STAThread' is not valid on this declaration type. It is valid on 'method' declarations only.C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WindowsApplication12\Form1.cs(94): The variable 'answer' is declared but never used各位大哥,为什么会出现这样问题啊~~如果我需要把 class hello中的Do you want me to write the two words 这条语句显示出来,那要怎么办啊(不是到控制台显示)谢谢!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication11
{
class Myclass
{
public static void ff()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
}
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 40);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
请教各位大哥:
class Myclass
{
public static void ff()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
}这个类是我自己写的类,是不是自己写的类一般都放在 namespace WindowsApplication11 的下面
(也就是我放的位置),还是可以根据不同的情况,放在不同的 地方呢?
问题2:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication13
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 56);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
/*
static void Main()
{
Application.Run(new Form1());
}
*/ class hello
{
public static void Main()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
} private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
我用
class hello
{
public static void Main()
{
string answer; System.Console.WriteLine("Do you want me to write the two words?");
}
}代替:static void Main()
{
Application.Run(new Form1());
}
可是编译时出现了如下错误:
C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WindowsApplication12\Form1.cs(81): Attribute 'STAThread' is not valid on this declaration type. It is valid on 'method' declarations only.C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WindowsApplication12\Form1.cs(94): The variable 'answer' is declared but never used各位大哥,为什么会出现这样问题啊~~如果我需要把 class hello中的Do you want me to write the two words 这条语句显示出来,那要怎么办啊(不是到控制台显示)谢谢!
解决方案 »
- 无法连接ftp??
- winform动态生成控件的几个问题
- 在C#.NET中有两个窗体form1 form2,form1为启动窗体,怎样才能做到从窗体1打开窗体2同时关闭窗体1呢?
- asp.net无法上传多媒体文件
- .net2 webbrowser 如何判断DocumentCompleted真正完成?
- DataSet转为XML特定格式的问题
- NUnit下如何伪造Web的上下文
- 一个统计图片的点击率的功能,小弟在线等呀
- 关于成为微信开发者的url 怎么填写?已有自己的服务器 C#版
- Point.ToString()后怎么转换回来?
- 来者有分,button中的tooltip,请帮忙
- ********** GGJJ,这个函数怎么写(C#)?
public static void ff()
静态的,放在什么地方都可以把。
2.
static void Main()
是默认的,不能变
就是在Form1_Load()
中写MessageBox.show("Do you want me to write the two words ");
问题1:public void ff() //不是静态的呢?那有什么要求呢?问题2 :我的意思是通过怎么通过 class hello 把"Do you want me to write the two words " 显示出来?
谢谢 dutguoyi 大哥!
{
public string getstr()
{
return "Do you want me to write the two words";
}
}想显示的时候调用hello.getstr();
hell用之前要实例化
HELLO hello = new HELLO();
string str = hello.getstr();//str = "Do you want me to write the two words";
static void Main()
{
myclass mycls = new myclass(); //在Main函数建立自己的类
mycls.ff(); //调用类的函数,但是你用的Console.WriteLine()函数不会在显示结果,因为这是WinForm的窗口,如果一定要用WriteLine来显示文字的话,可能需要先切换到控制台(但我不会切换),建议用MessageBox.Show()来显示。
Application.Run(new Form1());
}
lovefootball 大哥 和 kkk_visual 大哥: static void Main()
{
myclass mycls = new myclass(); //在Main函数建立自己的类
mycls.ff(); //调用类的函数,但是你用的Console.WriteLine()函数不会在显示结果,因为这是WinForm的窗口,如果一定要用WriteLine来显示文字的话,可能需要先切换到控制台(但我不会切换),建议用MessageBox.Show()来显示。
Application.Run(new Form1());
}为什么要把 myclass mycls = new myclass();
mycls.ff();
放在
Application.Run(new Form1()); 的前面呢?放在 Application.Run(new Form1()); 的后面可以不?
还有请两为大哥介绍本 C# 和 asp.net 入们的书啊
谢谢!
wrox一系列C#的书都值得出看。放在 Application.Run(new Form1()); 的前面是因为你需要在窗口显示出来之前显示你的那句话呀。放在后面当然可以啦,你可以试试,两者有什么不同,我也正在学C#,因为有VC++的基础,所以学起来很轻松的。C++很重要,建议学习。一起努力吧!祝你成功!