Tässä pätkä koodia ensin
Dim fontDlg As New FontDialog
fontDlg.ShowColor = True
fontDlg.ShowApply = False
fontDlg.ShowEffects = True
fontDlg.ShowHelp = False
fontDlg.MaxSize = 30
fontDlg.MinSize = 5
If (fontDlg.ShowDialog() = DialogResult.OK) Then
Label4.Font = fontDlg.Font
Label4.ForeColor = fontDlg.Color
Dim nimi As String
Dim koko As Integer
Dim tyyli As Integer
nimi = fontDlg.Font.Name
koko = fontDlg.Font.Size
tyyli = fontDlg.Font.Style
' vari = fontDlg.Color
FileOpen(1, "C:\set\font.set", OpenMode.Output)
Print(1, nimi & Chr(13))
Print(1, koko & Chr(13))
'Print(1, tyyli & Chr(13))
'Print(1, vari)
FileClose()miten noiden kahden puuttuvan arvon tallennus onnistuu eli Väri ja tyyli
Jos tarkoitus on lähinnä lukea tiedot myöhemmin ohjelmalliseen käyttöön, niin tallettaisin ne ihan vaan numeroina.
Moi heikkju2!
Sun kannattaa unohtaa toi sun homma heti alkuunsa syystä, että siitä puuttuu tyystin järki.
Ensinnäkään ei ole mitään hyötyä tallennella esim. Font.Style ominaisuuden arvoja tekstitiedostoon koska et voi palautella niitä suoraan minkään kontrollin Font.Style ominaisuudeksi syystä, että ko. ominaisuudet (properties) ovat ReadOnly-ominaisuuksia.
Toisekseen FontDialog palauttaa aina Color.ToString arvoksi Color[BLACK]...
Elikäs pystyäksesi hyödyntämään eri ominaisuusarvojen yhdistelmiä haluamissasi ohjausobjekteissa sinun tulisi ottaa huomioon muutama seikka joita on käsitelty mm. täällä
Heippa taas!
näin niillä voi leikkiä..
'HUOM! esimerkki on väännetty SharpDevelop 4.2/.Net Framework 4.0 ympäristössä
Imports System
Imports System.Drawing
Imports System.Configuration
Imports System.ComponentModel
Public Partial Class MainForm
Private MyFont As Font = Nothing
Private fColor As Color = Nothing
Private bColor As Color = Nothing
Private converter As TypeConverter = TypeDescriptor.GetConverter(GetType(Color))
Private config As Configuration = ConfigurationManager. _
OpenExeConfiguration(My.Application.Info.AssemblyName + ".exe")
Public Sub New()
Me.InitializeComponent()
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
With config.AppSettings.Settings
If .Item("family").Value = String.Empty Then
MyFont = New Font(New FontFamily("Microsoft Sans Serif"), 8.25!, _
CType(0,FontStyle), GraphicsUnit.Point)
Else
MyFont = New Font(New FontFamily( _
.Item("family").Value), CType(.Item("fsize").Value, Single), _
CType(.Item("fstyle").Value, FontStyle), GraphicsUnit.Point)
End If
textBox1.Font = MyFont
If .Item("fcolor").Value = String.Empty Then
fColor = Color.Black
Else
fColor = CType(converter.ConvertFromString(.Item("fcolor").Value), Color)
End If
textBox1.ForeColor = fColor
If .Item("bcolor").Value = String.Empty Then
bColor = Color.White
Else
bColor = CType(converter.ConvertFromString(.Item("bcolor").Value), Color)
End If
textBox1.BackColor = bColor
End With
textBox1.Focus
End Sub
Sub Button1Click(sender As Object, e As EventArgs)
fontDialog1.Font = MyFont
If fontDialog1.ShowDialog = DialogResult.OK Then
MyFont = fontDialog1.Font
With config.AppSettings.Settings
.Item("family").Value = fontDialog1.Font.FontFamily.Name
.Item("fsize").Value = (CType(fontDialog1.Font.Size,Single)).ToString
.Item("fstyle").Value = (CType(fontDialog1.Font.Style, Integer)).ToString
End With
textBox1.Font = MyFont
End If
If MsgBox("Tahdotko vaihtaa tekstin väriä", MsgBoxStyle.YesNo) = 6 Then
colorDialog1.Color = fColor
If colorDialog1.ShowDialog = DialogResult.OK Then
fColor = colorDialog1.Color
With config.AppSettings.Settings
.Item("fcolor").Value = "#" _
+ (fColor.R).ToString("X2") _
+ (fColor.G).ToString("X2") _
+ (fColor.B).ToString("X2")
End With
textBox1.ForeColor = fColor
End If
End If
If MsgBox("Tahdotko vaihtaa tekstin taustaväriä", MsgBoxStyle.YesNo) = 6 Then
colorDialog1.Color = bColor
If colorDialog1.ShowDialog = DialogResult.OK Then
bColor = colorDialog1.Color
With config.AppSettings.Settings
.Item("bcolor").Value = "#" _
+ (bColor.R).ToString("X2") _
+ (bColor.G).ToString("X2") _
+ (bColor.B).ToString("X2")
End With
textBox1.BackColor = bColor
End If
End If
config.Save(ConfigurationSaveMode.Modified)
textBox1.Focus
End Sub
Sub MainFormFormClosing(sender As Object, e As FormClosingEventArgs)
config = Nothing
converter = Nothing
fColor = Nothing
bColor = Nothing
MyFont.Dispose
End Sub
End Classapp.config näyttää tältä:
<?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <!--supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /--> </startup> <appSettings> <add key="family" value=""/> <add key="fsize" value=""/> <add key="fstyle" value=""/> <add key="fcolor" value=""/> <add key="bcolor" value=""/> </appSettings> </configuration>
Aihe on jo aika vanha, joten et voi enää vastata siihen.