مشكور سيدي على ردك ولكنني لا اعرف كيف استعمل اداة PrintPictureBox في كتابة نصوص عمودية او مستقيمة ربما احتج الى اجراآت GDI لرسم نصوص ثم طباعتها .... المهم لقد اعجبتني فكرة مشروعك انه هنلك اداة لوقت التصميم
PrintLabel ثم كلاس LabelPrinter الذي يترجم الاداة للطباعة عن طريق الرسم وبما انك تركت المشروع قيد التطوير ومن خلال بحث النترنت قمت باضافة بعض الكودات الي الاداة PrintLabel لكي يضهر النص بالزاوية التي تريدها
وهدا هو الكود :
كود :
[align=left]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]"
Private mRotationAngle As Double
Private mText As String
Public Sub New()
MyBase.AutoSize = False
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
#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.Parent, Section)
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
#Region " Rotation Angle"
<Description("Rotation Angle"), Category("Appearance")> _
Public Property RotationAngle() As Double
Get
Return mRotationAngle
End Get
Set(ByVal value As Double)
mRotationAngle = value
MyBase.Invalidate() 'Force a redraw when the angle is changed
End Set
End Property
#End Region
#Region "Display Text"
<Description("Display Text"), Category("Appearance")> _
Public Overrides Property Text() As String
'we override the text property so we can force a redraw
Get
Return mText
End Get
Set(ByVal value As String)
mText = value
MyBase.Invalidate()
End Set
End Property
#End Region
#End Region
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim graphics As Graphics = e.Graphics
Dim stringFormat As StringFormat = New StringFormat
stringFormat.Alignment = StringAlignment.Center
stringFormat.Trimming = StringTrimming.None
Dim textBrush As Brush = New SolidBrush(MyBase.ForeColor)
'Getting the width and height of the text, which we are going to write
Dim width As Double = graphics.MeasureString(Text, MyBase.Font).Width
Dim height As Double = graphics.MeasureString(Text, MyBase.Font).Height
'For rotation, you need to convert to radians
Dim angle As Double = (RotationAngle / 180) * Math.PI
graphics.TranslateTransform( _
(ClientRectangle.Width + CDbl(height * Math.Sin(angle)) - CDbl(width * Math.Cos(angle))) / 2, _
(ClientRectangle.Height - CDbl(height * Math.Cos(angle)) - CDbl(width * Math.Sin(angle))) / 2)
graphics.RotateTransform(CDbl(RotationAngle))
graphics.DrawString(Text, MyBase.Font, textBrush, 0, 0)
graphics.ResetTransform()
End Sub
#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
Sub ChangeText()
End Sub
#End Region
End Class[/align]
لكن واجهتني عدة مشاكل لانني مازلت لم افهم الكود جيدا لاعادة رسم الاداة اواعادة نسخها ان صح التعبير تم طباعتها وايضا لم تنجح فكرة الزاوية المهم اضفت
الى كلاس الطباعة هدا الكود :
كود :
[align=left]Dim direction As New StringFormat(StringFormatFlags.DirectionVertical)
....
....
g.DrawString(CurText, txt.Font, New SolidBrush(txt.ForeColor), Rec, direction) [/align]
حيث يتم طباعة بشكل عمودي ولكن عند استعمال g.Graphics.RotateTransform واستعمال الزاوية الموجودة في خاصية Rotation Angle لايتم ضهور النص او يضهر لكن ليس في المكان المطلوب
المهم سيدي انا اعلم انه كثرت عليك الاقتراحات هناك من يطلب الطباعة في عدة صفحات والطباعة العمودية ووووو...
واخيرا للامانة الاكواد ليست من انجازي فلقد وجدتها في النترنت ..