比较尴尬自己研究半天也一点没研究出来。
要求是这样的:
编写打印三角形算法程序,根据角度绘制直线。(要求放置三个编辑框,输入不同的角度,形成不同的三角形)
小弟在此谢过了能不能毕业就靠你们了。
要求是这样的:
编写打印三角形算法程序,根据角度绘制直线。(要求放置三个编辑框,输入不同的角度,形成不同的三角形)
小弟在此谢过了能不能毕业就靠你们了。
解决方案 »
- TargetType="{x:Type Button}"和TargetType="Button"有什么区别?
- C# VS2005中怎么实现这个控件?
- C# 应用程序 更换背景图片
- (高手请)将GridView的数据导入excel的时将标题居中(新手提问)
- c#RAR压缩文件的问题
- 请问如何在C#代码里设置系统日期?
- Files 的值“<<<<<<< .mine”无效。路径中具有非法字符。
- 请问,阅读代码的方法,我常常看到一大堆源码,不知所措。请大家指点一下。
- 菜鸟编程 在C# WINDOWS编程中怎么设置网址的超连接在窗口中放电视
- vc包不可用或未注册
- C# datagridview(或C1grid)的问题,都来看看
- 软件数据交互问题
System.Drawing.Graphics g = this.CreateGraphics();
g.DrawPolygon 你试试自己用这个试试。
如果你想干这行的话
需要努力啊。
用gdi 画就行了啊
问题是老师让输入角度,只要符合三角形内角和,就可以任意画三角形。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication263
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} void button1_Click(object sender, EventArgs e)
{
double A1 = double.Parse(textBox1.Text);
double A2 = double.Parse(textBox2.Text);
double A3 = double.Parse(textBox3.Text); if (A1 + A2 + A3 != 180)
{
MessageBox.Show("内角之合必须等于180度");
return;
} Bitmap Bmp = new Bitmap(100, 100);
using (Graphics G = Graphics.FromImage(Bmp))
{
PointF[] PS=new PointF[4];
PS[0]= new Point(50, 50); double LC = 30;
double LM = Math.Sin(A1 * Math.PI / 180) * LC;
double LA1 =Math.Cos(A1 * Math.PI / 180) * LC; PS[1] = PointF.Add(PS[0], new SizeF((float)LA1, (float)-LM)); double LA2 = LM / Math.Tan(A2 * Math.PI / 180); PS[2] = PointF.Add(PS[1], new SizeF((float)LA2, (float)LM)); PS[3] = new Point(50, 50); G.DrawLines(Pens.Red, PS);
} pictureBox1.Image = Bmp;
}
}
}
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
public class MyClass:Form
{
private int Length=200; //一条边的长度
private Point[] p=new Point[4];
private int start_x=0,start_y=0;
private int jiaodu_1=100; //角度1
private int jiaodu_2=30; //角度2
public static void Main()
{
Application.Run(new MyClass());
}
//初始化初
public MyClass()
{
start_x=this.Width/2;
start_y=this.Height/2;
this.p[0]=new Point(start_x,start_y); //起点
this.p[1]=new Point(start_x+this.Length,start_y); //第二个点
//this.p[2]=new Point(0,0);
this.p[3]=this.p[0]; //回到起点
this.ResizeRedraw=true;
}
//重载 OnPaint函数
protected override void OnPaint(PaintEventArgs pea)
{
this.Compult();
Graphics grfx=pea.Graphics;
grfx.DrawLines(System.Drawing.Pens.Black ,this.p ); }
///计算第三个坐标
public void Compult()
{
double k1=Math.Tan((this.jiaodu_1* Math.PI) / 180);
double k2=Math.Tan((this.jiaodu_2* Math.PI) / 180);
double x1=(double)this.p[0].X;
double y1=(double)this.p[0].Y;
double x2=(double)this.p[1].X;
double y2=(double)this.p[1].Y;
double x3=(k1*x1-k2*x2+y2-y1)/(k1-k2); // 初中时候公式
double y3=(x3-x1)*k1+y1;
this.p[2]=new Point((int)x3,(int)y3);
}
}
估计 还有问题 你在琢磨琢磨吧