-
novice C# user
Hallo I'm a novice C# user and I'm not the kind to do tutorials, I'm more of a learning by f... doing.
But this attitude has put me in a bit of a situation.
I'm making a Lab to RGB converter (for those of you who know about colours) so we don't have any compatibility issues around the office (some ppl use open office some use microsoft office, the OS 10 issus ill deal with later).
up til now i'v got it all pretty much running but I am having difficulty getting my output in a textbox.
Ill try to explain. I get an output of 3 doubles and now i need these doubles to follow in succession (an R, G and B value) in a textbox.
I'll add my code and all input, even if it is not an answer, is welcome.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsLABtoRGB
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Double L, a, b, X, Y, Z, var_X, var_Y, var_Z;
Double ref_X, ref_Y, ref_Z, var_R, var_B, var_G, R, G, B;
L = double.Parse(textBox1.Text);
a = double.Parse(textBox2.Text);
b = double.Parse(textBox3.Text);
var_Y = (L + 16) / 116;
var_X = a / 500 + var_Y;
var_Z = var_Y - b / 200;
if (Math.Pow(var_Y, 3) > 0.008856)
var_Y = (Math.Pow(var_Y, 3));
else
var_Y = ((var_Y - 16 / 116) / 7.787);
if (Math.Pow(var_X, 3) > 0.008856)
var_X = (Math.Pow(var_X, 3));
else
var_X = (var_X - 16 / 116) / 7.787;
if (Math.Pow(var_Z, 3) > 0.008856)
var_Z = Math.Pow(var_Z, 3);
else
var_Z = (var_Z - 16 / 116) / 7.787;
// Observer= 2°, Illuminant= D65
ref_X = 95.047;
ref_Y = 100.000;
ref_Z = 108.883;
X = ref_X * var_X;
Y = ref_Y * var_Y;
Z = ref_Z * var_Z;
var_X = X / 100;
var_Y = Y / 100;
var_Z = Z / 100;
var_R = var_X * 3.2406 + var_Y * -1.5372 + var_Z * -0.4986;
var_G = var_X * -0.9689 + var_Y * 1.8758 + var_Z * 0.0415;
var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * 1.0570;
if (var_R > 0.0031308)
var_R = 1.055 * Math.Pow(var_R, (1 / 2.4)) - 0.055;
else
var_R = 12.92 * var_R;
if (var_G > 0.0031308)
var_G = 1.055 * Math.Pow(var_G, (1 / 2.4)) - 0.055;
else
var_G = 12.92 * var_G;
if (var_B > 0.0031308)
var_B = 1.055 * Math.Pow(var_B, (1 / 2.4)) - 0.055;
else
var_B = 12.92 * var_B;
R = var_R * 255;
G = var_G * 255;
B = var_B * 255;
//THIS IS WHERE I WOULD LIKE HELP
//THIS IS WHERE I WOULD LIKE HELP
//THIS IS WHERE I WOULD LIKE HELP
//THIS IS WHERE I WOULD LIKE HELP
//THIS IS WHERE I WOULD LIKE HELP
//THIS IS WHERE I WOULD LIKE HELP
//THIS IS WHERE I WOULD LIKE HELP
//THIS IS WHERE I WOULD LIKE HELP
}
// numbers only textbox1,2,3
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case '.':
break;
case '-':
break;
default:
if (!Char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
break;
}
}
If you see anything you might not do for any reason please tell me. I'm here to learn.
-
Re: novice C# user
Hello and welcome to the VB forums, I am sure an admin will come along and move you to the correct place!
-
Re: novice C# user
Thread moved from the 'VB.Net' forum to the 'C#' forum (thanks for letting us know Grimfort :thumb: )
-
Re: novice C# user
String.Format would be the perfect option for creating one String out of three Doubles.
-
Re: novice C# user
Thank u grimfort for getting moved. Nice :)
-
Re: novice C# user
jmcilhinney - String.Format would be the perfect option for creating one String out of three Doubles.
thank you very much for your fast reply.
and what do you know it works:-)
but I'd like for my code to show the numbers in a format where it forces a 0 or two 00 in front if the actual number only has 2 or 1 digit.
So my question is do you think I should use a if loop or is a case a better way of going about it??
-
Re: novice C# user
String.Format can do that. Read the documentation and it will tell you all about what it can do.
-
Re: novice C# user