تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مشروع بناء أداة طباعة
#52
الحمد لله تم

فقط اتجاه عمودي او أفقي، لم أدعم بالزاوية لأنها تحتاج تفرغ

انسخ هذا الكود في PrintLabel

PHP كود :
Imports System.Drawing.Design
<ToolboxBitmap(GetType(Label))> _
Public Class PrintLabel
    Inherits Label
    
Implements IPrintableControl
    Friend 
Const pn As String "[pn]"
    
Friend Const pc As String "[pc]"
    
Public Sub New()
        
MyBase.AutoSize False
        MyBase
.SetStyle(ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBufferTrue)
    
End Sub
#Region "Properties"

#Region "Appearance"
    
<Category("Printing Appearance: Common"), Description("مساواة العرض أثناء الطباعة بالعرض أثناء التصميم")> _
    
Public Property FitMaxWidth As Boolean True
    
<Category("Printing Appearance: Common"), Description("مساواة الطول أثناء الطباعة بالطول أثناء التصميم")> _
    
Public Property FitMaxHeight As Boolean True
    
<Category("Printing Appearance"), Description("شكل الإطار الخارجي")> _
    
Public Property Border() As DashStyle DashStyle.Solid
    
<Category("Printing Appearance"), Description("سُمك الإطار الخارجي")> _
    
Public Property BorderSize() As Integer 0
    
<Category("Printing Appearance"), Description("لون الإطار الخارجي")> _
    
Public Property BorderColor() As Color Color.Black
    
<Category("Appearance"), Description("زاوية ميلان النص")> _
    
Public Property Direction() As TextDirection


#End Region

#Region "Printing Data"
    
Private _SourceControl As Label
    
<Browsable(False)> _
    
Public Property SourceControl As System.Windows.Forms.Control Implements IPrintableControl.SourceControl
        Get
            
If _SourceControl Is Nothing Then
                _SourceControl 
Me
            End 
If
            Return 
_SourceControl
        End Get
        Set
(ByVal value As System.Windows.Forms.Control)
            
_SourceControl value
        End Set
    End Property
    
<Category("Appearance"), Description("تحديد ما إذا كان الحقل لعرض رقم الصفحة، استخدم خاصية النص للتنسيق  ,[pn]=Page Number, [pc]=Page Count")> _
    
Public Property IsPageNumber As Boolean False
#End Region

#Region "Printing Components"
    
Dim _Printer As LabelPrinter
    
<Browsable(False)> _
    
Public ReadOnly Property Printer As Printer Implements IPrintableControl.Printer
        Get
            
If _Printer Is Nothing Then
                _Printer 
= New LabelPrinter(Me)
            
End If
            Return 
_Printer
        End Get
    End Property

    
<Browsable(False)> _
    
Public ReadOnly Property Section As Section Implements IPrintableControl.Section
        Get
            
Return CType(Me.ParentSection)
        
End Get
    End Property
#End Region

#Region "Printing Behavior"
    
<Category("Printing Behavior"), Description("تفعيل مقياس الرسم الأفقي")> _
    
Public Property ScaleHorizontal As Boolean True Implements IPrintableControl.ScaleHorizontal
    
<Category("Printing Behavior"), Description("تفعيل مقياس الرسم الرأسي")> _
    
Public Property ScaleVertical As Boolean True Implements IPrintableControl.ScaleVertical
    
<Category("Printing Behavior"), Description("رتبة مرحلة الطباعة")> _
    
Public Property StageIndex As Integer Implements IPrintableControl.StageIndex
    
<Category("Printing Behavior"), Description("رتبة الأداة أثناء مرحلة الطباعة")> _
    
Public Property PrintIndex As Integer Implements IPrintableControl.PrintIndex
    
<Category("Printing Behavior"), Description("تحديد ما إذا كانت الأداة تستكمل طباعتها في صفحات تالية أو لا")> _
    
Public Property OnePageOnly As Boolean False Implements IPrintableControl.OnePageOnly
#End Region
#End Region


#Region "Methods"
    
Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
        If 
Me.Parent IsNot Nothing Then
            
If Not TypeOf Parent Is Section Then
                Me
.Parent.Controls.Remove(Me)
            
End If
        
End If
    
End Sub
    
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        
'e.Graphics.DrawRectangle(New Pen(Me.BorderColor, Me.BorderSize) With {.Alignment = PenAlignment.Center}, e.ClipRectangle)

        DrawText(e.Graphics, e.ClipRectangle, Me.Text)
    End Sub
    Public Sub DrawText(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal txt As String)
        Dim rec = bounds
        Dim fl As StringFormatFlags
        If Me.RightToLeft = Forms.RightToLeft.Yes Then
            fl = StringFormatFlags.DirectionRightToLeft
        End If
        If Me.Direction = TextDirection.Vertical Then
            fl = fl Or StringFormatFlags.DirectionVertical
        End If
        DrawString(g, Me.Text, Me.Font, Me.ForeColor, rec, Me.TextAlign, fl)
    End Sub
    Public Sub DrawString(ByVal g As Graphics, ByVal Text As String, ByVal Font As Font, ByVal TextColor As Color, ByVal Rect As Rectangle, ByVal Align As ContentAlignment, ByVal FormatFlags As StringFormatFlags)
        Try

            Dim sf As New StringFormat
            sf.Alignment = GetXAlign(Align)
            sf.LineAlignment = GetYAlign(Align)
            sf.FormatFlags = FormatFlags

            g.DrawString(Text, Font, New SolidBrush(TextColor), Rect, sf)

        Catch ex As Exception

        End Try
    End Sub
#End Region



End Class
Public Enum TextDirection
    Horizontal
    Vertical
End Enum 



وهذا الكود في LabelPrinter

PHP كود :
Public Class LabelPrinter
    Inherits Printer
    Dim Text 
As String
    Dim ptxt 
As String
    
Public Sub New(ByVal printControl As IPrintableControl)
        
MyBase.New(printControl)
    
End Sub
    
Private ReadOnly Property txt As PrintLabel
        Get
            
Return MyBase.Control
        End Get
    End Property
    ReadOnly Property man 
As PrintManager
        Get
            
Return txt.Section.Page.PManager
        End Get
    End Property
    
Protected Friend Overrides Function Print(ByVal g As System.Drawing.GraphicsByVal Bounds As System.Drawing.Rectangle) As Boolean
        Dim sc 
txt.SourceControl
        
'g.DrawRectangle(Pens.Red, Bounds)
        Dim Completed As Boolean
        '
If First Printing
        
If Me.Text Is Nothing AndAlso sc.Text IsNot Nothing Then
            Me
.Text sc.Text
        End 
If
        If 
Me.txt.IsPageNumber Then
            Text 
Me.txt.Text.Replace(PrintLabel.pnman.CurPage).Replace(PrintLabel.pcman.PageCount)
        
End If
        If 
sc.Text IsNot Nothing Then
            
'Decleration
            Dim Rec As Rectangle = Bounds
            Dim StringFormat = New StringFormat
            Dim hAlign As ContentAlignment = ContentAlignment.MiddleLeft
            '
For Measure the text
            Dim CurText 
As String
            Dim numChars 
As Integer
            Dim numLines 
As Integer
            
'Alignment........
            With StringFormat
                .LineAlignment = GetYAlign(txt.TextAlign)
                .Alignment = GetXAlign(txt.TextAlign)
                .Trimming = StringTrimming.Word
                Dim rtl = txt.RightToLeft
                If rtl = Windows.Forms.RightToLeft.Yes Then
                    .FormatFlags = StringFormatFlags.DirectionRightToLeft
                End If
            End With

            '
Measure Text
            
'Dim s = Bounds.Size
            '
s.Height -= txt.Font.GetHeight(g)
            
Rec.Size g.MeasureString(Texttxt.FontRec.SizeStringFormatnumCharsnumLines).ToSize()
            
's.Height += txt.Font.GetHeight(g)

            '
Get Max of te=t
            CurText 
Text.Substring(0numChars)
            
'Adjust location by align
            Rec = GetRect(Rec.Size, Bounds, txt.TextAlign, 0, 0)
            '
Auto Size not
            
'Vertical

            If txt.FitMaxHeight Then
                Rec.Height = Bounds.Height
                Rec.Y = Bounds.Top
            End If
            '
Horizontal
            
If txt.FitMaxWidth Then
                Rec
.Width Bounds.Width
                Rec
.Bounds.X
            End 
If
            
'Drawing:
            '
1Fill Final Bounds
            g
.FillRectangle(New SolidBrush(txt.BackColor), Rec)
            
'2- Draw Border
            If txt.BorderSize > 0 Then
                Dim pn = New Pen(txt.BorderColor, txt.BorderSize)
                pn.DashStyle = txt.Border
                g.DrawRectangle(pn, Rec)
            End If
            '
3Draw Text
            
'g.DrawString(CurText, txt.Font, New SolidBrush(txt.ForeColor), Rec, StringFormat)
            txt.DrawText(g, Rec, CurText)
            '
g.DrawRectangle(Pens.RedRec)
            
'Finishing is completed ?
            If numChars < Me.Text.Length AndAlso Not Me.txt.OnePageOnly Then
                ptxt = Me.Text
                Me.Text = Text.Substring(numChars)
                If ptxt Is Me.Text Then
                    Return True
                End If
                Completed = False
            Else
                Me.Text = txt.Text
                Completed = True
            End If
            If txt.IsPageNumber Then
                Return True
            End If
            Return Completed
        End If
    End Function



End Class 
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
مشروع بناء أداة طباعة - بواسطة Sajad - 12-02-13, 10:52 PM
مشروع بناء أداة طباعة - بواسطة DreamsDotNet - 13-02-13, 12:16 AM
مشروع بناء أداة طباعة - بواسطة Sajad - 26-02-13, 11:27 PM
مشروع بناء أداة طباعة - بواسطة learning.net - 28-02-13, 01:45 PM
مشروع بناء أداة طباعة - بواسطة Nŏ Coммεητ - 03-03-13, 02:55 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 09-03-13, 01:07 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 09-03-13, 01:18 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 09-03-13, 02:33 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 09-03-13, 01:09 PM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 11-03-13, 04:07 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 11-03-13, 06:45 PM
مشروع بناء أداة طباعة - بواسطة Easy 4ever - 12-03-13, 07:10 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 13-03-13, 12:06 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 13-03-13, 10:40 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 30-03-13, 03:42 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 02-04-13, 04:04 AM
مشروع بناء أداة طباعة - بواسطة Ruru86 - 06-04-13, 01:50 AM
مشروع بناء أداة طباعة - بواسطة jascar - 06-04-13, 04:29 PM
مشروع بناء أداة طباعة - بواسطة jascar - 07-04-13, 08:45 PM
مشروع بناء أداة طباعة - بواسطة أبو يعقوب - 07-04-13, 11:17 PM
مشروع بناء أداة طباعة - بواسطة jascar - 08-04-13, 01:11 AM
مشروع بناء أداة طباعة - بواسطة jascar - 08-04-13, 01:34 AM
مشروع بناء أداة طباعة - بواسطة jascar - 08-04-13, 09:29 PM
مشروع بناء أداة طباعة - بواسطة jascar - 09-04-13, 06:50 PM
مشروع بناء أداة طباعة - بواسطة jascar - 10-04-13, 08:05 PM
مشروع بناء أداة طباعة - بواسطة jascar - 16-04-13, 07:35 PM
مشروع بناء أداة طباعة - بواسطة shaker.soft - 25-05-13, 02:50 PM
مشروع بناء أداة طباعة - بواسطة Nŏ Coммεητ - 27-07-13, 11:10 AM
مشروع بناء أداة طباعة - بواسطة Nŏ Coммεητ - 28-07-13, 05:13 AM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم