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

لو كان النص مجرد عنوان ثابت تستطيع كتابته في أي محرر نصوص وتدور الصورة وتضعها في الأداة

سأحاول الآن ، أنا لدي أداة label وفيه رسم النص بنفس الأسلوب أستطيع إضافة خاصية الزاوية

سأجرب وأوافيك بالخبر

جربت الاحتيال على أداة الليبل قبل أن أتعب ههه ولكن لا فائدة مجبور على رسم النص وكل شيء
الرد }}}
تم الشكر بواسطة:
#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 
الرد }}}
تم الشكر بواسطة:
#53
مشكور سيدي شكرا جزيلا مجهود رائع جدا لكن ينقص شيء واحد وهو طريقة عرض النص يعني النص يدور 90 درجة فقط ولكن اريد ه او يريده الكثير هو 270 درجة اي ان يكون النص من الاعلى الى الاسفل وخاصة في اللغة العربية

بقيت لك هاته النقطة فقط مشكور مسبقا
الرد }}}
تم الشكر بواسطة:
#54
هناك ايضا ملاحظة سيدي RightToLeft عند تفعيل Vertical تبقى تعمل علي مستوي الافقي بالنسبة لاطار النص
الرد }}}
تم الشكر بواسطة:
#55
الظاهر أنه لا مفر من استخدام RotateTransform وينبغي تشغيل حساب المثلثات إن لم يخب ظني، لأن محور الدوران هو النقطة صفر،صفر في حين أننا نريدها أن تكون المنتصف
الرد }}}
تم الشكر بواسطة:
#56
نعم سيدي ولكن كيف استخدم حساب المثلثات وايضا هل محور الدوران يكون بالنسبة للنص او مشتطيل الدي يحوي النص استغل وجودك للرد شكرا
الرد }}}
تم الشكر بواسطة:
#57
إقتباس :نعم سيدي ولكن كيف استخدم حساب المثلثات وايضا هل محور الدوران يكون بالنسبة للنص او مشتطيل الدي يحوي النص استغل وجودك للرد شكرا

محتاجة رسم علشان نضع المتغيرات ونصيغ المعادلة

المحور يكون بالنسبة للمساحة كلها يعني في مثالنا الليبل مساحته كلها تدور والنقطة هي صفر صفر وهي في الزاوية العلوية اليسرى
الرد }}}
تم الشكر بواسطة:
#58
من خلال بحثي في النترنت توصلت الي فكرة بسيطة ممكن ان تساعدك سيدي

وهي الرسم داخل اطار label بعد جعل الخاصية Autosize=false

وتفريغ محتوى النص يمكن ان نرسم نص داخل اطار مع تحديد اي زاوية تحتاجها واكتشفت ان الدرجة 270 تعادل الدرجة 90-

اما الرسم الدي طلبتها فلم افهم ما تريد واليك هاته الرسم تشرح TranslateTransform و RotateTransform التي استعملته في المثال :

[ATTACH=CONFIG]2368[/ATTACH]

واليك المثال ارجو ان يساعدك

[ATTACH]2367[/ATTACH]

شكرا


الملفات المرفقة صورة/صور
   

.rar   TextRotate.rar (الحجم : 77.06 ك ب / التحميلات : 74)
الرد }}}
تم الشكر بواسطة:
#59
هناك مشكلة واحدة

أريد من خاصية TextAlign أن تكون فعالة مع دوران النص
الرد }}}
تم الشكر بواسطة:
#60
بعد يحثي في النترنت وجدت لك اداة جميلة جدا تدعم هاته الخاصية وبها خصائص اخري جميلة مثل النص الدائري والدي على شكل قوس واتجاه النص عكس عقارب الساعة ومع عقارب الساعة و...

المهم حتي وان لم تكن تهمنا هاته الخصائص تركتها لك كما هي .

ملاحظة : هاته الاداة ممبرمجة ب #c وتحويلها الى vb مع تغييرات طفيفة ارجو ان تساعدك شكرا على تجاوبك

[attach]2379[/attach]


الملفات المرفقة
.rar   OrientedLabel.rar (الحجم : 1.73 ك ب / التحميلات : 61)
الرد }}}
تم الشكر بواسطة:



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


يقوم بقرائة الموضوع: