473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB.NET - ColorDialog - Saving Custom Colours

28
On an Options form I am setting a textbox.backcolor to a colour selected from the colordialog control, so that the backcolor of all textboxes in an application may be set to the user's preference.

I know how to save strings to the registry to read them back later, but can anyone tell me how I save the backcolor of a textbox to the registry, please?

The other associated question is, "How do I save a custom colour created in the colordialog, and put it back into the colordialog when the application is next run?"

Miscrosot help imakes no mention of these problems.
Sep 4 '08 #1
4 5907
Curtis Rutland
3,256 Expert 2GB
Are you sure that you want to use the registry for this? It seems like overkill. Look into using application settings.

Right click the Project, and pick properties, and go to the settings tab. There, you can add a User-level setting of whatever datatype you want.
Picture: (ignore that it says double click, just right-click and pick properties)



So make a setting for your program, set it to whatever datatype you need.

You can refer to these settings in code by using
Expand|Select|Wrap|Line Numbers
  1. 'assume the setting is called "test" and is a string
  2. 'How you get the value:
  3. Dim s as String
  4. s = My.Settings.test
  5. 'How you set it:
  6. My.Settings.test = s
  7.  
If you make it a user setting, and then set it using the code above, it will persist even after the user closes the program.
Sep 4 '08 #2
MickT
28
Many thanks for your response, but you seem to be using a later version of Visual Studio.

I am using VS 2003, and can't find a screen showing user setting as shown in your screenshot.
Sep 5 '08 #3
Curtis Rutland
3,256 Expert 2GB
Hmmm, well maybe it is part of the 2.0 Framework and not available in 2003.

I don't really have any experience in 2k3, so I can't help you. But MS does have a free version of VB2008 available.
Sep 5 '08 #4
MickT
28
I have dowloadeded VS2008 Express Edition as you suggested, and have found the Settings that you indicated.

I have created 3 settings: -
TBoxBackColour as type color
cboBackColour as type color
CDialogCustomColours as System.Collections.Specialised.StringCollection (only array type I could find)

When I set the first two manually, the following two lines of code retrieved the settings.

txtText.BackColor = My.Settings.TBoxBackColour
txtCombo.BackColor = My.Settings.cboBackColour

However, setting all three programatically, and saving them, did not appear to work.

I have read the documentation, and it appears that the CustomColours are saved as an array of Integers. As there isn't a type of Integer Array (or string array for that matter) in the application settings, I copied the integer array into a string array, and then added them to a StringCollection. This was then entered into the application settings and saved, along with the other two settings. Sadly, none of the setting were in the Settings page.

My intention was to give a user the opportunity of setting the backcolor of textboxes and combo boxes to a colour of their choice, and keeping any custome colours they create.. Setting the colours manually doesn't achieve this.

Am I missing something? My code is below. I would appreciate any help, as I'm tearing my hair out.

************************

With dlgColour
.Color = txtText.BackColor
.AllowFullOpen = True
'.AnyColor = True
.ShowHelp = True
.Color = My.Settings.TBoxBackColour
.CustomColors = GetCustomColours()
If (dlgColour.ShowDialog() = DialogResult.OK) Then
txtText.BackColor = .Color
My.Settings.TBoxBackColour = .Color
intCustomColours = .CustomColors
My.Settings.CDialogCustomColours = SetCustomColours(intCustomColours)
My.Settings.Save()
End If
End With

************************

Public Function GetCustomColours() As Integer()
' This function extracts the ColorDialog custom colours saved in the Application
' Settings, converts them to array of Integers, and returns them to the
' ColorDialog.CustomColors

Dim intCustomColours() As Integer = New Integer() {}
Dim strCustomColours() As String = New String() {}
Dim CustomColours As StringCollection
Dim X, Y As Integer

Try
strSubName = "modGlobalUtilitiesSQL - GetCustomColours"

strSub = strSubName + " - Moving the application settings to the StringCollection"
CustomColours = My.Settings.CDialogCustomColours

strSub = strSubName + " - Moving the StringCollection to the string array"
If Not CustomColours Is Nothing Then
ReDim strCustomColours(CustomColours.Count)
CustomColours.CopyTo(strCustomColours, 0)

strSub = strSubName + " - Moving the string array to the integer array"
Y = UBound(strCustomColours)
ReDim intCustomColours(UBound(strCustomColours))
For X = 0 To UBound(strCustomColours) - 1
intCustomColours(X) = CInt(strCustomColours(X))
Next X
'GetCustomeColours = intCustomColours
'.CustomColors = intCustomColours
End If

Catch objA As Exception
MessageBox.Show("Error in sub '" & strSub & "' with " & objA.Source & _
vbCrLf & vbCrLf & objA.Message, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally
GetCustomColours = intCustomColours
End Try
End Function

Public Function SetCustomColours(ByVal intCustomColours() As Integer) As StringCollection
Dim strCustomColours() As String = New String() {}
Dim CustomColours As New StringCollection()
Dim X, Y As Integer
'Dim strItem As String

Try
strSubName = "modGlobalUtilitiesSQL - SetCustomColours"

strSub = strSubName + " - Moving the integer array to the string array"
Y = UBound(intCustomColours)
ReDim strCustomColours(UBound(intCustomColours))
For X = 0 To UBound(intCustomColours) - 1
strCustomColours(X) = CStr(intCustomColours(X))
Next X

strSub = strSubName + " - Moving the string array to the StringCollection"
CustomColours.Clear()
CustomColours.AddRange(strCustomColours)
'For X = 0 To CustomColours.Count - 1
' strItem = CustomColours(X).ToString
'Next
'SetCustomColours = CustomColours

Catch objA As Exception
MessageBox.Show("Error in sub '" & strSub & "' with " & objA.Source & _
vbCrLf & vbCrLf & objA.Message, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally
SetCustomColours = CustomColours
End Try
End Function
Sep 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mchl gdbt | last post by:
Hi, I have several thousand tiffs generated by application A which are read by application B. I need to remove a few colours from the tiffs and I decided to try with the python imaging library....
4
by: bart plessers | last post by:
Hello, I am making a website where the user can choose a 'skin'. This works with asp en stylesheets. In the stylesheet, a number of tags are (re)defined. The main idea is to have a limited...
1
by: Ekey | last post by:
Hi: I want to realize the function that get a transparent color with standard ColorDialog ,but standard ColorDialog is not transparent color.i do not want to define a dialog such as colordialog by...
2
by: SpotNet | last post by:
Hi Newsgroup, I've been creating (almost done) Common Dialog class libraries (under one name space) with highly customisable common dialogs. With my ColorDialog I am able to completely hide...
1
by: Pierre | last post by:
Hi, Allowing my User to set Excel charts colors in my app with the help of a ColorDialog, I'm facing the following problem : the ColorDialog Colors does not suit with the Excel ones. So, here...
0
by: Steve Randall | last post by:
If you enable the 'define custom colors' button on the ColorDialog control the displayed form displays the basic colors on the left-hand side and the 'color builder' on the right-hand side. ...
0
by: ThunderMusic | last post by:
Hi, problem #1 : I have a MenuStrip on my Windows form and it doesn't get painted (is transparent) unless I move the form... Anyone ever encountered this? Anyone knows what could cause it? ...
1
by: nanaalwi | last post by:
Hi all, I'm doing a software using vb.net that related to excel. The software that i implement requires filling the color inside the cells. Previously, the source code that I used is: ...
3
by: Dan Tallent | last post by:
I would like to write my Windows Form app so I can set the colors of the different controls based on a color scheme. The end goal would be to be able to go into the properties window of a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.