主题:我的第一个c#程序,请指教
我刚开始学c#,因我没有c语言基础,所以困难重重。下面是我写的第一个c#程序,如果没有yuhua,telancs两位朋友的帮忙,这个程序还不知道要什么时候才能产生。我希望大家指教的是:
1。从总体上看这个程序存在的毛病.
2。int a=Convert.ToInt32("5"),这时a的值是5。如果题中s=Convert.ToInt32(m)则给出的是m的asc码,所以用了个笨法子,减48,请给出这种情况的转换办法。
3。这个程序改自8.5日VB版上的“马走日只差一步”,我希望把它改成敲一下窗体棋子走一步,可我不知从哪下手,请大家帮忙。
using System;
using System.Drawing;
using System.Windows.Forms;
namespace _100
{
public class Class_100
{
public static void DrawShapes(Graphics g) // 1。画法类
{
Pen p1 = new Pen(Color.FromArgb(255,0,0,0),2);
Pen p2 = new Pen(Color.FromArgb(100,25,0,0),1);
for(int i=1;i< 10;++i)
{
g.DrawLine(p1,40,40*i,360,40*i);
g.DrawLine(p1,40*i,40,40*i,360);
}
string c = "482715365778668768472816375846678876553426381725132142638465867453452412335475837152445677856472513211233143351422416281736182";
int j=0,m0=40*4+20, n0=40*8+20;
g.DrawEllipse(p1,m0-5,n0-5,10,10);
try
{
while(j< c.Length)
{
char m =c[j];
char n =c[j+1];
int s= 20+40*(Convert.ToInt32(m)-48);
int t =20+40*( Convert.ToInt32(n)-48);
g.DrawEllipse(p2,s-5,t-5,10,10);
g.DrawLine(p2,m0,n0,s,t);
j=j+2;
m0 = s;
n0 = t;
}
}
catch(Exception)
{
}
}
public static void FormClick(object sender,EventArgs e) //2。事件
{
Graphics g = ((Form)sender).CreateGraphics();
DrawShapes(g);
}
public static void Main(String[] args) //3。主程序
{
Form form = new Form();
form.Width = 600;
form.Height = 430;
form.BackColor = Color.White;
form.Click += new EventHandler(Class_100.FormClick);
Application.Run(form);
}
}
}
1。从总体上看这个程序存在的毛病.
2。int a=Convert.ToInt32("5"),这时a的值是5。如果题中s=Convert.ToInt32(m)则给出的是m的asc码,所以用了个笨法子,减48,请给出这种情况的转换办法。
3。这个程序改自8.5日VB版上的“马走日只差一步”,我希望把它改成敲一下窗体棋子走一步,可我不知从哪下手,请大家帮忙。
using System;
using System.Drawing;
using System.Windows.Forms;
namespace _100
{
public class Class_100
{
public static void DrawShapes(Graphics g) // 1。画法类
{
Pen p1 = new Pen(Color.FromArgb(255,0,0,0),2);
Pen p2 = new Pen(Color.FromArgb(100,25,0,0),1);
for(int i=1;i< 10;++i)
{
g.DrawLine(p1,40,40*i,360,40*i);
g.DrawLine(p1,40*i,40,40*i,360);
}
string c = "482715365778668768472816375846678876553426381725132142638465867453452412335475837152445677856472513211233143351422416281736182";
int j=0,m0=40*4+20, n0=40*8+20;
g.DrawEllipse(p1,m0-5,n0-5,10,10);
try
{
while(j< c.Length)
{
char m =c[j];
char n =c[j+1];
int s= 20+40*(Convert.ToInt32(m)-48);
int t =20+40*( Convert.ToInt32(n)-48);
g.DrawEllipse(p2,s-5,t-5,10,10);
g.DrawLine(p2,m0,n0,s,t);
j=j+2;
m0 = s;
n0 = t;
}
}
catch(Exception)
{
}
}
public static void FormClick(object sender,EventArgs e) //2。事件
{
Graphics g = ((Form)sender).CreateGraphics();
DrawShapes(g);
}
public static void Main(String[] args) //3。主程序
{
Form form = new Form();
form.Width = 600;
form.Height = 430;
form.BackColor = Color.White;
form.Click += new EventHandler(Class_100.FormClick);
Application.Run(form);
}
}
}