C# Snippets
Assembly_GetVersion
Public Shared Function GetVersion(ByVal objAssembly As System.Reflection.Assembly) _
As String
GetVersion = ""
Try
If gbEND_GENERAL = True Then Exit Function
Dim slocation As String
Dim iDebugAttributeLength As Integer
Dim sDebugFlag As String = ""
slocation = objAssembly.Location
objAssembly = System.Reflection.Assembly.LoadFrom(slocation)
iDebugAttributeLength = objAssembly.GetCustomAttributes(GetType(System.Diagnostics.DebuggableAttribute), False).Length
If iDebugAttributeLength > 0 Then sDebugFlag = "D"
If iDebugAttributeLength = 0 Then sDebugFlag = "R"
GetVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(slocation).ProductVersion & sDebugFlag
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL_ERRMSG = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("GetVersion", msCLASSNAME, _
"", _
mobjCOMException, mobjException)
End If
End Try
End Function
Graphics_FontNew
Public Shared Function FontNew(ByVal sFontName As String, _
ByVal sngFontSize As Single, _
ByVal bBold As Boolean, _
ByVal bItalic As Boolean, _
ByVal bUnderline As Boolean, _
ByVal bStrikeout As Boolean) _
As System.Drawing.Font
Try
If gbEND_GENERAL = True Then Exit Function
Dim objFont As System.Drawing.Font
Dim objFontStyle As System.Drawing.FontStyle
If bBold = False Then objFontStyle = objFontStyle Or Drawing.FontStyle.Regular
If bBold = True Then objFontStyle = objFontStyle Or Drawing.FontStyle.Bold
If bItalic = True Then objFontStyle = objFontStyle Or Drawing.FontStyle.Italic
If bUnderline = True Then objFontStyle = objFontStyle Or Drawing.FontStyle.Underline
If bStrikeout = True Then objFontStyle = objFontStyle Or Drawing.FontStyle.Strikeout
objFont = New System.Drawing.Font(sFontName, sngFontSize, objFontStyle)
FontNew = objFont
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("FontNew", msCLASSNAME, _
"", _
mobjCOMException, mobjException)
End If
End Try
End Function
Graphics_ReturnDrawingColor
Public Shared Function ReturnDrawingColor(ByVal sColour As String) As System.Drawing.Color
Try
If gbEND_GENERAL = True Then Exit Function
Dim objColor As System.Drawing.Color
Select Case sColour.ToUpper
Case "WHITE" : objColor = System.Drawing.Color.White
Case "YELLOW" : objColor = System.Drawing.Color.Yellow
End Select
ReturnDrawingColor = objColor
Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then
Call clsError.Handle("ReturnDrawingColor", "clsCmdBar", _
"", _
gobjCOMException, gobjException)
End If
End Try
End Function
Resource_SaveAs
Public Sub Resource_SaveAs(ByVal sResourceFileName As String, _
ByVal sFolderPath As String, _
ByVal sFileName As String, _
ByVal bDeleteIfExists As Boolean, _
Optional ByVal bInformUser As Boolean = True)
Dim sNameSpace As String
Dim objStream As System.IO.Stream
Dim objFileStream As System.IO.FileStream
Try
If modGeneral.File_Exists(sFolderPath & sFileName, False) = True Then
If (bDeleteIfExists = True) Then
Call modGeneral.File_Delete(sFolderPath, sFileName, "")
Else
If (bInformUser = True) Then
'tell user the file already exists and will be replaced
End If
End If
End If
sNameSpace = System.Reflection.Assembly.GetExecutingAssembly().GetName.Name.ToString
objStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(sNameSpace & "." & sResourceFileName)
objFileStream = New System.IO.FileStream(sFolderPath & sResourceFileName, IO.FileMode.CreateNew)
If Not (objStream Is Nothing) Then
For lcount As Long = 0 To (objStream.Length - 1)
objFileStream.WriteByte(CType(objStream.ReadByte, Byte))
Next lcount
End If
objFileStream.Close()
Catch ex As Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top