For programmers, especially programmers engaged in information management, report printing is the most troublesome but must do things throughout the programming process, and our common methods is:
First, export database records into Excell;
2. Generate a report file with the report tool such as CrystalReport or ActiveReport and then call it in the program;
Third, print the form directly;
There are many articles on the first method to introduce how to import data table records into Excell and how to control the Excell unit format to make a suitable report, but this method has many inconveniences, one is the user's computer must Installing Excell, which is obviously unreal (of course, the other is another matter), the second is that Excell comes with an ActiveX control, although .NET still supports ActiveX control, but this is obviously not worthless.
For the second method, there is little information related to CrystalReport or ActiveReport, and it is quite complicated, how to make reports to explore themselves.
No one will use for the third method unless you want to prove yourself.
In this case, can we use the powerful features provided by .NET to develop a control similar to Excell? It is actually necessary to develop a control as long as two things, one is to define various attributes and methods, and the other is based on various attributes draw the control interface.
Let's analyze the Excell's structure, Excell presented to us is a table of two-dimensional structures, each line equivalent to a record of the data table, each column equivalent to the field of the data table. However, each unit of Excell has many format control units rendering, which is where Excell is different from DataGrid, so how to achieve different rendering methods for each unit?
First we can define a class name assumption to DATACELL, this class defines a variety of properties such as: background color, text color, text font, alignment, text fold, unit width, unit height, etc., then we define an arraylist object , The name is assumed to be DataRow, a DataRow loads the appropriate number of DATACELL objects, which is equivalent to a row of Excell.
The second step we define an arraylist object, the name is assumed to be DataTable, each DataTable is loaded with a certain number of DATAROW, then this DataTable object is actually a two-dimensional table with a certain number of records, but the unit of this form is different. Format.
The third step is to draw the control interface. In this step we can use Graphics's DrawString, DrawLine, DrawRectangle, powerful feature, and draw a control interface according to the Different formats provided by the DATACELL object.
According to the above idea, the author has compiled a control similar to Excell, although the function is not as strong as Excell, but the general report is enough, do you want to try?
Home address:
Http://www.winfarsoft.com/
Download address: http://www.winfarsoft.com/richcell.exe The following is given below: Define a unit class, defined a number of properties in the class, as for the purpose of the attribute, I want to know, I'm not going to explain here Imports System.Drawing.Drawing2DPublic Class WinFar_Cell Public InitFlag As Boolean Public BorderStyle As WinFar_BorderStyle = WinFar_BorderStyle.Normal Public BackColor As Color = Color.White Public ForeColor As Color = Color.Black Public MergeFlag As Boolean = False Public MergeRows As Integer = 0 Public MergeCols As Integer = 0 Public MergeRowStep As Integer = 0 Public MergeColStep As Integer = 0 Public LeftLineStyle As WinFar_LineStyle = WinFar_LineStyle.None Public TopLineStyle As WinFar_LineStyle = WinFar_LineStyle.None Public RightLineStyle As WinFar_LineStyle = WinFar_LineStyle.None Public BottomLineStyle As WinFar_LineStyle = WinFar_LineStyle.None Public Image As Image = Nothing Public ImageAlignment As WinFar_Alignment = WinFar_Alignment.LeftCenter Public Font As Font = New Font (New FontFamily ( "Song"), 10) Public ShowStyle As WinFar_ShowStyle = W inFar_ShowStyle.Normal Public MultiLineFlag As Boolean = False Public TextAlignment As WinFar_Alignment = WinFar_Alignment.CenterCenter Public TextStyle As WinFar_TextStyle = WinFar_TextStyle.Normal Public Text As String = "" Public LockFlag As Boolean = False Public LoadString As String = "" Public HyperLink As String = "Public Calcexpress As String =" "Public CheckExpress As String =" "" End Class
Step 2: Define a class, inherit system.windows.Forms.Control, why inherit inheritance System.Windows.Forms.Control is not inherited from existing controls because only this can maximize control. Imports System.DrawingImports System.Drawing.TextImports System.Drawing.Drawing2DImports System.CollectionsImports System.ComponentModelPublic Class WinFar_DataSheet 'loading unit Public Sub New (Optional ByVal Rows As Integer = 50, Optional ByVal Cols As Integer = 26) Dim the constructor I As Integer Dim J As Integer Rows = 1000 M_Rows = Rows M_Cols = Cols InitProperty () M_DataTable = New ArrayList () For I = 0 To M_Rows - 1 M_RowitemCollection.Add (M_InitRowitem) M_DataRow = New ArrayList () For J = 0 To M_COLS - 1 if i = 0 THEN M_COLITEMCOLLECTION.ADD (M_INITCOLITEM) end if 'DIM S_CELL AS New Winfar_cell ()' s_cell.initflag = true 'm_datarow.add (s_cell)
M_DataRow.Add (M_InitCell) Next M_DataTable.Add (M_DataRow) NextEnd Sub
M_DataTable = New ArrayList () 'cell row set, each element is an ArrayList class M_DataRow = New ArrayList ()' column set unit, each element is a WinFar_Cell class M_RowitemCollection = New ArrayList () 'set M_ColitemCollection each row height = new ArrayList () 'set M_Rowitem each column width = new WinFar_Rowitem () M_Colitem = new WinFar_Colitem () M_InitRowitem = new WinFar_Rowitem () M_InitColitem = new WinFar_Colitem () M_Row = 0' selection region uppermost, i.e. the current row M_Col = 0 'Select the left column of the area, that is, the most downlink m_endcol = 0' of the current column m_endrow = 0 'selection area, the rightmost M_TOPROW = 0' is the most upstyle, M_LEFTCOL = 0 ', the left side can be seen, the left can be seen in column' m_copystring = "" M_undoopenflag = true m_undotype = new specialized.stringCollection () m_undotable = new arraylist () m_redotype = new specialized.stringCollection () m_redotable = NEW ARRAYLIST () End Sub 'Step 3: Reloading Control's onpaint events, draw the control interface with the various properties and methods of the Grahpics property of the parameter E on OnPAINT events.
Protected Overrides Sub OnPaint (ByVal E As PaintEventArgs) Dim I As Integer Dim J As Integer Dim S_Left As Integer 'Get Left Dim S_Top As units Integer' acquisition unit Top Dim S_Width As Integer 'acquisition unit Width Dim S_Height As Integer' the acquiring unit Height Dim S_Rect As Rectangle 'current cell Rect Dim S_Pen As Pen' pencil printing form lines Dim S_StringFormat As New StringFormat () 'when printing alignment M_Rect off-line text = New Rectangle (M_BorderWidth, M_BorderWidth, ClientRectangle.Width - M_VScrollSize - 2 * M_BorderWidth, ClientRectangle.Height - M_HScrollSize - 2 * M_BorderWidth) M_DataSheet.Rect = m_Rect '' to fill the background 'Select Case M_BackStyle Case WinFar_BackStyle.BackColorStyle' fill color E.Graphics.FillRectangle (New SolidBrush (M_BackColor), m_Rect ) Case Winfar_BackStyle.Backhatchstyle 'Plip Filter E.Graphics.FillRectangle (New Hatchbrush (M_Backhatchst " yle, M_BackHatchColor, M_BackColor), M_Rect) Case WinFar_BackStyle.BackGradientSingleStyle 'gradient fill Dim S_LinearGradientBrush As New LinearGradientBrush (M_Rect, M_BackGradientBeginColor, M_BackGradientEndColor, M_BackGradientAngle) Dim S_RelativeIntensities As Single () = {0.0F, M_BackGradientPercent, 1.0F} Dim S_RelativePositions As Single () = {0.0F, M_BackGradientPosition, 1.0F} Dim S_Blend As New Blend () S_Blend.Factors = S_RelativeIntensities S_Blend.Positions = S_RelativePositions S_LinearGradientBrush.Blend = S_Blend S_LinearGradientBrush.Blend =
S_Blend E.Graphics.FillRectangle (S_LinearGradientBrush, M_Rect) Case WinFar_BackStyle.BackGradientDoubleStyle If M_BackGradientAngle = 0 Then 'fill about two-way gradient Dim S_LinearGradientBrush1 As New LinearGradientBrush (New Rectangle (M_Rect.X, M_Rect.Y, Convert.ToInt32 (M_Rect.Width / 2), M_Rect.Height), M_BackGradientBeginColor, M_BackGradientEndColor, 0) Dim S_LinearGradientBrush2 As New LinearGradientBrush (New Rectangle (M_Rect.X Convert.ToInt32 (M_Rect.Width / 2), M_Rect.Y, M_Rect.Width - Convert.ToInt32 (M_Rect.Width / 2), M_Rect.Height), M_BackGradientBeginColor, M_BackGradientEndColor, 180) Dim S_RelativeIntensities As Single () = {0.0F, M_BackGradientPercent, 1.0F} Dim S_RelativePositions As Single () = {0.0F, M_BackGradientPosition, 1.0F } DIM S_BLEND AS New Blend () s_blend.factors = s_relarativeintensity s_blend.positions = s_relesspositions s_lineargradientbrush1.blend = s _Blend S_LinearGradientBrush1.Blend = S_Blend S_LinearGradientBrush2.Blend = S_Blend S_LinearGradientBrush2.Blend = S_Blend E.Graphics.FillRectangle (S_LinearGradientBrush1, New Rectangle (M_Rect.X, M_Rect.Y, Convert.ToInt32 (M_Rect.Width / 2), M_Rect.Height) ) E.Graphics.FillRectangle (S_LinearGradientBrush2, New Rectangle (M_Rect.X Convert.ToInt32 (M_Rect.Width / 2), M_Rect.Y, M_Rect.Width - Convert.ToInt32 (M_Rect.Width / 2), M_Rect.Height) ) E.Graphics.drawline (new Pen (M_BackGradientendColor), M_Rect.x Convert.Toint32 (M_Rect.width / 2), M_Rect.y, M_Rect.x
Convert.ToInt32 (M_Rect.Width / 2), M_Rect.Bottom) Else 'is filled up and down directions gradient Dim S_LinearGradientBrush1 As New LinearGradientBrush (New Rectangle (M_Rect.X, M_Rect.Y, M_Rect.Width, Convert.ToInt32 (M_Rect.Height / 2)), M_BackGradientBeginColor, M_BackGradientEndColor, 90) Dim S_LinearGradientBrush2 As New LinearGradientBrush (New Rectangle (M_Rect.X, M_Rect.Y Convert.ToInt32 (M_Rect.Height / 2), M_Rect.Width, M_Rect.Height - Convert.ToInt32 (M_Rect.Height / 2)), M_BackGradientBeginColor, M_BackGradientEndColor, 270) Dim S_RelativeIntensities As Single () = {0.0F, M_BackGradientPercent, 1.0F} Dim S_RelativePositions As Single () = {0.0F, M_BackGradientPosition, 1.0F} Dim S_Blend As new Blend () S_Blend.Factors = S_RelativeIntensities S_Blend.Positions = S_RelativePositions S_LinearGradientBrush1.Blend = S_Blend S_LinearGradientBrush1.Blend = S_Blend S_LinearGradientBrush2.Blend = S_Blend S_LinearGradientBrush2.Blend = S_Blend E.Graphics.FillRectangle (S_LinearGradientBrush1, New Rectangle (M_Rect.X, M_Rect.Y, M_Rect.Width, Convert.ToInt32 (M_Rect.Height / 2))) E.Graphics.FillRectangle (S_LinearGradientBrush2, New Rectangle (m_rect.x, m_rect.y convert.toint32 (m_rect.height / 2), m_rect.width, m_rect.height - convert.Toint32 (m_rect.height / 2)) E.Graphics.drawline (New Pen (M_backgradientendcolor), m_rect.x, m_rect.y convert.Toint32 (M_Rect.Height / 2), M_Rect.right, M_Rect.y
Convert.ToInt32 (M_Rect.Height / 2)) End If Case WinFar_BackStyle.BackPathSideStyle Dim S_Path As New GraphicsPath () S_Path.AddRectangle (M_Rect) Dim S_PathGrBrush As New PathGradientBrush (S_Path) S_PathGrBrush.CenterColor = M_BackGradientBeginColor Dim S_EndColor () As Color = {M_BackGradientEndColor} S_PathGrBrush.SurroundColors = S_EndColor If M_BackGradientAngle = 0 Then S_PathGrBrush.CenterPoint = New PointF (M_Rect.X, M_Rect.Y M_Rect.Height / 2) ElseIf M_BackGradientAngle = 45 Then S_PathGrBrush.CenterPoint = New PointF (M_Rect.X, M_Rect.Y) ElseIf M_BackGradientAngle = 90 Then S_PathGrBrush.CenterPoint = New PointF (M_Rect.X M_Rect.Width / 2, M_Rect.Y) ElseIf M_BackGradientAngle = 135 Then S_PathGrBrush.CenterPoint = New PointF (M_Rect.Right, M_Rect.Y) Elseif M_BackGradientangle = 180 THEN S_PATHGRBRUSH.CenterPoint = New Pointf (M _Rect.Right, M_Rect.Y M_Rect.Height / 2) ElseIf M_BackGradientAngle = 225 Then S_PathGrBrush.CenterPoint = New PointF (M_Rect.Right, M_Rect.Bottom) ElseIf M_BackGradientAngle = 270 Then S_PathGrBrush.CenterPoint = New PointF (M_Rect.X M_Rect.Width / 2, M_Rect.Bottom) ElseIf M_BackGradientAngle = 315 Then S_PathGrBrush.CenterPoint = New PointF (M_Rect.X, M_Rect.Bottom) Else S_PathGrBrush.CenterPoint = New PointF (M_Rect.X (M_Rect.Right - M_Rect.X ) / 2, m_rect.y
(M_Rect.Bottom - M_Rect.Y) / 2) End If E.Graphics.FillRectangle (S_PathGrBrush, M_Rect) Case WinFar_BackStyle.BackPathCenterStyle Dim S_Path As New GraphicsPath () S_Path.AddRectangle (M_Rect) Dim S_PathGrBrush As New PathGradientBrush (S_Path) S_PathGrBrush .CenterColor = M_BackGradientBeginColor Dim S_EndColor () As Color = {M_BackGradientEndColor} S_PathGrBrush.SurroundColors = S_EndColor S_PathGrBrush.CenterPoint = New PointF (M_Rect.X (M_Rect.Right - M_Rect.X) / 2, M_Rect.Y (M_Rect.Bottom - M_Rect.Y) / 2) E.Graphics.FillRectangle (S_PathGrBrush, m_Rect) Case WinFar_BackStyle.BackImageStyle 'filled image: the image tile If Not M_BackImage Is Nothing Then E.Graphics.FillRectangle (New TextureBrush (M_BackImage), m_Rect ) End if End select '' Draw Copyright Information 'S_StringFormat.Alignment = StringAlignment.Center S_StringFormat.LineAlignment = StringAlignment.Center E.Graphics.Textrend eringHint = TextRenderingHint.AntiAlias E.Graphics.DrawString ( "Winfarsoft Foxcell", New Font (New FontFamily ( "Times New Roman"), 32), New SolidBrush (Color.WhiteSmoke), New RectangleF (M_Rect.X, M_Rect.Y - 80, m_rect.width, m_rect.height, s_stringformat) E.Graphics.drawstring ("1992 ~ 2004", New Font (New FontFamily ("Times New Roman"), 32), New Solidbrush (color.whitesmoke), new RectangleF (M_Rect.X, M_Rect.Y, M_Rect.Width, M_Rect.Height), S_StringFormat) E.Graphics.DrawString ( "Copyright (C) LiangZhongQi", new Font (new FontFamily ( "Times new Roman"), 32 ), New Solidbrush, New Rectanglef (M_Rect.x, M_Rect.y
80, M_Rect.Width, M_Rect.Height), S_StringFormat) E.Graphics.TextRenderingHint = TextRenderingHint.SystemDefault '' drawn table cell 'Dim S_FixedWidth As Integer Dim S_FixedHeight As Integer S_FixedHeight = M_Rect.Y M_DataSheet.GetFixedHeight () S_FixedWidth = M_Rect .X M_DataSheet.GetFixedWidth () If M_BorderStyle = WinFar_BorderStyle.BorderEmbossStyle Then If M_DataSheet.FixedRows> 0 Then M_DataSheet.DrawFixedCols (E.Graphics, 0, M_DataSheet.FixedRows - 1, M_Rect.Y M_DataSheet.FixedHeight * M_DataSheet.Zoom, True) M_DataSheet.DrawCell (E.Graphics, 0, M_DataSheet.LeftCol, M_DataSheet.FixedRows - 1, M_DataSheet.Cols - 1, S_FixedWidth, M_Rect.Y M_DataSheet.FixedHeight * M_DataSheet.Zoom, M_EditingFlag) End If If M_DataSheet.FixedCols > 0 Then M_DataSheet.DrawFixedRows (E.Graphics, 0, M_DataSheet.FixedCols - 1, M_Rect.X M_DataSheet.FixedWidth * M_DataSheet.Zoom, True) M_DataSheet.DrawCell (E.Graphics, M_DataSheet.TopRow, 0, M_Da taSheet.Rows - 1, M_DataSheet.FixedCols - 1, M_Rect.X M_DataSheet.FixedWidth * M_DataSheet.Zoom, S_FixedHeight, M_EditingFlag) End If If M_DataSheet.FixedRows> 0 And M_DataSheet.FixedCols> 0 Then M_DataSheet.DrawCell (E.Graphics , 0, 0, M_DataSheet.FixedRows - 1, M_DataSheet.FixedCols - 1, M_Rect.X M_DataSheet.FixedWidth * M_DataSheet.Zoom, M_Rect.Y M_DataSheet.FixedHeight * M_DataSheet.Zoom, M_EditingFlag) End If '' non-fixed drawing Unit 'm_datasheet.drawcell (E.Graphics, m_datasheet.toprow, m_datasheet.llcol, m_datasheet.rows - 1, m_datasheet.cols - 1, s_fixedwidth, s_fixedheight, m_editingflag)' '
Draw the header unit 'If M_DataSheet.FixedWidth> 0 Then M_DataSheet.DrawFixedCols (E.Graphics, M_DataSheet.TopRow, M_DataSheet.Rows - 1, S_FixedHeight, True) End If If M_DataSheet.FixedHeight> 0 Then M_DataSheet.DrawFixedRows (E.Graphics , M_DataSheet.LeftCol, M_DataSheet.Cols - 1, S_FixedWidth, True) End If If M_DataSheet.FixedWidth> 0 And M_DataSheet.FixedHeight> 0 Then M_DataSheet.DrawConner (E.Graphics, True) End If Else 'drawing the upper fixing unit If M_DataSheet .FixedRows> 0 Then M_DataSheet.DrawFixedCols (E.Graphics, 0, M_DataSheet.FixedRows - 1, M_Rect.Y M_DataSheet.FixedHeight * M_DataSheet.Zoom, False) M_DataSheet.DrawCell (E.Graphics, 0, M_DataSheet.LeftCol, M_DataSheet .FixedRows - 1, M_DataSheet.Cols - 1, S_FixedWidth, M_Rect.Y M_DataSheet.FixedHeight * M_DataSheet.Zoom, M_EditingFlag) End If 'left drawing fixing unit If M_DataSheet.FixedCols> 0 Then M_DataSheet.DrawFixedRows (E.Graphics, 0 , M_datasheet.fixedc ols - 1, M_Rect.X M_DataSheet.FixedWidth * M_DataSheet.Zoom, False) M_DataSheet.DrawCell (E.Graphics, M_DataSheet.TopRow, 0, M_DataSheet.Rows - 1, M_DataSheet.FixedCols - 1, M_Rect.X M_DataSheet. FixedWidth * M_DataSheet.Zoom, S_FixedHeight, M_EditingFlag) End If 'upper left corner of the fixing unit drawing If M_DataSheet.FixedRows> 0 And M_DataSheet.FixedCols> 0 Then M_DataSheet.DrawCell (E.Graphics, 0, 0, M_DataSheet.FixedRows - 1, M_DataSheet .Fixedcols - 1, m_rect.x m_datasheet.fixedwidth * m_datasheet.zoom, m_rect.y m_datasheet.fixedHeight * m_datasheet.zoom, m_editingflag) end if '
Non-fixed bottom right drawing unit M_DataSheet.DrawCell (E.Graphics, M_DataSheet.TopRow, M_DataSheet.LeftCol, M_DataSheet.Rows - 1, M_DataSheet.Cols - 1, S_FixedWidth, S_FixedHeight, M_EditingFlag) '' draw the head unit 'If M_DataSheet. FixedWidth> 0 Then M_DataSheet.DrawFixedCols (E.Graphics, M_DataSheet.TopRow, M_DataSheet.Rows - 1, S_FixedHeight, False) End If If M_DataSheet.FixedHeight> 0 Then M_DataSheet.DrawFixedRows (E.Graphics, M_DataSheet.LeftCol, M_DataSheet.Cols - 1, s_fixedwidth, false) end if if m_datasheet.fixedwidth> 0 and m_datasheet.fixedHeight> 0 THEN M_DATASHEET.DRAWCONNER (E.GRAPHICS, FALSE) End if end if '' When the mouse moves, draw a variety of temporary lines or temporary rectangular 'Select Case M_MouseState Case WinFar_MouseState.ResizeColing S_Pen = New Pen (Color.Gray) S_Pen.DashStyle = DashStyle.Dash E.Graphics.DrawLine (S_Pen, M_RBPoint.X, 0, M_RBPoint.X, Me.Height) Case WinFar_MouseState. Resizerowing s_pen = new pen (color.gray) S_pen.dashstyle = dashstyle.dash E.Graphics.drawline (s_pen, 0, m_rbpoint.y, me.width, m_rbpoint.y) case winfar_mousestate.drawlineing if math.abs (m_rbpoint.x - m_ltpoint.x)> Math.Abs (M_rbpoint.y - m_ltpoint.y) THEN E.Graphics.drawline (New Pen (Color.Blue, 3), M_ltpoint, New Point (M_RBPoint.x, M_Ltpoint.y)) Else E.Graphics.drawline (New Pen Color.Blue, 3), M_Ltpoint, New Point (m_ltpoint.x, m_rbpoint.y)) end if case winfar_mousestate.delelineing if math.abs (m_rbpoint.x - m_ltpoint.x)>
Math.abs (m_rbpoint.y - m_ltpoint.y) THEN E.GRAPHICS.DRAWLINE (New Pen (Color.Red, 3), M_ltpoint, New Point (M_RBPoint.x, M_Ltpoint.y)) Else E.Graphics.drawline ( new Pen (Color.Red, 3), M_LTPoint, new Point (M_LTPoint.X, M_RBPoint.Y)) End If Case WinFar_MouseState.MoveRowing M_DataSheet.DrawDragRow (E.Graphics, M_EndRow) Case WinFar_MouseState.MoveColing M_DataSheet.DrawDragCol (E. Graphics, M_EndCol) Case WinFar_MouseState.MoveCelling M_DataSheet.DrawDragCell (E.Graphics, M_EndRow, M_EndCol, M_DataSheet.EndRow - M_DataSheet.Row, M_DataSheet.EndCol - M_DataSheet.Col) Case WinFar_MouseState.CopyFormating 'border drawing source unit S_Left = M_DataSheet.GetCellLeft (M_DataSheet.Col) M_Rect.X S_Top = M_DataSheet.GetCellTop (M_DataSheet.Row) M_Rect.Y S_Pen = New Pen (Color.Black) S_Pen.DashStyle = DashStyle.Dash S_Rect = New Rectangle (S_Left, S_Top, M_DataSheet. COLWIDTH (m_datasheet.col) * M_DataSheet.Zoom, M_DataSheet.RowHeight (M_DataSheet.Row) * M_DataSheet.Zoom) E.Graphics.DrawRectangle (New Pen (Color.White), S_Rect) E.Graphics.DrawRectangle (S_Pen, S_Rect) S_Rect = New Rectangle (S_Left 1, s_top 1, m_datasheet.colwidth (m_datasheet.col) * m_datasheet.zoom - 2, m_datasheet.rowheight (m_datasheet.row) * m_datasheet.zoom - 2) E.Graphics.drawRectangle (S_PEN, S_RECT) '
Draw frame selection unit M_DataSheet.DrawDragCell (E.Graphics, M_Row, M_Col, M_EndRow - M_Row, M_EndCol - M_Col) Case WinFar_MouseState.DrawShapeing E.Graphics.DrawRectangle (New Pen (Color.Gray), M_LTPoint.X, M_LTPoint.Y, M_RBPoint.X - M_LTPoint.X, M_RBPoint.Y - M_LTPoint.Y) Case WinFar_MouseState.DrawCharting E.Graphics.DrawRectangle (New Pen (Color.Gray), M_LTPoint.X, M_LTPoint.Y, M_RBPoint.X - M_LTPoint.X, M_RBPoint.Y - M_LTPoint.Y) End Select '' drawing page tab bar 'If M_DataLabelFlag = True Then' OK filled rectangle S_Rect = New rectangle (M_BorderWidth, ClientRectangle.Bottom - M_BorderWidth - 18, ClientRectangle.Width - M_BorderWidth, 18) E.Graphics.FillRectangle (New HatchBrush (HatchStyle.Percent50, M_DataSheet.FixedBackColor, Color.White), S_Rect) 'first button S_Rect = New Rectangle (M_BorderWidth, S_Rect.Top, 17, 18) M_DataSheet.DrawButton (E. Graphics, s_rect, 1) 'Second button S_RECT = New Rectangle (S_Rect.Right 1, S_Rect.top, 17, 18) m_datasheet .DrawButton (E.GRAPHICS, S_RECT, 2) 'The third button S_RECT = New Rectangle (s_rect.right 1, s_rect.top, 17, 18) m_datasheet.drawButton (E.GRAPHICS, S_RECT, 3)' fourth Button s_rect = new Rectangle (S_Rect.Right 1, S_Rect.top, 17, 18) m_datasheet.drawButton (E.GRAPHICS, S_RECT, 4) 'Draw Tag' DIM S_POINTS (3) AS PointF Dim S_Font AS Font DIM S_LightColor As Color = M_DataSheet.GetLightColor (M_DataSheet.FixedBackColor) Dim S_DarkColor As Color = M_DataSheet.GetDarkColor (M_DataSheet.FixedBackColor) S_Font = New Font (New FontFamily ( "Song"), 9) S_StringFormat.LineAlignment =
StringAlignment.Center S_StringFormat.Alignment = StringAlignment.Center S_StringFormat.FormatFlags = StringFormatFlags.NoWrap S_Left = M_BorderWidth 72 For I = M_LeftMember To M_DataLabel.Count - 1 S_Width = E.Graphics.MeasureString (M_DataLabel (I), S_Font) .Width 4 S_Points (0) = New PointF (S_Left, ClientRectangle.Bottom - M_BorderWidth - 18) S_Points (1) = New PointF (S_Left 17, ClientRectangle.Bottom - M_BorderWidth - 1) S_Points (2) = New PointF (S_Left s_Width 17, ClientRectangle.Bottom - M_BorderWidth - 1) S_Points (3) = New PointF (S_Left s_Width 17 17, ClientRectangle.Bottom - M_BorderWidth - 18) E.Graphics.FillPolygon (New SolidBrush (M_DataSheet.FixedBackColor), S_Points ) E.Graphics.DrawPolygon (New Pen (Color.Black), S_Points) S_Rect = New Rectangle (S_Left 17, ClientRectangle.Bottom - M_BorderWidth - 18, s_Width, 18) E.Graphics.DrawString (M_DataLabel (I), S_Font New Solidbrush (C olor.Black), New RectangleF (S_Rect.X 2, S_Rect.Y 2, S_Rect.Width, S_Rect.Height), S_StringFormat) S_Left = S_Left S_Width 17 If M_Scrollbars = WinFar_Scrollbars.None Then If S_Left> = ClientRectangle .Width - M_BorderWidth Then Exit For End If ElseIf M_Scrollbars = WinFar_Scrollbars.Vertical Then If S_Left> = ClientRectangle.Width - M_HScrollSize - M_BorderWidth Then Exit For End If ElseIf M_Scrollbars = WinFar_Scrollbars.Horizontal Or M_Scrollbars = WinFar_Scrollbars.Both Then If S_Left> =
ClientRectangle.Width * 0.75 Then Exit For End If End If Next 'to draw current label S_Left = M_BorderWidth 72 For I = M_LeftMember To M_DataLabel.Count - 1 S_Width = E.Graphics.MeasureString (M_DataLabel (I), S_Font) .Width 4 If I = M_DataMember Then S_Points (0) = New PointF (S_Left, ClientRectangle.Bottom - M_BorderWidth - 18) S_Points (1) = New PointF (S_Left 17, ClientRectangle.Bottom - M_BorderWidth - 1) S_Points (2) = New PointF (S_Left s_Width 17, ClientRectangle.Bottom - M_BorderWidth - 1) S_Points (3) = New PointF (S_Left s_Width 17 17, ClientRectangle.Bottom - M_BorderWidth - 18) E.Graphics.FillPolygon (New SolidBrush (S_LightColor ), S_Points) E.Graphics.DrawPolygon (New Pen (Color.Black), S_Points) S_Rect = New Rectangle (S_Left 17, ClientRectangle.Bottom - M_BorderWidth - 18, s_Width, 18) E.Graphics.DrawString (M_DataLabel (I ), S_fon T, New Solidbrush, New Rectanglef (S_Rect.x 2, S_Rect.y 2, S_Rect.width, S_Rect.Height), S_StringFormat) EXIT for end if s_left = s_left s_width 17 next ' data label to the right of the button 'If M_Scrollbars = WinFar_Scrollbars.None Then S_Rect = New Rectangle (ClientRectangle.Width - M_BorderWidth - 7, S_Rect.Top, 6, 18) ElseIf M_Scrollbars = WinFar_Scrollbars.Vertical Then S_Rect = New Rectangle (ClientRectangle.Width - M_HScrollSize - M_BorderWidth - 7, S_Rect.top, 6, 18) Elseif M_Scrollbars =
WinFar_Scrollbars.Horizontal Or M_Scrollbars = WinFar_Scrollbars.Both Then S_Rect = New Rectangle (ClientRectangle.Width * 0.75 - 7, S_Rect.Top, 6, 18) End If E.Graphics.FillRectangle (New SolidBrush (M_DataSheet.FixedBackColor), S_Rect) M_DataSheet .DrawButton (E.Graphics, S_Rect, 0) End If '' to draw the bottom right 'If M_HScrollSize = 18 And M_VScrollSize = 18 Then E.Graphics.FillRectangle (New SolidBrush (Color.FromKnownColor (KnownColor.Control)), New Rectangle ( ClientRectangle.Width - M_BorderWidth - 18, ClientRectangle.Height - M_BorderWidth - 18, 18, 18)) End If '' draw frame control 'Select Case BorderStyle Case WinFar_BorderStyle.BorderSingle E.Graphics.DrawRectangle (New Pen (Color.Black), new Rectangle (0, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1)) Case WinFar_BorderStyle.BorderEmbossStyle 'left E.Graphics.DrawLine (new Pen (M_DataSheet.GetDarkColor (M_DataSheet.FixedBackColor)), 0, 0, 0 ClientRectangle.height) E. Graphics.DrawLine (New Pen (M_DataSheet.GetLightColor (M_DataSheet.FixedBackColor)), 1, 0, 1, ClientRectangle.Height) 'on E.Graphics.DrawLine (New Pen (M_DataSheet.GetDarkColor (M_DataSheet.FixedBackColor)), 0, 0, ClientRectangle.Width, 0) E.Graphics.DrawLine (New Pen (M_DataSheet.GetLightColor (M_DataSheet.FixedBackColor)), 1, 1, ClientRectangle.Width, 1) 'Right E.Graphics.DrawLine (New Pen (Color. FromKnownColor (KnownColor.Control)), ClientRectangle.Width - 2, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 3) E.Graphics.DrawLine (New Pen (Color.White), ClientRectangle.Width - 1, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1) '
Under E.Graphics.DrawLine (New Pen (Color.FromKnownColor (KnownColor.Control)), 1, ClientRectangle.Height - 2, ClientRectangle.Width - 2, ClientRectangle.Height - 2) E.Graphics.DrawLine (New Pen (Color .White), 0, ClientRectangle.Height - 1, ClientRectangle.Width - 1, ClientRectangle.Height - 1) Case WinFar_BorderStyle.BorderIn3DStyle, WinFar_BorderStyle.BorderOut3DStyle 'on E.Graphics.DrawLine (New Pen (Color.Silver), 0, 0, ClientRectangle.width, 0) E.Graphics.drawline (New Pen (Color.Black), 1, 1, ClientRectangle.Width, 1) 'E.Graphics.drawline (New Pen (Color.Black), 1, 2 ClientRectangle.Width, 2) 'Left E.Graphics.drawline (New Pen (Color.Silver), 0, 0, 0, ClientRectangle.Height) E.Graphics.drawline (New Pen (Color.Black), 1, 1 , 1, ClientRectangle.height) 'E.Graphics.drawline (New Pen (Color.Black), 2, 1, 2, ClientRectangle.height)' under E.Graphics.drawline (New Pen (Color.FromknownColor (Knowncolor.Control) )), 1, c lientRectangle.Height - 2, ClientRectangle.Width - 2, ClientRectangle.Height - 2) E.Graphics.DrawLine (New Pen (Color.White), 0, ClientRectangle.Height - 1, ClientRectangle.Width - 1, ClientRectangle.Height - 1) 'Right E.Graphics.DrawLine (New Pen (Color.FromKnownColor (KnownColor.Control)), ClientRectangle.Width - 2, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 3) E.Graphics.DrawLine (New Pen (color.White), ClientRectangle.Width - 1, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1) End SelectenD Subend Class to this control is complete, of course, the above code cannot be executed, because here just provide one Thinking, there is still a lot of things to do with a real complete control.
If you are interested, we can communicate, discuss together, and improve them together.
There is no corresponding code in the previous "development of its own Excell Control", some code will be given here.
The first step: Define a unit class, define a lot of properties in the class, as for the purpose of the attribute, I think everyone will know, I will not explain the imports system.drawing.drawing2d here.
Public Class Winfar_Cell
Public Initflag As Boolean
Public BorderStyle AS Winfar_Borderstyle = Winfar_Borderstyle.Normal
Public Backcolor As Color = Color.White
Public Forecolor As Color = Color.Black
Public mergeflag as boolean = false
Public mergerows as integer = 0
Public mergecols as integer = 0
Public mergerowstep as integer = 0
Public mergecolstep as integer = 0
Public LeftlineStyle AS Winfar_LinesTyle = Winfar_LineStyle.none
Public ToplinesTyle AS Winfar_LineStyle = Winfar_LineStyle.none
Public RightLineStyle AS Winfar_LineStyle = Winfar_LineStyle.none
Public BottomlineStyle AS Winfar_LinesTyle = Winfar_LineStyle.none
Public image as image = Nothing
Public imageAlignment as winfar_alignment = winfar_alignment.LeftCenter
Public font as font = new font (New Fontfamily ("Song Body"), 10)
Public showstyle as winfar_showstyle = winfar_showstyle.normal
Public multilineflag as boolean = false
PUBLIC TEXTALIGNMENT AS WINFAR_ALIGNMENT = Winfar_Alignment.centerCenter
Public textStyle as winfar_textStyle = Winfar_TextStyle.Normal
Public text as string = "" "
Public lockflag as boolean = false
Public loadstring as string = ""
Public hyperlink as string = ""
Public cavercexpress as string = ""
Public checkexpress as string = ""
END CLASS
Step 2: Define a class, inherit system.windows.forms.control, why do you want to continue?
System.windows.Forms.Control is not inherited from existing controls because only this can we maximize control.
Imports system.drawing
Imports system.drawing.text
Imports system.drawing.drawing2d
Imports System.collectionsimports System.comPonentmodel
Public class winfar_datasheet
'Loading a unit in the constructor
Public Sub New (Optional Byval Rows As Integer = 50, Optional Byval COLS AS INTEGER = 26)
DIM I as integer
DIM J AS INTEGER
ROWS = 1000
M_ROWS = ROWS
M_cols = cols
INitproperty ()
M_dataable = new arraylist ()
For i = 0 to m_rows - 1
M_RowItemCollection.add (m_initrowItem)
M_datarow = new arraylist ()
For j = 0 to m_cols - 1
IF i = 0 THEN
M_colitemcollection.add (m_initcolitem)
END IF
'DIM S_CELL AS New Winfar_Cell ()
'S_cell.initflag = true
'M_datarow.add (s_cell)
M_datarow.add (m_initcell)
NEXT
M_dataable.add (m_datarow)
NEXT
End Sub
Public subinitproperty ()
M_zoom = 1
M_password = "" "
M_gridvisibledflag = true
M_gridcolor = color.black
M_gridstyle = dashstyle.dot
M_selectbackcolor = color.fromargb (88, 148, 158, 168)
M_selectforecolor = color.black
M_lockbackcolor = color.fromknowncolor (knowncolor.control)
M_lockforecolor = color.gray
M_calcbackcolor = color.transparent
M_calcforecolor = color.green
M_hyperlinkbackcolor = color.transparent
M_hyperlinkforecolor = color.black
M_defaultbackcolor = color.transparent
M_defaultforecolor = color.black
M_LineColor = color.black
M_accountcount = 10
M_decimalcount = 2
M_initcell = new winfar_cell ()
M_fixed3dstyleflag = true
M_fixedforecolor = color.black
M_fixedbackcolor = color.fromknowncolor (knowncolor.control)
'Fixed unit dark color
M_fixeddarkcolor = getDarkColor (m_fixedbackcolor)
'Fixing in the fixed unit color
M_fixedmiddlecolor = getMiddleColor (m_fixedbackcolor) 'fixed unit light colors
M_fixedlightcolor = getlightcolor (m_fixedbackcolor)
IF M_ROWS <10000 THEN
M_fixedwidth = 35
Else
M_fixedwidth = 42
END IF
M_fixedheight = 26
M_fixedtextStyle = Winfar_TextStyle.raiad3DStyle
M_fixedfont = new font (New Fontfamily ("Song Body"), 10)
M_fixedrows = 0
M_fixedcols = 0
M_datatable = new arraylist () 'Unit line collection, each element is an ArrayList class
M_datarow = new arraylist () 'single column collection, each element is a Winfar_Cell class
M_RowItemCollection = new arraylist () 'Each line of heights
M_colitemcollection = new arraylist () 'Collection of each column width
M_RowItem = New Winfar_RowItem ()
M_colitem = new winfar_colitem ()
M_initrowItem = new Winfar_RowItem ()
M_initcolitem = new winfar_colitem ()
M_row = 0 'Selecting the most upstream of the area, that is, the current line
M_col = 0 'Select the leftmost column of the area, that is, the current column
M_ENDROW = 0 'The most downlink of the selection area
M_endcol = 0 'The rightmost right of the selection area
M_toprow = 0 'is the top edge
M_LEFTCOL = 0 'The left side can be seen
'
M_copystring = "" "
M_undoopenflag = true
M_undotype = new specialized.stringcollection ()
M_undotable = new arraylist ()
M_redotype = new specialized.stringcollection ()
M_redotable = new arraylist ()
End Sub
'Step 3: Rebate the Control onPaint Event, draw controls and methods for the various properties and methods of the grahpics attribute in the onpaint event
interface.
Protected Overrides Sub onpaint (Byval E As PainteventArgs)
DIM I as integer
DIM J AS INTEGER
DIM S_LEFT AS INTEGER 'Gets Left of Unit
DIM S_TOP AS INTEGER 'Get TOP of the unit
DIM S_WIDTH AS INTEGER 'Gets Width
DIM S_HEIGHT AS INTEGER 'Getting the HEIGHT of the Unit
DIM S_RECT AS Rectangle 'current unit's RECT
DIM S_PEN AS PEN 'Print Pencil
DIM S_STRINGFORMAT AS New StringFormat () 'Mandatory When printing a folding text
M_rect = new rectangle (m_borderwidth, m_borderwidth, clientRectangle.width - m_vscrollsize -
2 * m_borderwidth, clientRectangle.Height - M_HScrollsize - 2 * m_borderwidth)
M_datasheet.rect = m_Rect
'
'Padding background
'
SELECT CASE M_BACKSTYLELELELELELELE
Case winfar_backstyle.backcolorstyle
'Filling color
E.Graphics.FillRectangle (New Solidbrush (M_BackColor), M_Rect)
Case Winfar_BackStyle.Backhatchstyle
'Filling shading
E.Graphics.FillRectangle (New Hatchbrush (M_Backhatchstyle, M_Backhatchcolor,
M_backcolor, m_rect)
Case Winfar_BackStyle.BackGradientSingleStyle
'Filling gradient
DIM S_LINEARGRADIENTBRUSH AS New LineargradientBrush (M_Rect, M_BackGradientBegincolor,
M_backgradientendColor, M_BackGradientangle)
DIM S_RELATIVEINTENSITIES AS SINGLE () = {0.0F, M_BackGradientPercent, 1.0F}
DIM S_RELATIVEPOSITIONS AS SINGLE () = {0.0F, M_BackGradientPosition, 1.0F}
DIM S_BLEND AS New Blend ()
S_blend.factors = s_relarativeintensities
S_blend.positions = s_relaitypositions
S_LinearGradientBrush.blend = S_BLEND
S_LinearGradientBrush.blend = S_BLEND
E.Graphics.FillRectangle (S_LineargradientBrush, M_Rect)
Case Winfar_BackStyle.BackGradientDouBleStyle
IF m_backgradientangle = 0 THEN
'Fill left and right two-way gradient
DIM S_LINEARGRADIENTBRUSH1 AS New LineargradientBrush (New Rectangle (M_Rect.x,
M_rect.y, convert.toint32 (m_rect.width / 2), m_rect.height), M_BackGradientBegincolor,
M_backgradientendcolor, 0)
DIM S_LINEARGRADIENTBRUSH2 AS New LineargradientBrush (New Rectangle (M_Rect.x
Convert.TOINT32 (M_Rect.Width / 2), M_Rect.y, M_Rect.Width - Convert.Toint32 (M_Rect.Width / 2),
M_rect.height), M_BackGradientBegincolor, M_BackGradientendColor, 180)
DIM S_RELATIVEINTENSITIES AS SINGLE () = {0.0F, M_BackGradientPercent, 1.0F} DIM S_RELATIVEPOSITIONS AS SINGLE () = {0.0F, M_BackGradientPosition, 1.0F}
DIM S_BLEND AS New Blend ()
S_blend.factors = s_relarativeintensities
S_blend.positions = s_relaitypositions
S_LinearGradientBrush1.blend = s_blend
S_LinearGradientBrush1.blend = s_blend
S_LinearGradientBrush2.blend = s_blend
S_LinearGradientBrush2.blend = s_blend
E.Graphics.FillRectangle (S_LineargradientBrush1, New Rectangle (m_rect.x, m_rect.y,
Convert.TOINT32 (M_Rect.width / 2), M_Rect.Height)))
E.Graphics.FillRectangle (S_LineargradientBrush2, New Rectangle (M_Rect.x
Convert.TOINT32 (M_Rect.Width / 2), M_Rect.y, M_Rect.Width - Convert.Toint32 (M_Rect.Width / 2),
M_rect.height))))
E.Graphics.drawline (new pen (m_backgradientendcolor), m_rect.x
Convert.TOINT32 (M_Rect.width / 2), M_Rect.y, M_Rect.x Convert.Toint32 (M_Rect.Width / 2),
M_rect.bottom)
Else
'Fill up and down two-way gradient
DIM S_LINEARGRADIENTBRUSH1 AS New LineargradientBrush (New Rectangle (M_Rect.x,
M_Rect.y, M_Rect.Width, Convert.Toint32 (M_Rect.Height / 2)), M_BackGradientBegincolor,
M_BackGradientendColor, 90)
DIM S_LINEARGRADIENTBRUSH2 AS New LineargradientBrush (New Rectangle (M_Rect.x,
M_rect.y convert.Toint32 (m_rect.height / 2), m_rect.width, m_rect.height -
Convert.TOINT32 (M_Rect.Height / 2)), M_BackGradientBegincolor, M_BackGradientendColor, 270)
DIM S_RELATIVEINTENSITIES AS SINGLE () = {0.0F, M_BackGradientPercent, 1.0F}
DIM S_RELATIVEPOSITIONS AS SINGLE () = {0.0F, M_BackGradientPosition, 1.0F}
DIM S_BLEND AS New Blend ()
S_blend.factors = s_relarativeintensities
S_blend.positions = s_relaitypositions
S_LINEARGRADIENTBRUSH1.BLEND = S_BLENDS_LINEARGRADIENTBRUSH1.BLEND = S_BLEND
S_LinearGradientBrush2.blend = s_blend
S_LinearGradientBrush2.blend = s_blend
E.Graphics.FillRectangle (S_LineargradientBrush1, New Rectangle (m_rect.x, m_rect.y,
M_rect.width, convert.Toint32 (M_Rect.Height / 2))))))))
E.Graphics.FillRectangle (S_LineargradientBrush2, New Rectangle (m_rect.x, m_rect.y
Convert.TOINT32 (M_Rect.Height / 2), M_Rect.Width, M_Rect.Height - Convert.Toint32 (M_Rect.height
/ 2)))
E.Graphics.drawline (New Pen (M_BackGradientendColor), M_Rect.x, M_Rect.y
Convert.TOINT32 (M_Rect.Height / 2), M_Rect.right, M_Rect.y Convert.Toint32 (M_Rect.Height /
2))
END IF
Case Winfar_BackStyle.BackPathidestyle
DIM S_PATH AS New GraphicsPath ()
S_Path.AddRectangle (M_Rect)
DIM S_PATHGRBRUSH AS NEW PATHGRADIENTBRUSH (S_PATH)
S_pathgrbrush.centercolor = m_backgradientbegincolor
DIM S_ENDCOLOR () as color = {m_backgradientendcolor}
S_pathgrbrush.surroundcolors = s_endcolor
IF m_backgradientangle = 0 THEN
S_pathgrbrush.centerpoint = new pointf (m_rect.x, m_rect.y m_rect.Height / 2)
Elseif M_BackGradientangle = 45 THEN
S_pathgrbrush.centerpoint = new pointf (m_rect.x, m_rect.y)
Elseif M_BackGradientangle = 90 THEN
S_pathgrbrush.centerpoint = new pointf (m_rect.x m_rect.width / 2, m_rect.y)
Elseif M_BackGradientangle = 135 THEN
S_pathgrbrush.centerpoint = new pointf (m_rect.right, m_rect.y)
Elseif M_BackGradientangle = 180 THEN
S_pathgrbrush.centerpoint = new pointf (m_rect.right, m_rect.y m_rect.Height / 2)
Elseif M_BackGradientangle = 225 THEN
S_pathgrbrush.centerpoint = new pointf (m_rect.right, m_rect.berttom)
Elseif M_BackGradientangle = 270 THENS_PATHGRBRUSH.CenterPoint = New PointF (m_rect.x m_rect.width / 2, m_rect.bottom)
Elseif M_BackGradientangle = 315 THEN
S_pathgrbrush.centerpoint = new pointf (m_rect.x, m_rect.bottom)
Else
S_pathgrbrush.centerpoint = new pointf (m_rect.x (m_rect.right - m_Rect.x) / 2,
M_rect.y (m_rect.bottom - m_rect.y) / 2)
END IF
E.Graphics.FillRectangle (S_Pathgrbrush, M_Rect)
Case Winfar_BackStyle.BackPathCenterStyle
DIM S_PATH AS New GraphicsPath ()
S_Path.AddRectangle (M_Rect)
DIM S_PATHGRBRUSH AS NEW PATHGRADIENTBRUSH (S_PATH)
S_pathgrbrush.centercolor = m_backgradientbegincolor
DIM S_ENDCOLOR () as color = {m_backgradientendcolor}
S_pathgrbrush.surroundcolors = s_endcolor
S_pathgrbrush.centerpoint = new pointf (m_rect.x (m_rect.right - m_Rect.x) / 2,
M_rect.y (m_rect.bottom - m_rect.y) / 2)
E.Graphics.FillRectangle (S_Pathgrbrush, M_Rect)
Case Winfar_BackStyle.BackImageStyle
'Padding image: image tile
IF not m_backimage is nothing then
E.Graphics.FillRectangle (New Texturebrush, M_Rect)
END IF
End SELECT
'
'Draw copyright information
'
S_StringFormat.Alignment = stringalignment.center
S_StringFormat.LineAlignment = StringAlignment.Center
E.Graphics.TextRenderingHint = TextRenderingHint.ntialias
E.Graphics.drawstring ("Winfarsoft Foxcell", New Font Font (New FontFamily ("Times New Roman"), 32),
New solidbrush (color.whitesmoke), New Rectanglef (M_Rect.x, M_Rect.y - 80, M_Rect.width,
M_rect.height), S_StringFormat)
E.Graphics.drawstring ("1992 ~ 2004", New Font (New FontFamily ("Times New Roman"), 32), New
Solidbrush (color.whitesmoke), New Rectanglef (m_rect.x, m_rect.y, m_rect.width, m_rect.Height), S_StringFormat
E.Graphics.drawstring ("Copyright (C) Liangzhongqi, New Font (New FontFamily (" TIMES New
Roman "), 32), New Solidbrush (color.whitesmoke), New Rectanglef (m_rect.x, m_rect.y 80,
M_rect.width, m_rect.height), s_stringformat)
E.Graphics.TextRenderingHint = TextRenderingHint.systemdefault
'
'Draw Table Unit
'
DIM S_FIXEDWIDTH AS INTEGER
DIM S_FIXEDHEIGHT AS INTEGER
S_fixedheight = m_rect.y m_datasheet.GetFixedHeight ()
S_fixedwidth = m_rect.x m_datasheet.getfixedwidth ()
IF m_borderstyle = winfar_borderstyle.borderembossstyle thein
IF m_datasheet.fixedrows> 0 THEN
M_datasheet.drawfixedcols (E.Graphics, 0, M_Datasheet.fixedRows - 1, M_Rect.Y
M_datasheet.fixedheight * m_datasheet.zoom, true)
M_datasheet.drawcell (E.Graphics, 0, M_Datasheet.leftcol, m_datasheet.fixedrows - 1,
M_Datasheet.cols - 1, s_fixedwidth, m_rect.y m_datasheet.fixedHeight * m_datasheet.zoom,
M_editingflag)
END IF
IF m_datasheet.fixedcols> 0 THEN
M_datasheet.drawfixedRows (E.Graphics, 0, M_Datasheet.fixedCOLS - 1, M_RECT.X
M_datasheet.fixedwidth * m_datasheet.zoom, true)
M_datasheet.drawcell (E.Graphics, m_datasheet.toprow, 0, m_datasheet.rows - 1,
M_Datasheet.fixedcols - 1, m_rect.x m_datasheet.fixedWidth * m_datasheet.zoom, s_fixedheight,
M_editingflag)
END IF
IF m_datasheet.fixedrows> 0 and m_datasheet.fixedcols> 0 THEN
M_Datasheet.drawcell (E.Graphics, 0, 0, M_DataHeet.FixedRows - 1, M_Dataheet.fixedCOLS
- 1, m_rect.x m_datasheet.fixedwidth * m_datasheet.zoom, m_rect.y m_datasheet.fixedHeight *
M_Datasheet.zoom, m_editingflag) End IF
'
'Draw a non-fixed unit
'
M_datasheet.drawcell (E.Graphics, m_datasheet.toprow, m_datasheet.llcol, m_datasheet.rows
- 1, m_datasheet.cols - 1, s_fixedwidth, s_fixedheight, m_editingflag)
'
'Draw a head unit
'
IF m_datasheet.fixedwidth> 0 THEN
M_datasheet.drawfixedcols (E.Graphics, m_datasheet.toprow, m_datasheet.rows - 1,
S_fixedheight, true)
END IF
IF m_datasheet.fixedheight> 0 THEN
M_datasheet.drawfixedRows (E.Graphics, m_datasheet.LRAFTCOL, M_DATASHEET.COLS - 1,
S_fixedwidth, true)
END IF
IF m_datasheet.fixedWidth> 0 and m_datasheet.fixedheight> 0 THEN
M_datasheet.drawconner (E.Graphics, True)
END IF
Else
'Draw the upper side fixed unit
IF m_datasheet.fixedrows> 0 THEN
M_datasheet.drawfixedcols (E.Graphics, 0, M_Datasheet.fixedRows - 1, M_Rect.Y
M_datasheet.fixedheight * m_datasheet.Zoom, False)
M_datasheet.drawcell (E.Graphics, 0, M_Datasheet.leftcol, m_datasheet.fixedrows - 1,
M_Datasheet.cols - 1, s_fixedwidth, m_rect.y m_datasheet.fixedHeight * m_datasheet.zoom,
M_editingflag)
END IF
'Draw the left fixed unit
IF m_datasheet.fixedcols> 0 THEN
M_datasheet.drawfixedRows (E.Graphics, 0, M_Datasheet.fixedCOLS - 1, M_RECT.X
M_datasheet.fixedwidth * m_datasheet.zoom, false)
M_datasheet.drawcell (E.Graphics, m_datasheet.toprow, 0, m_datasheet.rows - 1,
M_Datasheet.fixedcols - 1, m_rect.x m_datasheet.fixedWidth * m_datasheet.zoom, s_fixedheight,
M_editingflag)
END IF
'Draw the upper left corner fixing unit
IF m_datasheet.fixedrows> 0 and m_datasheet.fixedcols> 0 THEN
M_Datasheet.drawcell (E.Graphics, 0, 0, M_DataHeet.FixedRows - 1, M_Dataheet.fixedCOLS
- 1, m_rect.x m_datasheet.fixedwidth * m_datasheet.zoom, m_rect.y m_datasheet.fixedHeight * m_datasheet.zoom, m_editingflag)
END IF
'Draw a non-fixed unit in the lower right corner
M_datasheet.drawcell (E.Graphics, m_datasheet.toprow, m_datasheet.llcol, m_datasheet.rows
- 1, m_datasheet.cols - 1, s_fixedwidth, s_fixedheight, m_editingflag)
'
'Draw a head unit
'
IF m_datasheet.fixedwidth> 0 THEN
M_datasheet.drawfixedcols (E.Graphics, m_datasheet.toprow, m_datasheet.rows - 1,
S_fixedheight, false)
END IF
IF m_datasheet.fixedheight> 0 THEN
M_datasheet.drawfixedRows (E.Graphics, m_datasheet.LRAFTCOL, M_DATASHEET.COLS - 1,
S_fixedwidth, false)
END IF
IF m_datasheet.fixedWidth> 0 and m_datasheet.fixedheight> 0 THEN
M_datasheet.drawconner (E.GRAPHICS, FALSE)
END IF
END IF
'
'When the mouse moves, draw a variety of temporary lines or temporary rectangles
'
SELECT CASE M_MOUSTATE
Case winfar_mousestate.resizecoling
S_PEN = New Pen (Color.gray)
S_pen.dashstyle = dashstyle.dash
E.Graphics.drawline (s_pen, m_rbpoint.x, 0, m_rbpoint.x, me.height)
Case winfar_mousestate.resizerowing
S_PEN = New Pen (Color.gray)
S_pen.dashstyle = dashstyle.dash
E.Graphics.drawline (S_PEN, 0, M_RBPOINT.Y, Me.Width, M_RBPoint.y)
Case Winfar_MouseState.drawLineing
If Math.abs (M_RBPoint.x - M_ltpoint.x)> Math.abs (M_RBPoint.Y - M_Ltpoint.y) THEN
E.Graphics.drawline (New Pen (Color.Blue, 3), M_ltpoint, New Point (m_rbpoint.x,
M_ltpoint.y))))
Else
E.Graphics.drawline (New Pen (Color.Blue, 3), M_ltpoint, New Point (m_ltpoint.x,
M_rbpoint.y))))
END IF
Case winfar_mousestate.delelineing
If Math.abs (M_RBPoint.x - M_ltpoint.x)> Math.abs (M_RBPoint.Y - M_Ltpoint.y) THEN
E.Graphics.drawline (New Pen (Color.Red, 3), M_ltpoint, New Point (m_rbpoint.x,
M_ltpoint.y))))
Else
E.Graphics.drawline (New Pen (Color.Red, 3), M_ltpoint, New Point (M_ltpoint.x,
M_rbpoint.y))))
END IF
Case winfar_mousestate.moverowing
M_datasheet.drawdragrow (E.Graphics, M_ENDROW)
Case winfar_mousestate.movecoling
M_datasheet.drawdragcol (E.GRAPHICS, M_ENDCOL)
Case winfar_mousestate.movecelling
M_datasheet.drawdragcell (E.GRAPHICS, M_ENDROW, M_ENDCOL, M_DATASHEET.Endrow -
M_datasheet.row, m_datasheet.endcol - m_datasheet.col)
Case winfar_mousestate.copyformating
'Draw Source Unit Border
S_LEFT = m_datasheet.getcellleft (m_datasheet.col) m_rect.x
S_top = m_datasheet.getcelltop (m_datasheet.row) m_rect.y
S_pen = new pen (color.black)
S_pen.dashstyle = dashstyle.dash
S_Rect = new Rectangle (S_LEFT, S_TOP, M_DATASHEET.COLWIDTH (m_datasheet.col) *
M_datasheet.zoom, m_datasheet.rowheight (m_datasheet.row) * m_datasheet.zoom)
E.Graphics.drawRectangle (New Pen (Color.White), S_RECT)
E.Graphics.drawRectangle (S_PEN, S_RECT)
S_Rect = New Rectangle (S_LEFT 1, S_TOP 1, M_Datasheet.colwidth (m_datasheet.col) *
M_datasheet.zoom - 2, m_datasheet.rowheight (m_datasheet.row) * m_datasheet.zoom - 2)
E.Graphics.drawRectangle (S_PEN, S_RECT)
'Draw the selection unit border
M_datasheet.drawdragcell (E.GRAPHICS, M_ROW, M_COL, M_ENDROW - M_ROW, M_ENDCOL - M_COL)
Case winfar_mousestate.drawshapeing
E.Graphics.drawRectangle (New Pen (Color.gray), M_ltpoint.x, M_Ltpoint.y, M_RBPoint.x -
M_ltpoint.x, m_rbpoint.y - m_ltpoint.y)
Case winfar_mousestate.drawcharting
E.Graphics.drawRectangle (New Pen (Color.gray), M_ltpoint.x, M_Ltpoint.y, M_RBPoint.x -
M_ltpoint.x, m_rbpoint.y - m_ltpoint.y)
End SELECT
'
'Draw a page tab
'
IF m_datalabelflag = true kil
'Determine the rectangle and fill
S_Rect = New Rectangle (M_BorderWidth, ClientRectangle.Bottom - M_Borderwidth - 18, ClientRectangle.Width - M_Borderwidth, 18)
E.Graphics.FillRectangle (new hatchbrush (hatchstyle.percent50, m_datasheet.fixedbackcolor,
Color.White), S_RECT)
'First button
S_Rect = new Rectangle (m_borderwidth, s_rect.top, 17, 18)
M_datasheet.drawbutton (E.Graphics, S_Rect, 1)
'Second button
S_Rect = New Rectangle (S_Rect.Right 1, S_Rect.top, 17, 18)
M_datasheet.drawbutton (E.Graphics, S_Rect, 2)
'Third button
S_Rect = New Rectangle (S_Rect.Right 1, S_Rect.top, 17, 18)
M_datasheet.drawbutton (E.Graphics, S_RECT, 3)
'Fourth button
S_Rect = New Rectangle (S_Rect.Right 1, S_Rect.top, 17, 18)
M_datasheet.drawButton (E.Graphics, S_RECT, 4)
'
'Draw label
'
DIM S_POINTS (3) As PointF
DIM S_FONT AS FONT
DIM S_LightColor as color = m_datasheet.getlightcolor (m_datasheet.fixedbackColor)
DIM S_DARKCOLOR As Color = m_datasheet.getdarkColor (m_datasheet.fixedbackColor)
S_font = new font (New FontFamily ("Song Body"), 9)
S_StringFormat.LineAlignment = StringAlignment.Center
S_StringFormat.Alignment = stringalignment.center
S_stringformat.formatflags = StringFormatFlags.nowrap
S_LEFT = M_BorderWidth 72
For i = m_leftmember to m_datalabel.count - 1
S_Width = E.Graphics.MeasureString (M_DataLabel (i), s_font) .width 4
S_Points (0) = New Pointf (S_LEFT, ClientRectangle.Bottom - M_BorderWidth - 18)
S_Points (1) = New Pointf (S_LEFT 17, ClientRectangle.Bottom - M_BorderWidth - 1)
S_Points (2) = New Pointf (S_LEFT S_WIDTH 17, ClientRectangle.Bottom - M_Borderwidth
- 1)
S_Points (3) = New PointF (S_LEFT S_WIDTH 17 17, ClientRectangle.Bottom -m_BorderWidth - 18)
E.Graphics.FillPolygon (New Solidbrush (M_Datasheet.fixedbackColor), S_Points
E.Graphics.drawPolygon (New Pen (Color.Black), S_Points)
S_Rect = New Rectangle (S_LEFT 17, ClientRectangle.bottom - M_Borderwidth - 18,
S_Width, 18)
E.Graphics.drawstring (m_datalabel (i), s_font, new solidbrush (color.black), New
Rectanglef (s_rect.x 2, s_rect.y 2, s_rect.width, s_rect.Height), S_StringFormat
S_LEFT = S_LEFT S_WIDTH 17
IF m_scrollbars = winfar_scrollbars.none life
If S_LEFT> = ClientRectangle.Width - M_Borderwidth Then
EXIT for
END IF
Elseif M_Scrollbars = Winfar_Scrollbars.Vertical Then
IF S_LEFT> = ClientRectangle.Width - M_HScrollsize - M_Borderwidth Then
EXIT for
END IF
Elseif m_scrollbars = winfar_scrollbars.horizontal or m_scrollbars =
Winfar_scrollbars.both dam
IF S_LEFT> = ClientRectangle.width * 0.75 THEN
EXIT for
END IF
END IF
NEXT
'Draw the current label
S_LEFT = M_BorderWidth 72
For i = m_leftmember to m_datalabel.count - 1
S_Width = E.Graphics.MeasureString (M_DataLabel (i), s_font) .width 4
IF i = m_datamember dam
S_Points (0) = New Pointf (S_LEFT, ClientRectangle.Bottom - M_BorderWidth - 18)
S_Points (1) = New Pointf (S_LEFT 17, ClientRectangle.Bottom - M_BorderWidth - 1)
S_points (2) = new pointf (S_LEFT S_WIDTH 17, ClientRectangle.bottom -
M_borderwidth - 1)
S_Points (3) = New Pointf (S_LEFT S_WIDTH 17 17, ClientRectangle.bottom -
M_BorderWidth - 18)
E.Graphics.FillPolygon (New Solidbrush (S_LightColor), S_Points
E.Graphics.drawPolygon (New Pen (color.ble) s_rect = new Rectangle (S_LEFT 17, ClientRectangle.Bottom - M_BorderWidth - 18,
S_Width, 18)
E.Graphics.drawstring (m_datalabel (i), s_font, new solidbrush (color.black), New
Rectanglef (s_rect.x 2, s_rect.y 2, s_rect.width, s_rect.Height), S_StringFormat
EXIT for
END IF
S_LEFT = S_LEFT S_WIDTH 17
NEXT
'
'Data tag right button
'
IF m_scrollbars = winfar_scrollbars.none life
S_Rect = New Rectangle (ClientRectangle.width - M_Borderwidth - 7, S_Rect.top, 6, 18)
Elseif M_Scrollbars = Winfar_Scrollbars.Vertical Then
S_Rect = New Rectangle (ClientRectangle.Width - M_HScrollsize - M_Borderwidth - 7,
S_Rect.top, 6, 18)
Elseif m_scrollbars = winfar_scrollbars.horizontal or m_scrollbars =
Winfar_scrollbars.both dam
S_Rect = New Rectangle (ClientRectangle.Width * 0.75 - 7, S_Rect.top, 6, 18)
END IF
E.Graphics.FillRectangle (new solidbrush (m_datasheet.fixedbackcolor), s_RECT)
M_datasheet.drawbutton (E.Graphics, S_Rect, 0)
END IF
'
'Draw the lower right corner
'
IF m_hscrollsize = 18 and m_vscrollsize = 18 THEN
E.Graphics.FillRectangle (New Solidbrush (color.fromknowncolor (knowncolor.control), New
Rectangle (ClientRectangle.Width - M_Borderwidth - 18, ClientRectangle.Height - M_Borderwidth -
18, 18, 18))
END IF
'
'Draw control border
'
Select Case BorderStyle
Case winfar_borderstyle.bordersingle
E.Graphics.drawRectangle (New Pen (Color.Black), New Rectangle (0, 0,
ClientRectangle.Width - 1, ClientRectangle.Height - 1))
Case Winfar_Borderstyle.BordeRembossstyle
'left
E.Graphics.drawline (new pen (m_datasheet.GetdarkColor), 0,
0, 0, ClientRectangle.height)
E.Graphics.drawline (new pen (m_datasheet.GetlightColor), 1,0, 1, clientRectangle.Height)
'on
E.Graphics.drawline (new pen (m_datasheet.GetdarkColor), 0,
0, ClientRectangle.width, 0)
E.Graphics.drawline (New Pen (m_datasheet.getlightcolor), 1,
1, ClientRectangle.width, 1)
'right
E.Graphics.drawline (New Pen (Color.FromknownColor (KNownColor.control),
ClientRectangle.Width - 2, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 3)
E.Graphics.Drawline (New Pen (Color.White), ClientRectangle.width - 1, 0,
ClientRectangle.Width - 1, ClientRectangle.Height - 1)
'under
E.Graphics.drawline (New Pen (Color.FromknownColor (KNownColor.Control), 1,
ClientRectangle.height - 2, ClientRectangle.Width - 2, ClientRectangle.Height - 2)
E.Graphics.drawline (New Pen (Color.White), 0, ClientRectangle.height - 1,
ClientRectangle.Width - 1, ClientRectangle.Height - 1)
Case Winfar_Borderstyle.Borderin3dStyle, Winfar_Borderstyle.Borderout3DStyle
'on
E.Graphics.drawline (New Pen (Color.Silver), 0, 0, ClientRectangle.width, 0)
E.Graphics.drawline (New Pen (Color.Black), 1, 1, ClientRectangle.Width, 1)
'E.Graphics.drawline (New Pen (Color.Black), 1, 2, ClientRectangle.Width, 2)
'left
E.Graphics.drawline (New Pen (Color.Silver), 0, 0, 0, ClientRectangle.Height)
E.Graphics.drawline (New Pen (Color.Black), 1, 1, 1, ClientRectangle.Height)
'E.Graphics.drawline (New Pen (Color.Black), 2, 1, 2, ClientRectangle.Height)
'under
E.Graphics.drawline (New Pen (Color.FromknownColor (KNownColor.Control), 1,
ClientRectangle.height - 2, ClientRectangle.Width - 2, ClientRectangle.Height - 2)
E.Graphics.drawline (New Pen (Color.White), 0, ClientRectangle.height - 1,
ClientRectangle.Width - 1, ClientRectangle.Height - 1)
'right
E.Graphics.drawline (New Pen (Color.FromknownColor (KNownColor.control),
ClientRectangle.Width - 2, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 3)
E.Graphics.Drawline (New Pen (Color.White), ClientRectangle.width - 1, 0,
ClientRectangle.Width - 1, ClientRectangle.Height - 1)
End SELECT
End Sub
END CLASS
At this point, the control is complete, and of course the above code is not executed, because here is just a idea, there are many real-complete controls.
Things have to do.
If you are interested, we can communicate, discuss together, and improve them together.