ShrimperDan 01-10-2005, 11:42 AM I am working on a report generator dll which enables me to pass parameters like .font = , .title = , .subtitle =.
This part I've got working.
I want to add a bit more like...
.title.text =
.title.font =
.title.justification =
.subtitle.text =
.subtitle.font =
.subtitle.justification =
My thought was create a class of all text properties (font, text, justification, color) and inherit these properties into the other.
How can I do this? Sample code woulod be appreciated. I've tried but I'm missing something.
here's a bit 'o code using images:
Public class Report
'...report properties...
Public Class HeaderImageRight
Inherits ImageProperties
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
End Class
Class ImageProperties
Public Property Location() As String
Get
Return mLocation
End Get
Set(ByVal Value As String)
mLocation = Value
End Set
End Property
Public Property Width() As Integer
Get
Return mWidth
End Get
Set(ByVal Value As Integer)
mWidth = Value
End Set
End Property
Public Property Height() As Integer
Get
Return mHeight
End Get
Set(ByVal Value As Integer)
mHeight = Value
End Set
End Property
End Class
end class
ShrimperDan 01-10-2005, 12:02 PM to clarifiy a point, in my code that calls the report, I want it to look like
report = new report document
report.layout = "portrait" ' this is ok
report.title.text = "Search Results"
report.title.font = new font("Arial", 10)
It's those last two I can't get to come up.
Iceplug 01-10-2005, 12:07 PM Well, you can add a class or a structure that contains a Text, Font, and Justification property.
Then, in your class, you add a Title as YourObject and Subtitle As YourObject, where YourObject is whatever you had for the Text, Font, and Justification.
ShrimperDan 01-10-2005, 12:34 PM Well, you can add a class or a structure that contains a Text, Font, and Justification property.
Then, in your class, you add a Title as YourObject and Subtitle As YourObject, where YourObject is whatever you had for the Text, Font, and Justification.
Here is what I've tried. See my inline comments.
Imports System.Drawing
Public Class Test
'this is the base class with a bunch of report level properties like layout.
Private strtitle As String
'report title
Public Property sTitle() As String
Get
Return strtitle
End Get
Set(ByVal Value As String)
strtitle = Value
End Set
End Property
'other classes for other stuff like footers, bylines, etc.
Public Class Footer
Inherits TextProperties
Private strname As String
'FooterFont = new textproperties.zfont
'Dim FooterFont = New TextProperties.zfont
'this is wher I'm stuck as the above two give error and the intellisense
'doesn't pick up the textproperties properties.
End Class
Public Class TextProperties
Private mFont As Font
Private mText As String
Public Property zFont() As Font
Get
Return mFont
End Get
Set(ByVal Value As Font)
mFont = Value
End Set
End Property
Public Property Text() As String
Get
Return mText
End Get
Set(ByVal Value As String)
mText = Value
End Set
End Property
End Class
End Class
Faith 01-10-2005, 01:30 PM Here's an example, but I have to admit, I'm totally lost with your:
'FooterFont = new textproperties.zfont
'Dim FooterFont = New TextProperties.zfont
I have no idea what you're trying to achieve...
Public Class Test
Dim Something As New TextProperties(Font, text)
Sub Something()
'Call the properties of TextProperties trough the instance of TextProperties:
'Something.Font
'Something.Text
'So if your class was named Text, and you'd make an instance of this class
'(as I presume), then Something would be named TextProperties
'And you'd call MyText.TextProperties.Font
'This assumes that whenever you create a new "text" or whatever, you
'create a New Set of everything, Textproperties, and stuf.
End Sub
Class TextProperties
Private mFont As System.Drawing.Font
Private mText As String
'An overloaded constructor, you can pass either an existing instance of the class or new data
Sub New(ByVal tFont As Drawing.Font, ByVal Text As String)
mFont = Font
mText = Text
End Sub
Sub New(ByVal tFont As TextProperties)
mFont = tFont.mFont
mText = tFont.mText
End Sub
Public Property Font() As Drawing.Font
Get
Return Me.mFont
End Get
Set(ByVal Value As Drawing.Font)
mFont = Value
End Set
End Property
Public Property Text() As String
Get
Return Me.mText
End Get
Set(ByVal Value As String)
Me.mText = Value
End Set
End Property
End Class
End Class
The code is self explanatory, and I assume you know some things about this...
I'm wondering if this is even close to what you're trying to do?
:)
ShrimperDan 01-11-2005, 08:12 AM That's to all for your help. Here is a short form of my final solution for anyone else who ever has a similar problem;
Imports System.Drawing
Public Class ReportDocument
Inherits PrintDocument
'...existing dims and properties
'...new text properties
Private mTextP As clsTextProperty
Public Property TextLineProperty() As clsTextProperty
Get
Return mTextP
End Get
Set(ByVal Value As clsTextProperty)
mTextP = Value
End Set
End Property
Public Class clsTextProperty
' standard properties
Inherits TextProperties
'additional property
Private mstrDescription As String
Public ReadOnly Property Description() As String
Get
Return mstrDescription
End Get
End Property
Public Sub New(ByVal InText As String)
Text = InText
mstrDescription = "Test"
End Sub
End Class
Public Class TextProperties
Private mFont As System.Drawing.Font
Private mText As String
Public Property Font() As Drawing.Font
Get
Return Me.mFont
End Get
Set(ByVal Value As Drawing.Font)
mFont = Value
End Set
End Property
Public Property Text() As String
Get
Return Me.mText
End Get
Set(ByVal Value As String)
Me.mText = Value
End Set
End Property
End Class
'............
'this is all in my dll
'so the code in the app using the dll is
imports vbReport
'etc
dim report as ReportDocument
report = New ReportDocument
report.textlineproperty.text = xyz
'For practical purposes, I'll modify to have;
report.header.text =
report.header.font =
report.footer.text =
report.footer.font =
report.logo.image = 'in image cases, I'll have image sub classes like I did with fonts.
report.logo.height =
|