PDA

View Full Version : تغییر قلم



hosein320
پنج شنبه 22 فروردین 1392, 22:58 عصر
سلام دوستان
یه سوال دارم
من رنگ و نوع قلمم رو از پایگاه داده ام میگیرم
که به صورت رشته ذخیره شده
حالا که میخوام به رنگ و نوع قلمم رو به لیبل بدم ارور میده
و میگه تبدیل رشته به فونت امکان پذیر نیست
میخواستم ببینم چجوری میشه رشته رو به نوع قابل استفاده برای فونت تبدیل کرد
برای مثال
Dim font_name as string="Color.Red"
label1.forecolor=font_name

alu0075
پنج شنبه 22 فروردین 1392, 23:24 عصر
به ظاهر سادست ولی یکم پیچیده تر از اونیه که فکر می کردم




Private Function GetFontByString(ByVal sFont As String) As Font
sFont = sFont.Substring(1, sFont.Length - 2)
sFont = Replace(sFont, ",", vbNullString)
sFont = Replace(sFont, "Font:", vbNullString)
Dim sElement() As String = Split(sFont, " ")
Dim sSingle() As String
Dim sValue As String
Dim FontName As String
Dim FontSize As Single
Dim FontStyle As FontStyle = Drawing.FontStyle.Regular
Dim FontUnit As GraphicsUnit = GraphicsUnit.Point
Dim gdiCharSet As Byte
Dim gdiVerticalFont As Boolean

For Each sValue In sElement
sValue = Trim(sValue)
sSingle = Split(sValue, "=")
If sSingle.GetUpperBound(0) > 0 Then
If sSingle(0) = "Name" Then
FontName = sSingle(1)
ElseIf sSingle(0) = "Size" Then
FontSize = CSng(sSingle(1))
ElseIf sSingle(0) = "Units" Then
FontUnit = CInt(sSingle(1))
ElseIf sSingle(0) = "GdiCharSet" Then
FontName = CByte(sSingle(1))
ElseIf sSingle(0) = "GdiVerticalFont" Then
FontName = CBool(sSingle(1))
End If
End If
Next
Return New Font(FontName, FontSize, FontStyle, FontUnit, gdiCharSet, gdiVerticalFont)
End Function



توی یک انجمن پیدا کردم
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/cdc2b1e1-7db0-4f22-8c1c-a4183ea9d5f0/

alu0075
پنج شنبه 22 فروردین 1392, 23:25 عصر
به ظاهر سادست ولی یکم پیچیده تر از اونیه که فکر می کردم




Private Function GetFontByString(ByVal sFont As String) As Font
sFont = sFont.Substring(1, sFont.Length - 2)
sFont = Replace(sFont, ",", vbNullString)
sFont = Replace(sFont, "Font:", vbNullString)
Dim sElement() As String = Split(sFont, " ")
Dim sSingle() As String
Dim sValue As String
Dim FontName As String
Dim FontSize As Single
Dim FontStyle As FontStyle = Drawing.FontStyle.Regular
Dim FontUnit As GraphicsUnit = GraphicsUnit.Point
Dim gdiCharSet As Byte
Dim gdiVerticalFont As Boolean

For Each sValue In sElement
sValue = Trim(sValue)
sSingle = Split(sValue, "=")
If sSingle.GetUpperBound(0) > 0 Then
If sSingle(0) = "Name" Then
FontName = sSingle(1)
ElseIf sSingle(0) = "Size" Then
FontSize = CSng(sSingle(1))
ElseIf sSingle(0) = "Units" Then
FontUnit = CInt(sSingle(1))
ElseIf sSingle(0) = "GdiCharSet" Then
FontName = CByte(sSingle(1))
ElseIf sSingle(0) = "GdiVerticalFont" Then
FontName = CBool(sSingle(1))
End If
End If
Next
Return New Font(FontName, FontSize, FontStyle, FontUnit, gdiCharSet, gdiVerticalFont)
End Function



توی یک انجمن پیدا کردم
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/cdc2b1e1-7db0-4f22-8c1c-a4183ea9d5f0/