Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Save color in a txt file from a ColorDialog?

Posted on 2004-09-21
2
Medium Priority
?
330 Views
Last Modified: 2010-04-23
like the topic says how do i do this?
0
Comment
Question by:stromberg10
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 80 total points
ID: 12114960
Here is a simple example of a form that stores its user customizable backcolor in a text file and restores it on form load.  Just double click the form to select a color.  Then close the form and reopen it.  The form should still be the same color.

Regards,

Idle_Mind

Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sp As String = Application.StartupPath
        If Not sp.EndsWith("\") Then
            sp = sp & "\"
        End If
        Dim fileName As String = sp & "myColor.txt"
        If File.Exists(fileName) Then
            Dim fs As StreamReader = New StreamReader(fileName)
            Try
                Dim strColor As String = fs.ReadLine()
                Dim intColor As Integer = Integer.Parse(strColor)
                Me.BackColor = Color.FromArgb(intColor)
            Catch ex As Exception
            End Try
            fs.Close()
        End If
    End Sub

    Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
        If ColorDialog1.ShowDialog = DialogResult.OK Then
            Me.BackColor = ColorDialog1.Color
        End If
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Dim sp As String = Application.StartupPath
        If Not sp.EndsWith("\") Then
            sp = sp & "\"
        End If
        Dim fs As StreamWriter = New StreamWriter(sp & "myColor.txt")
        fs.WriteLine(Me.BackColor.ToArgb.ToString)
        fs.Close()
    End Sub

End Class
0
 

Author Comment

by:stromberg10
ID: 12115942
thanks, just the answer i was looking for.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question