using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
public partial class 三角形計算器 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
double area = 0, a = 0, b = 0, c = 0, p = 0;
double x1 = Convert.ToDouble(TextBox1.Text);
double y1 = Convert.ToDouble(TextBox2.Text);
double x2 = Convert.ToDouble(TextBox3.Text);
double y2 = Convert.ToDouble(TextBox4.Text);
double x3 = Convert.ToDouble(TextBox5.Text);
double y3 = Convert.ToDouble(TextBox6.Text);
a = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
b = Math.Sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
c = Math.Sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
if (a + b > c && a + c > b && b + c > a)
{
p = (a + b + c) / 2;
area = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
Label1.Text = "三角形的面積是:" + area.ToString();
}
else
{
Label1.Text = "此三點不能構成三角形,請重新輸入";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
int x1 = Convert.ToInt32(TextBox1.Text);
int y1 = Convert.ToInt32(TextBox2.Text);
int x2 = Convert.ToInt32(TextBox3.Text);
int y2 = Convert.ToInt32(TextBox4.Text);
int x3 = Convert.ToInt32(TextBox5.Text);
int y3 = Convert.ToInt32(TextBox6.Text);
//創建畫布
Bitmap MyMap = new Bitmap(10,10);//創建一個寬100,高100的畫布
Graphics g = Graphics.FromImage(MyMap);
//創建畫筆
Pen pen = new Pen(Brushes.Black,2);
//創建三個坐標點
Point p1 = new Point(x1,y1);
Point p2 = new Point(x2,y2);
Point p3 = new Point(x3,y3);
Point[] p = {p1,p2,p3};
g.Clear(Color.White);
g.DrawPolygon(pen,p);
MyMap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
MyMap.Dispose();
g.Dispose();
}
}
uj5u.com熱心網友回復:
你只是把圖片輸出到流,但是前端怎么用沒寫吧,前端也要相應的處理uj5u.com熱心網友回復:
是要加一個image控制元件嗎?剛開始學asp,很多不懂請諒解轉載請註明出處,本文鏈接:https://www.uj5u.com/net/58393.html
標籤:C#
上一篇:C#通過Socket接收下位回傳的命令并顯示在DataGridview中
下一篇:gridview系結多個資料
