資源簡介
本例說明一種報表組件的實現方法。
原理:將各個表格元素,以圖像的方式設置、添加到紙張畫布上,生成圖像,打印圖像。
功能:
1、支持SQL Serrver、Access數據庫,如需其他數據庫,也可很方便的添加到代碼中,自動獲取數據表,在元素中可選擇添加字段到報表中;
2、報表元素可自由拖放、設置大小、內容、字體、字體樣式等(元素非PictureBox組件);
3、支持全程的“撤銷”、“重做”;
4、可保存、讀取報表文件;
5、預覽、打印沒加上去,原理就是根據元素生成一幅或多幅圖像,再輸出到打印機,自行修改添加。
這里說明一下,這只是個規劃草稿,只是描述了一種報表組件的設計方式,所以代碼寫的較為繁瑣、冗余,代碼無委托線程等,所以比較容易看明白。
原理:將各個表格元素,以圖像的方式設置、添加到紙張畫布上,生成圖像,打印圖像。
功能:
1、支持SQL Serrver、Access數據庫,如需其他數據庫,也可很方便的添加到代碼中,自動獲取數據表,在元素中可選擇添加字段到報表中;
2、報表元素可自由拖放、設置大小、內容、字體、字體樣式等(元素非PictureBox組件);
3、支持全程的“撤銷”、“重做”;
4、可保存、讀取報表文件;
5、預覽、打印沒加上去,原理就是根據元素生成一幅或多幅圖像,再輸出到打印機,自行修改添加。
這里說明一下,這只是個規劃草稿,只是描述了一種報表組件的設計方式,所以代碼寫的較為繁瑣、冗余,代碼無委托線程等,所以比較容易看明白。
/// <summary> /// 剪切復制粘貼組件操作 /// </summary> public class OperationObject { public bool isData { get; set; } // 是否有剪切復制粘貼數據 public Rectangle Region { get; set; } // 大小范圍 public bool IsDragging { get; set; } // 能否拖動 public Point DraggingPoint { get; set; } // 組件拖動位置 public Bitmap Setimage { get; set; } // 組件圖像 public int SetType { get; set; } // 組件類型 public bool isContent { get; set; } // 組件內是否有內容 public int Field_BandType { get; set; } // 欄目類型 public Bitmap Field_Img { get; set; } // 圖像組件的圖像 public string Field_Text { get; set; } // 文字 public string Field_TextFont { get; set; } // 字體 public int Field_TextFontSize { get; set; } // 字體大小 public FontStyle Field_TextFontStyle { get; set; } // 文字樣式 public string Field_Align { get; set; } // 對齊方式 public int Field_ImgZoom { get; set; } // 圖像縮放 public bool[] Field_BoxLine { get; set; } // 邊框和斜線 public int Field_Shape { get; set; } // 形狀的類型 } public static OperationObject operationObject; /// <summary> /// 組件操作記錄 /// </summary> public class RecordObject { public int Num; // 序號 public Rectangle Region; // 大小范圍 public bool IsDragging; // 能否拖動 public Point DraggingPoint; // 組件拖動位置 public Bitmap Setimage; // 組件圖像 public int SetType; // 組件類型 public bool isContent; // 組件內是否有內容 public int Field_BandType; // 欄目類型 public Bitmap Field_Img; // 圖像組件的圖像 public string Field_Text; // 文字 public string Field_TextFont; // 字體 public int Field_TextFontSize; // 字體大小 public FontStyle Field_TextFontStyle; // 文字樣式 public string Field_Align; // 對齊方式 public int Field_ImgZoom; // 圖像縮放 public bool[] Field_BoxLine; // 邊框和斜線 public int Field_Shape; // 形狀的類型 public RecordObject( int _Num,Rectangle _Region, bool _IsDragging, Point _DraggingPoint, Bitmap _Setimage, int _SetType, bool _isContent, int f_BandType, Bitmap f_Img, string f_Text, string f_TextFont, int f_TextFontSize, FontStyle f_TextFontStyle, string f_Align, int f_ImgZoom, bool[] f_BoxLine, int f_Shape) { Num = _Num; Region = _Region; IsDragging = _IsDragging; DraggingPoint = _DraggingPoint; Setimage = _Setimage; SetType = _SetType; isContent = _isContent; Field_BandType = f_BandType; Field_Img = f_Img; Field_Text = f_Text; Field_TextFont = f_TextFont; Field_TextFontSize = f_TextFontSize; Field_TextFontStyle = f_TextFontStyle; Field_Align = f_Align; Field_ImgZoom = f_ImgZoom; Field_BoxLine = f_BoxLine; Field_Shape = f_Shape; } } public static List<List<RecordObject>> recordObject; /// <summary> /// 組件移動 /// </summary> public abstract class ADraggableGDIObject { public abstract Rectangle Region { get; set; } // 大小范圍 public abstract bool IsDragging { get; set; } // 能否拖動 public abstract Point DraggingPoint { get; set; } // 組件拖動位置 public abstract Bitmap Setimage { get; set; } // 組件圖像 public abstract int SetType { get; set; } // 組件類型 public abstract void OnPaint(PaintEventArgs e); // 重繪 public abstract bool isContent { get; set; } // 組件內是否有內容 public abstract int Field_BandType { get; set; } // 欄目類型 public abstract Bitmap Field_Img { get; set; } // 圖像組件的圖像 public abstract string Field_Text { get; set; } // 文字 public abstract string Field_TextFont { get; set; } // 字體 public abstract int Field_TextFontSize { get; set; } // 字體大小 public abstract FontStyle Field_TextFontStyle { get; set; } // 文字樣式 public abstract string Field_Align { get; set; } // 對齊方式 public abstract int Field_ImgZoom { get; set; } // 圖像縮放 public abstract bool[] Field_BoxLine { get; set; } // 邊框和斜線 public abstract int Field_Shape { get; set; } // 形狀的類型 } /// <summary> /// 組件移動對象定義 /// </summary> public class Draggable : ADraggableGDIObject { private bool m_IsDragging; // 能否拖動 private Point m_DraggingPoint; // 組件拖動位置 private Rectangle m_Region; // 大小范圍 private Bitmap m_image; // 組件圖像 private int m_controlType; // 組件類型 private bool m_isContent; // 組件內是否有內容 private int f_BandType; // 欄目類型 private Bitmap f_Img; // 圖像組件的圖像 private string f_Text; // 文字 private string f_TextFont; // 字體 private int f_TextFontSize; // 字體大小 private FontStyle f_TextFontStyle; // 文字樣式 private string f_Align; // 對齊方式 private int f_ImgZoom; // 圖像縮放 private bool[] f_BoxLine = new bool[8] { false, false, false, false, false, false, false, false }; // 邊框和斜線 private int f_Shape; // 形狀的類型 public Draggable(int startx, int starty, int _settype) { m_Region = new Rectangle(startx, starty, 51, 51); m_controlType = _settype; m_isContent = false; } public override int SetType { get { return m_controlType; } set { m_controlType = value; } } public override Rectangle Region { get { return m_Region; } set { m_Region = value; } } public override Bitmap Setimage { get { return m_image; } set { m_image = value; } } public override void OnPaint(PaintEventArgs e) { e.Graphics.DrawImage(m_image, m_Region); } public override bool IsDragging { get { return m_IsDragging; } set { m_IsDragging = value; } } public override Point DraggingPoint { get { return m_DraggingPoint; } set { m_DraggingPoint = value; } } public override bool isContent { get { return m_isContent; } set { m_isContent = value; } } public override int Field_BandType { get { return f_BandType; } set { f_BandType = value; } } public override Bitmap Field_Img { get { return f_Img; } set { f_Img = value; } } public override string Field_Text { get { return f_Text; } set { f_Text = value; } } public override string Field_TextFont { get { return f_TextFont; } set { f_TextFont = value; } } public override int Field_TextFontSize { get { return f_TextFontSize; } set { f_TextFontSize = value; } } public override FontStyle Field_TextFontStyle { get { return f_TextFontStyle; } set { f_TextFontStyle = value; } } public override string Field_Align { get { return f_Align; } set { f_Align = value; } } public override int Field_ImgZoom { get { return f_ImgZoom; } set { f_ImgZoom = value; } } public override bool[] Field_BoxLine { get { return f_BoxLine; } set { f_BoxLine = value; } } public override int Field_Shape { get { return f_Shape; } set { f_Shape = value; } } } public static List<ADraggableGDIObject> m_DraggableGDIObjects; /// <summary> /// 序列化保存讀取組件 /// </summary> [Serializable] public class SerializerObject { public string Data_Type; // 數據庫類型 public string Data_DataName; //數據庫名 public string Data_Table; // 數據表 public string Data_UserName; //用戶名 public string Data_Password; // 密碼 public string Data_ConnectionIP; // 地址 public string Page_TypeFace; public int Page_Direction; public int[] Page_Margin; public int controlNum; public Rectangle Region; // 大小范圍 public bool IsDragging; // 能否拖動 public Point DraggingPoint; // 組件拖動位置 public Bitmap Setimage; // 組件圖像 public int SetType; // 組件類型 public bool isContent; // 組件內是否有內容 public int Field_BandType; // 欄目類型 public Bitmap Field_Img; // 圖像組件的圖像 public string Field_Text; // 文字 public string Field_TextFont; // 字體 public int Field_TextFontSize; // 字體大小 public FontStyle Field_TextFontStyle; // 文字樣式 public string Field_Align; // 對齊方式 public int Field_ImgZoom; // 圖像縮放 public bool[] Field_BoxLine; // 邊框和斜線 public int Field_Shape; // 形狀的類型 public bool[] Band_Flag; // 欄目只出現一次 public SerializerObject( string _DataType, string _DataName,string _DataTable, string _DataUserName, string _DataPassword, string _DataConnectionIP, string _TypeFace, int _Direction, int[] _Margin, int _Num, Rectangle _Region, bool _IsDragging, Point _DraggingPoint, Bitmap _Setimage, int _SetType, bool _isContent, int f_BandType, Bitmap f_Img, string f_Text, string f_TextFont, int f_TextFontSize, FontStyle f_TextFontStyle, string f_Align, int f_ImgZoom, bool[] f_BoxLine, int f_Shape, bool[] _BandFlag) { Data_Type = _DataType; Data_DataName = _DataName; Data_Table = _DataTable; Data_UserName = _DataUserName; Data_Password = _DataPassword; Data_ConnectionIP = _DataConnectionIP; Page_TypeFace = _TypeFace; Page_Direction = _Direction; Page_Margin = _Margin; controlNum = _Num; Region = _Region; IsDragging = _IsDragging; DraggingPoint = _DraggingPoint; Setimage = _Setimage; SetType = _SetType; isContent = _isContent; Field_BandType = f_BandType; Field_Img = f_Img; Field_Text = f_Text; Field_TextFont = f_TextFont; Field_TextFontSize = f_TextFontSize; Field_TextFontStyle = f_TextFontStyle; Field_Align = f_Align; Field_ImgZoom = f_ImgZoom; Field_BoxLine = f_BoxLine; Field_Shape = f_Shape; Band_Flag = _BandFlag; } } public static List<SerializerObject> serializerObject = new List<SerializerObject>(); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static bool Change_Flag = false; // 是否改變了組件 /*窗體定義*/ public static Point screen_Location; // 窗體位置 public static Size screen_Size; //窗體大小 public static bool setFont_Flag = false; // 選擇字體窗口打開標志 public static bool setFontSize_Flag = false; // 選擇字體大小窗口打開標志 public static bool setDate_Flag = false; // 選擇日期窗口打開標志 public static bool setPageCode_Flag = false; // 選擇頁碼窗口打開標志 /*數據庫*/ public static string Data_Type = ""; // 數據庫類型 public static string Data_DataName = ""; // 數據庫名 public static string Data_Table = ""; // 數據表 public static string Data_UserName = ""; //用戶名 public static string Data_Password = ""; // 密碼 public static string Data_ConnectionIP = ""; // 地址 /*組件區域位置*/ public static PointF[] CursorArea = new PointF[8]; // 鼠標區域 public static Font LabelFont = new Font("微軟雅黑", 9, FontStyle.Regular); // label 字體設置 public static bool ShowLine = true; // 是否顯示組件標線 /*設計頁面*/ public static string Page_TypeFace = "A4"; // 紙張類型 public static int Page_Direction = 0; // 紙張方向 public static Size[] Page_Area = new Size[2] { new Size(789,1136), new Size(1136,789) }; // 橫向、縱向紙張大小 public static int[] Page_Margin = new int[4] { 0,0,0,0 }; // 紙張邊距 public static PanelEx pageDesing; // 設計框 public static PanelEx pageContainer; // 頁面容器 public static PanelEx A4_PageType; // 頁面 public static bool controlPlace = false; // 能否放置組件 public static int controlType = -1; // 組件類型 public static int control_Num = -1; // 組件序號 public static int oper_Record = -1; // 操作動作序號 /*底部狀態信息欄*/ public static PanelEx statePanel; public static PanelEx[] control_Input = new PanelEx[8]; /*選擇形狀、欄目標志*/ public static int Select_Shape = 0; public static int Select_Band = 0; public static bool[] Band_Flag = new bool[3] { false,false,false}; // 欄目只出現一次
代碼片段和文件信息
using?System;
using?System.Drawing;
using?System.Drawing.Drawing2D;
using?System.Windows.Forms;
using?static?DefineList;
public?class?ControlObj
{
????private?static?Bitmap?blockBox_Select?=?(Bitmap)Image.FromFile(“images/r1.png“);
????private?static?Bitmap?blockDot_Select?=?(Bitmap)Image.FromFile(“images/r2.png“);
????private?static?Bitmap?blockBox?=?(Bitmap)Image.FromFile(“images/r1s.png“);
????private?static?Bitmap?blockDot?=?(Bitmap)Image.FromFile(“images/r2s.png“);
????private?static?int?set_midX;?//?繪制線段中間圖像位置
????private?static?int?set_midY;//?繪制線段中間圖像位置
????private?static?UiDrawTextMethod?DrawText?=?new?UiDrawTextMethod();
????public?static?Bitmap?LinBox(int?width?int?height?int?selectType?int?_controlType?int?_controlNum)
????{
????????Bitmap?_bmp?=?new?B
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????88??2018-07-27?12:22??ds1\.vs\ds1\DesignTimeBuild\.dtbcache
????..A..H.?????96768??2018-09-13?09:27??ds1\.vs\ds1\v15\.suo
?????文件??????????0??2018-09-09?08:45??ds1\.vs\ds1\v15\Server\sqlite3\db.lock
?????文件?????913408??2018-09-13?08:33??ds1\.vs\ds1\v15\Server\sqlite3\storage.ide
?????文件??????32768??2018-09-13?08:26??ds1\.vs\ds1\v15\Server\sqlite3\storage.ide-shm
?????文件????4190072??2018-09-13?09:27??ds1\.vs\ds1\v15\Server\sqlite3\storage.ide-wal
?????文件????????189??2018-07-24?09:24??ds1\App.config
?????文件????????119??2018-07-24?11:04??ds1\bin\Debug\back.png
?????文件?????145920??2018-09-13?08:59??ds1\bin\Debug\ds1.exe
?????文件????????189??2018-07-24?09:24??ds1\bin\Debug\ds1.exe.config
?????文件?????239104??2018-09-13?08:59??ds1\bin\Debug\ds1.pdb
?????文件??????18422??2018-08-06?14:27??ds1\bin\Debug\images\band.png
?????文件??????28066??2018-08-06?14:27??ds1\bin\Debug\images\band.psd
?????文件??????18803??2018-09-02?20:01??ds1\bin\Debug\images\band_cur.png
?????文件??????15152??2018-09-02?19:51??ds1\bin\Debug\images\band_pb.png
?????文件??????15263??2018-09-02?19:53??ds1\bin\Debug\images\band_pd.png
?????文件??????15148??2018-09-02?19:51??ds1\bin\Debug\images\band_pt.png
?????文件??????15451??2018-09-04?11:36??ds1\bin\Debug\images\botmost.png
?????文件??????15536??2018-09-06?10:14??ds1\bin\Debug\images\cancel.png
?????文件????????145??2018-07-16?13:03??ds1\bin\Debug\images\cDot.png
?????文件????????120??2018-07-16?12:55??ds1\bin\Debug\images\cLine.png
?????文件??????15164??2018-09-06?09:38??ds1\bin\Debug\images\copy.png
?????文件??????15735??2018-09-06?09:37??ds1\bin\Debug\images\cut.png
?????文件??????15496??2018-09-06?08:45??ds1\bin\Debug\images\datali
?????文件??????15229??2018-09-04?11:22??ds1\bin\Debug\images\datetime.png
?????文件??????16006??2018-09-06?09:41??ds1\bin\Debug\images\del.png
?????文件??????15558??2018-09-06?10:17??ds1\bin\Debug\images\delall.png
?????文件??????15093??2018-09-06?08:48??ds1\bin\Debug\images\exit.png
?????文件??????15290??2018-08-06?14:55??ds1\bin\Debug\images\field.png
?????文件??????16059??2018-08-23?11:09??ds1\bin\Debug\images\font.png
............此處省略128個文件信息
- 上一篇:C#串口調試助手(源碼)
- 下一篇:WPF視頻播放器
評論
共有 條評論