Тема: Создаем полезные функции и свойства объекта Page
Set сPage = New clsPage
Вы не вошли. Пожалуйста, войдите или зарегистрируйтесь.
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
Set сPage = New clsPagePublic Property Get mPageSetup() As PageSetup ' Настройка страницы
Set mPageSetup = Me.Rectangle.Range.PageSetup
End PropertyPublic Property Get LeftMargin() As Single
LeftMargin = Me.mPageSetup.LeftMargin
End Property
Public Property Get RightMargin() As Single
RightMargin = Me.mPageSetup.RightMargin
End Property
Public Property Get TopMargin() As Single
TopMargin = Me.mPageSetup.TopMargin
End Property
Public Property Get BottomMargin() As Single
BottomMargin = Me.mPageSetup.BottomMargin
End PropertyДалее модифицируем созданные нами ранее свойства:
Public Property Get PageWidth() As Single
PageWidth = form_ClassInfo.Value(Me.mPageSetup.PageWidth)
End Property
Public Property Get PageHeight() As Single
PageHeight = form_ClassInfo.Value(Me.mPageSetup.PageHeight)
End Property
Public Property Get PageSpace() As Single
PageSpace = Me.PageWidth * Me.PageHeight
End Property
Public Property Get LeftMargin() As Single
LeftMargin = form_ClassInfo.Value(Me.mPageSetup.LeftMargin)
End Property
Public Property Get RightMargin() As Single
RightMargin = form_ClassInfo.Value(Me.mPageSetup.RightMargin)
End Property
Public Property Get TopMargin() As Single
TopMargin = form_ClassInfo.Value(Me.mPageSetup.TopMargin)
End Property
Public Property Get BottomMargin() As Single
BottomMargin = form_ClassInfo.Value(Me.mPageSetup.BottomMargin)
End Property
Public Property Get PrinttableWidth() As Single
PrinttableWidth = Me.PageWidth - (Me.LeftMargin + Me.RightMargin)
End Property
Public Property Get PrinttableHeight() As Single
PrinttableHeight = Me.PageHeight - (Me.TopMargin + Me.BottomMargin)
End Property
Public Property Get PrinttableSpace() As Single
PrinttableSpace = Me.PrinttableWidth * Me.PrinttableHeight
End PropertyОтредактировано aap77 (17.05.2012 21:57:54)
Private Sub Class_Initialize()
Load form_ClassInfo
Options.MeasurementUnit = wdMillimeters
form_ClassInfo.opb_UnitApplication.Value = True
With form_ClassInfo
.opb_UnitInches.Enabled = False
.opb_UnitCentimeters.Enabled = False
.opb_UnitMillimeters.Enabled = False
.opb_UnitPoints.Enabled = False
.opb_Lines.Enabled = False
.opb_UnitPicas.Enabled = False
.Caption = "Информация о свойствах класса clsPage"
End With
End SubСоздадим в классе clsPage функцию форматирования числа и модернизируем свойства
Public Function FormatValue(Num As Variant) As Single
FormatValue = Format(Num, "#####.#")
End FunctionPublic Property Get PageWidth() As Single
PageWidth = Me.FormatValue(form_ClassInfo.Value(Me.mPageSetup.PageWidth))
End Property
Public Property Get PageHeight() As Single
PageHeight = Me.FormatValue(form_ClassInfo.Value(Me.mPageSetup.PageHeight))
End Property
Public Property Get PageSpace() As Single
PageSpace = Me.FormatValue(Me.PageWidth * Me.PageHeight)
End Property
Public Property Get LeftMargin() As Single
LeftMargin = form_ClassInfo.Value(Me.mPageSetup.LeftMargin)
End Property
Public Property Get RightMargin() As Single
RightMargin = Me.FormatValue(form_ClassInfo.Value(Me.mPageSetup.RightMargin))
End Property
Public Property Get TopMargin() As Single
TopMargin = Me.FormatValue(form_ClassInfo.Value(Me.mPageSetup.TopMargin))
End Property
Public Property Get BottomMargin() As Single
BottomMargin = Me.FormatValue(form_ClassInfo.Value(Me.mPageSetup.BottomMargin))
End Property
Public Property Get PrinttableWidth() As Single
PrinttableWidth = Me.FormatValue(Me.PageWidth - (Me.LeftMargin + Me.RightMargin))
End Property
Public Property Get PrinttableHeight() As Single
PrinttableHeight = Me.FormatValue(Me.PageHeight - (Me.TopMargin + Me.BottomMargin))
End Property
Public Property Get PrinttableSpace() As Single
PrinttableSpace = Me.FormatValue(Me.PrinttableWidth * Me.PrinttableHeight)
End PropertyPublic Property Get PrinttableBounds() As Collection
Dim TopBounds As Collection, lstXY As Collection, Info As String
Dim CenterBounds As Collection
Dim BottomBounds As Collection
Set PrinttableBounds = New Collection
Set TopBounds = New Collection
Set CenterBounds = New Collection
Set BottomBounds = New Collection
Set lstXY = New Collection
lstXY.Add Me.FormatValue(Me.LeftMargin), "X"
lstXY.Add Me.FormatValue(Me.TopMargin), "Y"
Info = Info & " Точка_1: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
TopBounds.Add lstXY, "Bounds_1"
Set lstXY = New Collection
lstXY.Add Me.FormatValue((Me.LeftMargin + Me.PrinttableWidth) / 2), "X"
lstXY.Add Me.FormatValue(Me.TopMargin), "Y"
Info = Info & " Точка_2: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
TopBounds.Add lstXY, "Bounds_2"
Set lstXY = New Collection
lstXY.Add Me.FormatValue(Me.LeftMargin + Me.PrinttableWidth), "X"
lstXY.Add Me.FormatValue(Me.TopMargin), "Y"
Info = Info & " Точка_3: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
TopBounds.Add lstXY, "Bounds_3"
Set lstXY = New Collection
lstXY.Add Me.FormatValue(Me.LeftMargin), "X"
lstXY.Add Me.FormatValue((Me.TopMargin + Me.PrinttableHeight) / 2), "Y"
Info = Info & " Точка_4: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
CenterBounds.Add lstXY, "Bounds_4"
Set lstXY = New Collection
lstXY.Add Me.FormatValue((Me.LeftMargin + Me.PrinttableWidth) / 2), "X"
lstXY.Add Me.FormatValue((Me.TopMargin + Me.PrinttableHeight) / 2), "Y"
Info = Info & " Точка_5: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
CenterBounds.Add lstXY, "Bounds_5"
Set lstXY = New Collection
lstXY.Add Me.FormatValue(Me.LeftMargin + Me.PrinttableWidth), "X"
lstXY.Add Me.FormatValue((Me.TopMargin + Me.PrinttableHeight) / 2), "Y"
Info = Info & " Точка_6: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
CenterBounds.Add lstXY, "Bounds_6"
Set lstXY = New Collection
lstXY.Add Me.FormatValue(Me.LeftMargin), "X"
lstXY.Add Me.FormatValue(Me.TopMargin + Me.PrinttableHeight), "Y"
Info = Info & " Точка_7: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
BottomBounds.Add lstXY, "Bounds_7"
Set lstXY = New Collection
lstXY.Add Me.FormatValue((Me.LeftMargin + Me.PrinttableWidth) / 2), "X"
lstXY.Add Me.FormatValue(Me.TopMargin + Me.PrinttableHeight), "Y"
Info = Info & " Точка_8: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
BottomBounds.Add lstXY, "Bounds_8"
Set lstXY = New Collection
lstXY.Add Me.FormatValue((Me.LeftMargin + Me.PrinttableWidth)), "X"
lstXY.Add Me.FormatValue(Me.TopMargin + Me.PrinttableHeight), "Y"
Info = Info & " Точка_9: X = " & lstXY(1) & "; "
Info = Info & "Y = " & lstXY(2) & Chr(13)
BottomBounds.Add lstXY, "Bounds_9"
PrinttableBounds.Add TopBounds, "TopBounds"
PrinttableBounds.Add CenterBounds, "CenterBounds"
PrinttableBounds.Add BottomBounds, "BottomBounds"
Info = "Координаты точек внутреннего поля:" & Chr(13) & Info
PrinttableBounds.Add Info
End PropertyСтраницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться