I want to use a combo box which contain some colors to change the background color of Windows Form?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jun 28, 2014, 7:21 AM EDT
pen1 = new System.Drawing.Pen(cd.Color, 2F);
VulpesRank #55 · 29.2K reputationPosted Jun 23, 2014, 10:59 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 24, 2014, 1:19 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 24, 2014, 10:28 AM EDT
This has the advantage that the user can actually see what the colors look like. However, you're limited to a choice of 48 colors though another 16 'custom' colors can be added if you wish.
Here's how you'd show a ColorDialog on, say, a button click:
VulpesRank #55 · 29.2K reputationPosted Jun 27, 2014, 3:41 PM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 23, 2014, 9:55 PM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 24, 2014, 8:43 AM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 24, 2014, 8:50 AM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 25, 2014, 7:41 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 26, 2014, 6:55 AM EDT
The colors are all shown in little boxes.
The user just has to select one and click OK.
Joe WilsonRank #631 · 3.8K reputationPosted Jun 26, 2014, 8:50 PM EDT
My code:
private System.Drawing.Graphics g;
private System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.Blue, 2F);
private void butEllipse_Click(object sender, EventArgs e)
{
g = PictureBox1.CreateGraphics();
g.DrawEllipse(pen1, 50, 50, 100, 150);
}
private void butRectangle_Click(object sender, EventArgs e)
{
g = PictureBox1.CreateGraphics();
g.DrawRectangle(pen1, 30, 30, 50, 60);
}
Joe WilsonRank #631 · 3.8K reputationPosted Jun 28, 2014, 5:42 AM EDT
and mentioned does not take constructor that takes 2 arguments .Please check it.
Joe WilsonRank #631 · 3.8K reputationPosted Jun 28, 2014, 10:43 AM EDT