台灣最大程式設計社群網站
線上人數
1656
 
會員總數:242956
討論主題:187845
歡迎您免費加入會員
討論區列表 >> C# >> 將Windows Forms轉成WPF
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
將Windows Forms轉成WPF
價值 : 20 QP  點閱數:307 回應數:0

樓主

ttt
門外漢
0 7
71 5
發送站內信

以下Windows Forms程式碼要轉成WPF:
//负责画左边的坐标和数据点
protected override void OnPaint(PaintEventArgs e)
{

Graphics graphics = e.Graphics;

Pen pen = new Pen(Color.Black, 1);
Brush text_brush = new SolidBrush(Color.Black);
Font text_font = new Font("宋体", 14);
//x
graphics.DrawLine(pen, Center_Zero_X, Center_Zero_Y, Center_Zero_X + LineLength, Center_Zero_Y);//x横线
graphics.DrawLine(pen, Center_Zero_X + LineLength - 5, Center_Zero_Y - 5, Center_Zero_X + LineLength, Center_Zero_Y);//x
graphics.DrawLine(pen, Center_Zero_X + LineLength - 5, Center_Zero_Y + 5, Center_Zero_X + LineLength, Center_Zero_Y);//x
graphics.DrawString("X", text_font, text_brush, Center_Zero_X + LineLength, Center_Zero_Y - 10);
//y
graphics.DrawLine(pen, Center_Zero_X, Center_Zero_Y, Center_Zero_X, Center_Zero_Y - LineLength);//y竖向线

graphics.DrawLine(pen, Center_Zero_X - 5, Center_Zero_Y - LineLength + 5, Center_Zero_X, Center_Zero_Y - LineLength);//y竖向线
graphics.DrawLine(pen, Center_Zero_X + 5, Center_Zero_Y - LineLength + 5, Center_Zero_X, Center_Zero_Y - LineLength);//y竖向线
graphics.DrawString("Y", text_font, text_brush, Center_Zero_X, Center_Zero_Y - LineLength + 10);
//0
Pen point_pen = new Pen(Color.Black, 2);
foreach (DataPoint dp in Dbscan.DataPoints_arry)
{
if (dp != null)
{
if (dp.cluster_tag == 0)
point_pen.Color = Color.Black;
else
point_pen.Color = GetColor(dp.cluster_tag);

graphics.DrawEllipse(point_pen, (float)dp.d1, (float)dp.d2, 2, 1);
}
}
#region Windows 画凹包
if (reset && convexhull_checkbox.Checked)
{
int size = Dbscan.clustet_set.Count;
int num = 0;
for (int i = 0; i < size; i++)
{
int count = ((ArrayList)Dbscan.clustet_set[i]).Count;
Console.WriteLine("count " + i + " , n=" + count);
num += count;
ArrayList subArray = (ArrayList)Dbscan.clustet_set[i];
Color clusterColor = GetColor(((DataPoint)subArray[0]).cluster_tag);
Points p = new Points();
for (int j = 0; j < count; j++)
{
p.Add(new CGPoint(((DataPoint)subArray[j]).d1, ((DataPoint)subArray[j]).d2));
}

if (p.Count > 3)
{
Console.WriteLine("big thank 3");
Points convexPoint = new Points();
convexHull = new ConvexHull(p);
convexPoint = convexHull.GetConvexHull();
PointF[] pointf;
pointf = new PointF[convexPoint.Count];
for (int k = 0; k < convexPoint.Count; k++)
{
pointf[k] = new PointF(convexPoint[k].X, convexPoint[k].Y);
}
Pen bluePen = new Pen(clusterColor, 2);
graphics.DrawPolygon(bluePen, pointf);
}
}
reset = false;
Console.WriteLine("the num=" + num);
}
#endregion

}
//根据index,返回不同类的颜色,用于区分不同的族.最大支持16种不同颜色
public Color GetColor(int index)
{
Color[] xColor ={ Color.Red , Color.Pink, Color.Green,
Color.Gold, Color.Purple, Color.Blue, Color.Orange,
Color.Plum ,Color.Cyan,Color.GreenYellow,Color.LightBlue,
Color.MediumSpringGreen,Color.PowderBlue,Color.SlateBlue};
return xColor[index % xColor.Length];
}



搜尋相關Tags的文章: [ Windows Forms轉成WPF ] ,
本篇文章發表於2018-06-03 08:56
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
目前尚無任何回覆
   

回覆
如要回應,請先登入.