c# invokeMember click won't work - c#

So I load a webpage, that has this in its html code:
<input style="margin-left: 140px;" name="e43X45asfaw4ybrZ34fi879234tg3e4eex" type="submit" id="submit" value="Begå kriminaliteten!" onmouseover="$('#ggg').fadeIn().delay(3000).fadeOut();">
and I use this to click it:
object o = webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("e43X45asfaw4ybrZ34fi879234tg3e4eex")[0].InvokeMember("click");
if (o != null)
{
MessageBox.Show("It worked!");
}
else
{
MessageBox.Show("It didnt work!");
}
and that code always leave it didn't work as well it didn't do anything to the webpage.
Here is my full 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 MafiaspilletRankeBot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("mafiaspillet.no");
webBrowser1.ScriptErrorsSuppressed = true;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
timer1.Enabled = true;
timer1.Interval = 15000;
}
catch {
timer1.Enabled = false;
MessageBox.Show("Timer error", "Looks like there a error");
}
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
timerun.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("brukernavn")[0].SetAttribute("value", textBox1.Text);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("passord")[0].SetAttribute("value", textBox2.Text);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("login_buton")[0].InvokeMember("click");
timer2.Enabled = true;
timer2.Interval = 15000;
timer1.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
webBrowser1.Navigate("http://mafiaspillet.no/kriminalitet3.php");
timer3.Enabled = true;
timer3.Interval = 15000;
timer2.Enabled = false;
}
private void timer3_Tick(object sender, EventArgs e)
{
object o = webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("e43X45asfaw4ybrZ34fi879234tg3e4eex")[0].InvokeMember("click");
if (o != null)
{
MessageBox.Show("It worked!");
}
else
{
MessageBox.Show("It didnt work!");
}
MessageBox.Show("Bot finnished!", "YEEY!");
timer3.Enabled = false;
}
int i = 0;
private void runtime_Tick(object sender, EventArgs e)
{
i++;
timerun.Text = i.ToString() + " Sekunder";
}
}
}
So my problem is that the InvokeMember("click") doesn't work in my public void timer3_Tick.
It's like it can't do anything, but I can't find the problem :/

you need to processing in the function WebBrowserDocumentCompletedEventArgs
here full code
private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElementCollection inputCol = this.WebBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement el in inputCol)
{
if (el.GetAttribute("type").Equals("submit"))
{
el.InvokeMember("Click");
MessageBox.Show("It worked!");
}
}
}

Related

How to make two forms receive information from the serial port that receives information from Arduino?

I am developing a graphical interface that reads variables from different sensors that arrive through the serial port, so far I have managed to read all the variables with a single form but now I want to have two forms.
The first form asks the user to choose the COM and confirms whether the connection was successful or not. Once the connection is successful, the second form is opened where the variables from the sensors will be shown in "labels", the readings sent from Arduino are read by the serial port and stored in an array:
data[0], data[1], data[2] etc...
This is the first form where Serialport1 is found and the data arrives through the serialPort1_DataReceived event:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Media;
namespace AUTOCLAVES_GUI
{
public partial class GUI_AUTOCLAVES_GENERADOR_DE_VAPOR : Form
{
/*VARIABLES GLOBALES*/
string puerto_seleccionado;
public GUI_AUTOCLAVES_GENERADOR_DE_VAPOR()
{
InitializeComponent();
string[] puertos = SerialPort.GetPortNames();
foreach (string mostrar in puertos)
{
comboBox1.Items.Add(mostrar);
}
}
private void Salir_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Minimizar_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void Maximizar_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Maximized;
Maximizar.Visible = false;
Restaurar.Visible = true;
}
private void Restaurar_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Normal;
Restaurar.Visible = false;
Maximizar.Visible = true;
}
private void MenuSideBar_Click(object sender, EventArgs e)
{
if (Sidebar.Width == 270)
{
Sidebar.Visible = false;
Sidebar.Width = 68;
SidebarWrapper.Width = 90;
LineaSidebar.Width = 68;
AnimacionSidebar.Show(Sidebar);
}
else
{
Sidebar.Visible = false;
Sidebar.Width = 270;
SidebarWrapper.Width = 300;
LineaSidebar.Width = 268;
AnimacionSidebarBack.Show(Sidebar);
}
}
private void bunifuFlatButton8_Click(object sender, EventArgs e)
{
try
{
serialPort1.Close();
serialPort1.Dispose();
serialPort1.Open();
CheckForIllegalCrossThreadCalls = false;
label2.Text = "CONEXIÓN EXITOSA";
label2.ForeColor = Color.Green;
label2.Font = new Font(label2.Font, FontStyle.Bold);
openChildForm(new MUESTREO_EN_TIEMPO_REAL());
}
catch
{
label2.Text = "CONEXIÓN FALLIDA";
label2.ForeColor = Color.Red;
label2.Font = new Font(label2.Font, FontStyle.Bold);
MessageBox.Show("REVISE CONEXIÓN DE ARDUINO", "ADVERTENCIA", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
puerto_seleccionado = comboBox1.Text;
serialPort1.PortName = puerto_seleccionado;
}
private void bunifuFlatButton7_Click(object sender, EventArgs e)
{
comboBox1.Items.Clear();
label2.Text = "SIN CONEXIÓN";
label2.ForeColor = Color.White;
string[] puertos = SerialPort.GetPortNames();
foreach (string mostrar in puertos)
{
comboBox1.Items.Add(mostrar);
}
}
private Form activeForm = null;
private void openChildForm(Form childForm)
{
if (activeForm != null)
activeForm.Close();
activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
panel1.Controls.Add(childForm);
panel1.Tag = childForm;
childForm.BringToFront();
childForm.Show();
}
private void bunifuFlatButton2_Click(object sender, EventArgs e)
{
openChildForm(new MUESTREO_EN_TIEMPO_REAL());
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string[] data = serialPort1.ReadLine().Split(',');
if (data.Length > 10)
{
}
else
{
MessageBox.Show("Intente nuevamente", "ADVERTENCIA", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
}
}
}
Here is my second form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AUTOCLAVES_GUI
{
public partial class MUESTREO_EN_TIEMPO_REAL : Form
{
public MUESTREO_EN_TIEMPO_REAL()
{
InitializeComponent();
}
private void MUESTREO_EN_TIEMPO_REAL_Load(object sender, EventArgs e)
{
}
private void Salir_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
I hope someone can help me overcome this problem.

C# Serial Port Communication Arduino

I have a project where I need to communicate with Arduino over the serial ports. The problem I face is that I cannot print continously the data I receive from the serial monitor on multiple lines on a richtextbox. When I press the button "Reveice" I do receive only one value and after this, pressing again the Receive button will overwrite the line.
I'm tring to fix this for few days, but it's my first time programming in c# so I'm asking for your help.
The code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace aplicatie_comanda_v1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
getAvilablePorts();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Close();
progressBar1.Value = 0;
button3.Enabled = true;
button1.Enabled = false;
receive.Enabled = false;
richTextBox1.Clear();
}
private void label1_Click(object sender, EventArgs e)
{
}
void getAvilablePorts()
{
string[] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
try
{
if (comboBox1.Text == "" || comboBox2.Text == "" && serialPort1 != null && serialPort1.IsOpen)
{
richTextBox1.Text = "Select COM port and BAUD rate !";
serialPort1.Close();
}
else
{
string cmd = Convert.ToString(comboBox1.Text);
int baud = Convert.ToInt32(comboBox2.Text);
serialPort1.PortName = cmd;
serialPort1.BaudRate = baud;
serialPort1.DtrEnable = true;
serialPort1.RtsEnable = true;
serialPort1.Open();
progressBar1.Value = 100;
button1.Enabled = true;
button2.Enabled = true;
textBox1.Enabled = true;
button3.Enabled = false;
}
}
catch (UnauthorizedAccessException)
{
richTextBox1.Text = "Unauthorized !";
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string text = textBox1.Text;
serialPort1.Write(text);
}
private void receive_Click(object sender, EventArgs e)
{
try
{
richTextBox1.Text = serialPort1.ReadLine() + "\n";
}
catch (TimeoutException)
{
richTextBox1.Text = "Timeout !";
}
}
private void button4_Click(object sender, EventArgs e)
{
serialPort1.Write("w");
}
private void button5_Click(object sender, EventArgs e)
{
serialPort1.Write("s");
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
serialPort1.Write("a");
}
private void button7_Click(object sender, EventArgs e)
{
serialPort1.Write("d");
}
private void button12_Click(object sender, EventArgs e)
{
serialPort1.Write("b");
}
private void button13_Click(object sender, EventArgs e)
{
string cmd = Convert.ToString(trackBar1.Value);
serialPort1.Write(cmd);
}
private void button8_Click(object sender, EventArgs e)
{
serialPort1.Write("q");
}
private void button11_Click(object sender, EventArgs e)
{
serialPort1.Write("e");
}
private void button9_Click(object sender, EventArgs e)
{
serialPort1.Write("z");
}
private void button10_Click(object sender, EventArgs e)
{
serialPort1.Write("c");
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
while (serialPort1.IsOpen)
{
try
{
string date = serialPort1.ReadLine();
richTextBox1.Text = date + "\n";
}
catch (TimeoutException)
{
richTextBox1.Text = "Timeout !";
}
}
}
}
}
Print screen of the final app: http://i.imgur.com/5f8EOly.png
Thank you !
I haven't written any Serial applications in C# yet, but already did a few projects involving Java <-> Arduino communication.
My first guess would be that you overwrite the existing line with the received line.
richTextBox1.Text = serialPort1.ReadLine() + "\n";
instead you would want:
richTextBox1.Text += serialPort1.ReadLine() + "\n";
Also you should take a look at this article on MSDN:
https://msdn.microsoft.com/en-us/library/system.io.ports.serialport.datareceived(v=vs.110).aspx
This shows how you could use Events to continuously receive text from the Arduino.

Backgroundworker lag when starting, split method for multiple threads

The below code is for searching files. The thing is that when I select a large folder (like C disk) program starts with some delay. I think I need to divide disk into smaller parts (folders) and run it on different threads, but I do not know how.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
using System.Collections;
using System.Diagnostics;
namespace failu_paieska
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
}
FolderBrowserDialog Folder = new FolderBrowserDialog();
Stopwatch stopwatch = new Stopwatch();
static List<string> lstFilesFound = new List<string>();
int fileCount;
int fileCount1;
//string test;
private void Form1_Load(object sender, EventArgs e)
{
//label2.Text = Environment.ProcessorCount.ToString();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = Folder.ShowDialog();
textBox2.Text = Folder.SelectedPath.ToString();
}
private void IdetiIListbox()
{
foreach (string n in lstFilesFound.ToList())
{
stopwatch.Start();
if (Path.GetFileName(n).Contains(textBox1.Text.ToString()))
{
this.BeginInvoke(new MethodInvoker(() =>
{
listBox1.Items.Add(n);
//progressBar1.Value++;
}));
}
}
stopwatch.Stop();
int paieska = listBox1.Items.Count;
this.BeginInvoke(new MethodInvoker(() =>
{
textBox3.Text = Convert.ToString(stopwatch.Elapsed);
}));
}
public void Ieskoti1()
{
foreach (string ff in Directory.EnumerateFiles(textBox2.Text.ToString(), "*.*"))
{// Paima failus is pirmo katalogo
lstFilesFound.Add(ff);
fileCount1 = lstFilesFound.Count();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy != true)
{
backgroundWorker1.RunWorkerAsync(textBox2.Text.ToString());
}
}
static void DirSearch(string sDir)
{
foreach (string d in Directory.EnumerateDirectories(sDir))
{
try
{
lstFilesFound.Add(d);
//visoFailu += 1;
foreach (string f in Directory.EnumerateFiles(d, "*.*"))
{
//visoFailu += 1;
lstFilesFound.Add(f);
}
DirSearch(d);
}
catch (Exception ee)
{
}
continue;
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label4.Text = (e.ProgressPercentage.ToString() + "%");
progressBar1.Value = e.ProgressPercentage;
}
private void backgroundWorker1_DoWork_1(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
//DirSearch(textBox2.Text.ToString());
Ieskoti1();
DirSearch(textBox2.Text.ToString());
// IdetiIListbox();
for (int i = 0; i <= 100; i++)
{
backgroundWorker1.ReportProgress(i);
System.Threading.Thread.Sleep(100);
}
}
private void backgroundWorker1_RunWorkerCompleted_1(object sender, RunWorkerCompletedEventArgs e)
{
//DirSearch(textBox2.Text.ToString());
IdetiIListbox();
if (e.Cancelled == true)
{
MessageBox.Show("Cancelled!");
}
else if (e.Error != null)
{
MessageBox.Show("Error: " + e.Error.Message);
}
else
{
MessageBox.Show("Done!");
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
fileCount = Directory.GetFiles(textBox2.Text.ToString()).Length;
}
}
}

"System.UnauthorizedAccessException" error when opening second serial port

i Need to open a second serialPort in my Visual C# program to read data from my arduino.
it already worked fine, but in the case you see below it does not work..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using CommandsPD4I;
namespace CSharpExample
{
public partial class CSharpExample : Form
{
public ComMotorCommands motor1;
public CSharpExample()
{
InitializeComponent();
motor1 = new ComMotorCommands();
motor1.SetSteps(Convert.ToInt32(numericSchritte.Value));
}
SerialPort arduino;
delegate void InvokeLB(string Data);
InvokeLB lbRecievedDelegate;
int xPos = 0;
private void StartBtn_Click(object sender, EventArgs e)
{
// Set comm settings for motor 1
motor1.SelectedPort = ComPortBox1.Text;
motor1.Baudrate = Convert.ToInt32(BaudrateBox1.Text);
// Set motor address
motor1.MotorAddresse = Convert.ToInt32(Motor1ID.Value);
// Set relative positioning mode
motor1.SetPositionType(1);
// Start travel profile
if (motor1.ErrorFlag)
{
StatusLabel1.Text = "Status 1: " + motor1.ErrorMessageString;
}
else
{
StatusLabel1.Text = "Status 1: OK";
}
}
private void StopBtn_Click(object sender, EventArgs e)
{
// Stop travel profile
motor1.StopTravelProfile();
}
private void timer1_Tick(object sender, EventArgs e)
{
lblPosition.Text = Convert.ToString(motor1.GetPosition());
lblStatus.Text = motor1.ErrorMessageString;
// this.chart1.Series["Kraft"].Points.AddXY(xPos, Convert.ToDouble(lblKraft.Text));
// xPos++;**strong text**
}
private void btnHoch_Click(object sender, EventArgs e)
{
motor1.SetDirection(0);
motor1.SetPositionType(1);
motor1.StartTravelProfile();
}
private void btnRunter_Click(object sender, EventArgs e)
{
motor1.SetDirection(1);
motor1.SetPositionType(1);
motor1.StartTravelProfile();
}
private void numericSchritte_ValueChanged(object sender, EventArgs e)
{
motor1.SetSteps(Convert.ToInt32(numericSchritte.Value));
}
private void numericGeschwindigkeit_ValueChanged(object sender, EventArgs e)
{
motor1.SetMaxFrequency(Convert.ToInt32(numericGeschwindigkeit.Value));
}
private void btnDiagramm_Click(object sender, EventArgs e)
{
if (timer1.Enabled)
{
timer1.Stop();
}
else
{
timer1.Start();
}
}
private void btnResetDiagramm_Click(object sender, EventArgs e)
{
this.chart1.Series["Kraft"].Points.Clear();
xPos = 0;
}
private void arduino_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string RecievedLine = " ";
while (RecievedLine != "")
{
RecievedLine = arduino.ReadLine();
lblKraft.Invoke(lbRecievedDelegate, new object[] { RecievedLine });
}
}
void Invokelabel1(string Data)
{
label1.Text = Data;
this.chart1.Series["Kraft"].Points.AddXY(xPos, Convert.ToDouble(lblKraft.Text));
xPos++;
}
private void btnArduino_Click(object sender, EventArgs e)
{
//Hier erstellen wir unseren Serialport und legen die Einstellungen fest
arduino = new SerialPort("COM7", 9600);
if (!arduino.IsOpen)
{
arduino.Open();
if (arduino.IsOpen)
{
lblArduino.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(200)))), ((int)(((byte)(0)))));
lblArduino.Text = "Verbunden mit " + arduino.PortName;
}
}
lbRecievedDelegate = new InvokeLB(Invokelabel1);
arduino.DataReceived += new SerialDataReceivedEventHandler(arduino_DataReceived); //DataRecieved Event abonnieren
}
}
}
When i leave out this:
motor1.SelectedPort = ComPortBox1.Text;
motor1.Baudrate = Convert.ToInt32(BaudrateBox1.Text);
then it works..
I hope you can help :)

How do I fix this nullreferenceexception in my listbox? [duplicate]

This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 8 years ago.
Sorry for asking this question again but, I don't really know how to debug this.
The debugger is giving me nullreferenceexception in this line:
if (listBox1.SelectedItem.ToString() == "Chicken $15")
I figure that the reason why it is giving me nullreferenceexception is because listbox1 is null so I think I have to initialize it. But how? I dont know how to initialize a listbox.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lab6
{
public partial class Form1 : Form
{
double total = 0;
int x = 0;
string ord = "";
public Form1()
{
InitializeComponent();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void placeToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox1.Checked = false;
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
switch (checkBox1.Checked)
{
case true:
total += 1;
ord += "Water\n";
break;
}
if (comboBox1.Text == "Extra Meat")
{
total += 1;
ord += ord + "Extra Meat\n";
}
if (comboBox1.Text == "Extra Rice")
{
total += 1;
ord += "Extra Rice\n";
}
if (comboBox1.Text == "Extra Veggies")
{
total += 1;
ord += "Extra Veggies\n";
}
if (listBox1.SelectedItem.ToString() == "Chicken $15")
{
total += 15;
ord += " Chicken\n";
}
else { }
if (listBox1.SelectedItem.ToString() == "Pizza $8") //< my pathetic attempt to figure it out with intelisense
{
total += 8;
ord += "Pizza\n";
}
else
{
}
if (listBox1.SelectedItem.ToString() == "Spaghetti $12")//< my pathetic attempt to figure it out with intelisense
{
total += 12;
ord += " Spaghetti\n";
}
else { }
if (listBox1.SelectedItem.ToString() == "Fries $8")
{
total += 8;
ord += " Fries\n";
}
else { }
if (listBox1.SelectedItem.ToString() == "Burger $10")
{
total += 10;
ord += " Burger\n";
}
else { }
//radiobutton
if (radioButton1.Checked)
{
total+=5;
ord += "Pineapple Juice\n";
}
if (radioButton2.Checked)
{
total+=6;
ord += "Mango Juice\n";
}
if (radioButton3.Checked)
{
total+=7;
ord += "Apple Juice\n";
}
if (radioButton4.Checked)
{
total+=8;
ord += "Orange Juice\n";
}
MessageBox.Show("Order Done");
listBox1.SelectedItems.Clear();
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
ord = "";
total = 0;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void displayToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Order: " + ord+"\nTotal: "+total);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
It looks like you're assuming that listBox1.SelectedItem is never null, try doing somthing like
if (listBox1.SelectedItem != null)
{
// code here
}

Categories

Resources