用C#写一个画图程序
- 提问者网友:浪女天生ˇ性情薄
- 2021-03-02 06:40
- 二级知识专家网友:何以畏孤独
- 2021-03-02 08:14
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine(); //获取输入数据,空格分开
char[] sep = { ' ' };
string[] res = str.Split(sep,StringSplitOptions.RemoveEmptyEntries);
int[] inputs = new int[res.Length]; // 输入任意个数字
for (int i = 0; i < res.Length; i++)
{
inputs[i] = Convert.ToInt32(res[i]);
}
Console.WriteLine("max:" + inputs.Max());
Console.WriteLine("min:" + inputs.Min());
Console.WriteLine("max:" + inputs.Average());
Console.ReadKey();
}
}
- 1楼网友:何必打扰
- 2021-03-02 08:33
这是一个很简单的画图程序,你可以参考一下,运行正常。
using system; using system.drawing; using system.collections; using system.componentmodel; using system.windows.forms; using system.data;
namespace usegdi_ { /// <summary> /// form1 的摘要说明。 /// </summary> public class form1 : system.windows.forms.form { private system.windows.forms.mainmenu mainmenu1; private system.windows.forms.menuitem menuitem1; private system.windows.forms.menuitem mnutooleraser; private system.windows.forms.menuitem mnutooldraw; private system.windows.forms.menuitem mnutoolclear; private system.windows.forms.menuitem menuitem5; /// <summary> /// 必需的设计器变量。 /// </summary> private system.componentmodel.container components = null;
public form1() { // // windows 窗体设计器支持所必需的 // initializecomponent();
// // todo: 在 initializecomponent 调用后添加任何构造函数代码 // }
/// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void dispose( bool disposing ) { if( disposing ) { if (components != null) { components.dispose(); } } base.dispose( disposing ); }
#region windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void initializecomponent() { this.mainmenu1 = new system.windows.forms.mainmenu(); this.menuitem1 = new system.windows.forms.menuitem(); this.mnutooleraser = new system.windows.forms.menuitem(); this.mnutooldraw = new system.windows.forms.menuitem(); this.mnutoolclear = new system.windows.forms.menuitem(); this.menuitem5 = new system.windows.forms.menuitem(); // // mainmenu1 // this.mainmenu1.menuitems.addrange(new system.windows.forms.menuitem[] { this.menuitem1}); // // menuitem1 // this.menuitem1.index = 0; this.menuitem1.menuitems.addrange(new system.windows.forms.menuitem[] { this.mnutooleraser, this.mnutooldraw, this.menuitem5, this.mnutoolclear}); this.menuitem1.text = "工具"; // // mnutooleraser // this.mnutooleraser.index = 0; this.mnutooleraser.text = "橡皮"; this.mnutooleraser.click += new system.eventhandler(this.mnutooleraser_click); // // mnutooldraw // this.mnutooldraw.checked = true; this.mnutooldraw.index = 1; this.mnutooldraw.text = "绘图"; this.mnutooldraw.click += new system.eventhandler(this.mnutooldraw_click); // // mnutoolclear // this.mnutoolclear.index = 3; this.mnutoolclear.text = "清除"; this.mnutoolclear.click += new system.eventhandler(this.mnutoolclear_click); // // menuitem5 // this.menuitem5.index = 2; this.menuitem5.text = "-"; // // form1 // this.autoscalebasesize = new system.drawing.size(6, 14); this.clientsize = new system.drawing.size(376, 321); this.menu = this.mainmenu1; this.name = "form1"; this.startposition = system.windows.forms.formstartposition.centerscreen; this.text = "form1"; this.mousedown += new system.windows.forms.mouseeventhandler(this.form1_mousedown); this.mousemove += new system.windows.forms.mouseeventhandler(this.form1_mousemove);
} #endregion
/// <summary> /// 应用程序的主入口点。 /// </summary> [stathread] static void main() { application.run(new form1()); }
int x,y; private void form1_mousedown(object sender, system.windows.forms.mouseeventargs e) { if(e.button==mousebuttons.left) { x=e.x; y=e.y; } }
private void form1_mousemove(object sender, system.windows.forms.mouseeventargs e) { if(e.button==mousebuttons.left && this.sign==1) { graphics g=this.creategraphics(); pen p=new pen(color.red,1); g.drawline(p,new point(x,y),new point(e.x,e.y)); x=e.x; y=e.y; } else if(e.button==mousebuttons.left && this.sign==0) { graphics g=this.creategraphics(); solidbrush b=new solidbrush(color.blue); g.fillrectangle(b,x,y,math.abs(e.x-x)+10,math.abs(e.y-y)+20); x=e.x; y=e.y; } }
private void mnutoolclear_click(object sender, system.eventargs e) { this.refresh(); }
int sign=1; private void mnutooldraw_click(object sender, system.eventargs e) { this.sign=1; this.setchecked((menuitem)sender); }
private void setchecked(menuitem item) { this.mnutooldraw.checked=false; this.mnutooleraser.checked=false;
item.checked=true; }
private void mnutooleraser_click(object sender, system.eventargs e) { this.sign=0; this.setchecked((menuitem)sender); } } }
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |