System.Drawing.Color

G

Greg

In code I have set the back color of my forms to one of the
System.Drawing.Color options. Anyway, I would like to make these colors
available to my users and let them chooose one for themselves. I know how to
show the color dialog, but I'd like to make these colors available to my
user's instead. Is there a color dialoog that deals with these?
 
K

kimiraikkonen

In code I have set the back color of my forms to one of the
System.Drawing.Color options. Anyway, I would like to make these colors
available to my users and let them chooose one for themselves. I know how to
show the color dialog, but I'd like to make these colors available to my
user's instead. Is there a color dialoog that deals with these?

There's "colorDialog" control in toolbox.
 
K

kimiraikkonen

In code I have set the back color of my forms to one of the
System.Drawing.Color options. Anyway, I would like to make these colors
available to my users and let them chooose one for themselves. I know how to
show the color dialog, but I'd like to make these colors available to my
user's instead. Is there a color dialoog that deals with these?

Addition: Add a button to your form and place this code inside
button1_click event:

If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.BackColor = ColorDialog1.Color
End If
 
L

Linda Liu[MSFT]

Hi Douglas,

In the Form2 within my sample project, I create a BindingSource instance to
bind to the dataset and datatable, and then bind the TextBox and two
ComboBoxes to the BindingSource instance instead of the dataset. In the
Button1's Click event handler, I call the BindingSource.EndEdit method to
apply the pending changes to the underlying data source and all works well.
The following is the modified code in the Form2:

public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private DataSet ds;
public DataSet DS
{
get { return ds; }
set { ds = value; }
}
// create a BindingSource instance
private BindingSource bs;

private void Form2_Load(object sender, EventArgs e)
{
BindingSource bsParent = new BindingSource(ds,"Measure");
BindingSource bsChild =new
BindingSource(bsParent,"Measure_Unit");
this.comboBox1.DataSource = bsParent;
this.comboBox1.DisplayMember ="Name";
this.comboBox1.ValueMember = "ID";

this.comboBox2.DataSource = bsChild;
this.comboBox2.DisplayMember = "Name";
this.comboBox2.ValueMember = "ID";

// bind the BindingSource instance to the dataset
bs = new BindingSource(ds, "DataTable1");

// bind the controls to the BindingSource instead of the dataset
this.textBox1.DataBindings.Add("Text", bs, "ID");
this.comboBox1.DataBindings.Add("SelectedValue", bs,
"MeasureID");
this.comboBox2.DataBindings.Add("SelectedValue", bs, "UnitID");

// call the BindingSource.AddNew method to add a new row
bs.AddNew();
}

private void button1_Click(object sender, EventArgs e)
{
this.comboBox2.DataBindings["SelectedValue"].WriteValue();

// call the BindingSource.EndEdit method to apply the pending
changes to the underlying data source
bs.EndEdit();
this.Close();
}
}

Since I couldn't reproduce the problem in my sample project, I strongly
recommend you to send me a sample project that could just reproduce the
problem or modify my sample project to reproduce the problem.

Thank you for your understanding and I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
F

Family Tree Mike

Linda,

It looks like you responded by accident to this email rather than the
intended.
 
L

Linda Liu[MSFT]

Hi Greg,

Sorry for my first reply which is a mistake.

As for your question, my understanding is that you want to show a color
dialog which only contains several specified colors for the user to choose.
If I'm off base, please feel free to let me know.

I find a good color picker sample in the codeproject website:

http://www.codeproject.com/KB/selection/dotnetcolorpicker.aspx

You can use the ColorPanel in the above sample to show the specified colors
for the user in your application.

Hope this is what you want.

If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

kimiraikkonen

Hi Douglas,

In the Form2 within my sample project, I create a BindingSource instance to
bind to the dataset and datatable, and then bind the TextBox and two
ComboBoxes to the BindingSource instance instead of the dataset. In the
Button1's Click event handler, I call the BindingSource.EndEdit method to
apply the pending changes to the underlying data source and all works well.
The following is the modified code in the Form2:

public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private DataSet ds;
public DataSet DS
{
get { return ds; }
set { ds = value; }
}
// create a BindingSource instance
private BindingSource bs;

private void Form2_Load(object sender, EventArgs e)
{
BindingSource bsParent = new BindingSource(ds,"Measure");
BindingSource bsChild =new
BindingSource(bsParent,"Measure_Unit");
this.comboBox1.DataSource = bsParent;
this.comboBox1.DisplayMember ="Name";
this.comboBox1.ValueMember = "ID";

this.comboBox2.DataSource = bsChild;
this.comboBox2.DisplayMember = "Name";
this.comboBox2.ValueMember = "ID";

// bind the BindingSource instance to the dataset
bs = new BindingSource(ds, "DataTable1");

// bind the controls to the BindingSource instead of the dataset
this.textBox1.DataBindings.Add("Text", bs, "ID");
this.comboBox1.DataBindings.Add("SelectedValue", bs,
"MeasureID");
this.comboBox2.DataBindings.Add("SelectedValue", bs, "UnitID");

// call the BindingSource.AddNew method to add a new row
bs.AddNew();
}

private void button1_Click(object sender, EventArgs e)
{
this.comboBox2.DataBindings["SelectedValue"].WriteValue();

// call the BindingSource.EndEdit method to apply the pending
changes to the underlying data source
bs.EndEdit();
this.Close();
}
}

Since I couldn't reproduce the problem in my sample project, I strongly
recommend you to send me a sample project that could just reproduce the
problem or modify my sample project to reproduce the problem.

Thank you for your understanding and I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support

Isn't that code a C# code in VB group? And what does differ from
Linda's code when compared to following as i understood from OP:
(nothing mentioned except form backcolor)

Bring colordialog control then:

'To change form backcolor
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.BackColor = ColorDialog1.Color
End If

Regards
 
C

Cor Ligthert[MVP]

Greg,

In my idea is this the only answer in code on your answer.
Tell me what I do see wrong?

\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles
Button1.Click
Dim colDialog As New ColorDialog
If colDialog.ShowDialog() = DialogResult.OK Then
Me.BackColor = colDialog.Color
End If
End Sub
///

Cor
 
R

RobinS

This might be what you are looking for. Unfortunately, I only have it in C#,
and
don't have time to convert it right this minute. If you can't figure it out,
post back
and I will do that this weekend. Please don't flame me for posting C#, I'm
just
trying to help here.

I started with the windows color dialog, and wasn't happy, so I am now using
a
combobox to show the colors, with OwnerDraw set up to draw a square
containing the color, and the name of the color, in each line of the
dropdown list.
I got code for that from Tim Patrick's "Start-to-Finish VB" book, or he
posted it in this forum somewhere. It didn't have info on howto get the list
though.

This uses reflection to get the same color names that are displayed in the
Visual Studio dropdown list, like "Alice Blue" and "Yellow". You have to
import
the System.Reflection namespace.

I am actually pulling the RGB values and sorting the list to try to get some
kind of
order out of it rather than alphabetical by name, but it's not a perfect
algorithm.

If you want the ownerdraw stuff, re-post, and I'll post it. It will be
in C# tho, unless I have time to convert it.

So this is how I'm retrieving the list of colors.

PropertyInfo[] props = typeof(Color).GetProperties();

foreach (PropertyInfo prop in props)
{
string cName = prop.Name;
if (cName != "Transparent")
{
ColorConverter clrConverter = new ColorConverter();
//you'll get R, G, B, A, and the properties
IsKnownColor, etc.
//put in a try/catch block so if it's not a valid color,
it just continues
try
{
Color clr =
(Color)clrConverter.ConvertFromString(cName);
if (clr.IsNamedColor)
{
System.Diagnostics.Debug.Print("Color name =
{0}", prop.Name);
}
}
catch { }
}

}

Hope that helps.

RobinS.
GoldMail, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top