標籤:href count jpg point 高度 drawing cti 設定圖 檔案
前言
可執行檔下載 QfdHouse-exe.zip
因項目需要做了一個品質功能配置(Quality Function Deployment 簡稱Qfd)的品質屋編製工具軟體,本軟體是在發布一個免費開源軟體-- PAD流程圖繪製軟體PADFlowChart基礎之上做的,效果如下:
支援建立、儲存、匯出圖片,自訂使用者需求和技術特性,儲存格點擊切換關聯矩陣程度和自關聯矩陣的相關性。
開發中解決的問題
相信來這的人對Qfd是不感興趣的,下面就把遇到的問題說一下。
如何設定圖形的初始大小
1.在Shape類增加預設高度和寬度的屬性
/// <summary> /// 預設寬度 /// </summary> private float mDefaultWidth = 0f; /// <summary> /// 預設高度 /// </summary> private float mDefaultHeigh = 0f;
/// <summary> /// 預設寬度 /// </summary> [GraphMLData]public float DefaultWidth { get { return mDefaultWidth; } set { mDefaultWidth = value; } } /// <summary> /// 預設高度 /// </summary> [GraphMLData] public float DefaultHeigh { get { return mDefaultHeigh; } set { mDefaultHeigh = value; } }
2.在TableShape類中初始化
public TableShape() : base() { this.Init(); this.InitTestData3(); BindingEventHandler(); base.DefaultWidth = 300; base.DefaultHeigh = 100; }
3.修改GraphControl的DrawShapeMouseUp(PointF p)函數
private void DrawShapeMouseUp(PointF p) { Cursor = System.Windows.Forms.Cursors.Default; float t_left = (mMouseDownPoint.X < p.X ? mMouseDownPoint.X : p.X); float t_right = (mMouseDownPoint.X >= p.X ? mMouseDownPoint.X : p.X); float t_top = (mMouseDownPoint.Y < p.Y ? mMouseDownPoint.Y : p.Y); float t_bottom = (mMouseDownPoint.Y >= p.Y ? mMouseDownPoint.Y : p.Y); if (t_right - t_left < 10) { // t_right = t_left + mDefaultShapeWidth; t_right = t_left + Math.Max(mDefaultShapeWidth, mshapeObject.DefaultWidth); } if (t_bottom - t_top < 10) { //t_bottom = t_top + mDefaultShapeHeight; t_bottom = t_top + Math.Max(mDefaultShapeHeight, mshapeObject.DefaultHeigh); } mshapeObject.Rectangle = RectangleF.FromLTRB(t_left, t_top, t_right, t_bottom); Invalidate(); EndDrawShapeWithMouse(); }
注釋掉的是原來的代碼
如何匯出圖形到圖片格式
1. 在FlowChartForm.cs中增加儲存圖形圖片的方法
public bool SaveShapeImage() { if (graphControl.SelectedShapes.Count != 1) { MessageBox.Show("請選中一個圖形"); return false; } var fileName = string.Empty; using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.DefaultExt = ".jpg"; sfd.Filter = "jpg file(*.jpg)|*.jpg"; if (sfd.ShowDialog() == DialogResult.OK) { fileName = sfd.FileName; } else { return false; } } var shape = graphControl.SelectedShapes[0]; graphControl.SaveShapeImage(fileName, shape); return true; }
2.在GraphControl.cs中增加SaveShapeImage方法
public void SaveShapeImage(string path,Shape shape) { Image bmp = GetShapeImage(shape); bmp.Save(path); } public Image GetShapeImage(Shape shape) { var oldRectangle = shape.Rectangle; var newRectangle = new RectangleF(0, 0, oldRectangle.Width, oldRectangle.Height); shape.Rectangle = newRectangle; Bitmap bmp = new Bitmap((int)shape.Rectangle.Width, (int)shape.Rectangle.Height, this.CreateGraphics()); using (Graphics g = Graphics.FromImage(bmp)) { g.SmoothingMode = SmoothingMode.AntiAlias; shape.Paint(g); } shape.Rectangle = oldRectangle; Image.GetThumbnailImageAbort tCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); return bmp.GetThumbnailImage((int)shape.Rectangle.Width,(int)shape.Rectangle.Height, tCallback, IntPtr.Zero); }
使用NetronGraphLib類庫開發Qfd品質屋編製工具