Solved

Save color in a txt file from a ColorDialog?

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

Accepted Solution

by:
Mike Tomlinson earned 20 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now