I recently started using Visual Studio to update some older python scripts into stand alone UIs. I have some python experience, but C# is fairly new. Currently I am working on a calculator that will take in two user inputs, and calculate a height and width based on the items in two comboboxes.
Basically the user inputs a pixel size and file size into a text box, then selects the type of imagery from combobox1 (BW (1), Color (3), or Color-IR (4)) for my calculations I will need to reference the (1, 3, or 4) associated to the specific imagery, and in combobox2 (8 bit, or 16 bit).
Ultimately, from these inputs I am going to calculate a height and width that we can use during my project prep process. I have set up my UI and have code for my pixel size and file size, and manually added my data into both comboboxes from the properties menu for the drop down list.
I would like to create specific variables from the items in the drop down menus to use throughout my math equations.
If I have a pixel size of .2, file size of 250mb, Color, and 16 bit... calculate.
A little help in pointing me towards creating a statement like...
IF (combobox1.text == "color") and (combobox2.text == "8 bit")
// Math
...or another recommendation on the best course of action for a C# noob such as myself would be greatly appreciated!
I have tried creating a dictionary for the combobox1 with the type of imagery and the number associated with it, but I don't fully understand how to pull the (3) from Color if that is what the user selects to apply in my equations.
public partial class Form1 : Form
{
Dictionary<string, int> ColorBands = new Dictionary<string, int>
{
{"BW", 1 },
{"Color", 3 },
{"Color-IR", 4 }
};
public Form1()
{
InitializeComponent();
}
private void BT_HeightAndWidth_Click(object sender, EventArgs e)
{
try
{
// Calculate Height and Width from Pixel Value and Sheet Size.
decimal PixVal;
if (!decimal.TryParse(TXB_PixelSize.Text, out PixVal)) ;
{
MessageBox.Show("Pixel Size isn't valid!");
return;
}
decimal SheetSize;
if (!decimal.TryParse(TXB_SheetSize.Text, out SheetSize)) ;
{
MessageBox.Show("Sheet Size isn't valid!");
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}