Command Line Argument c# - c#

I have a standalone example program which when executed gives a terminal to get the input as "0" and then shows another window which is essentially the camera function.
program for camera which intakes the command line arguments:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using mv.impact.acquire;
#if USE_DISPLAY
using mv.impact.acquire.display;
#endif // #if USE_DISPLAY
using mv.impact.acquire.examples.helper;
namespace SW_FormsApplication3
{
class ContinousCapture
{
public static void StartCamera(string[] args)
{
//Acquire camera image and display it on window
}//End Method
}//End class
}//End namespace
My toolstrip button to invoke the method:
private void toolStripButton2_Click(object sender, EventArgs e)
{
ContinousCapture.StartCamera();
}
I want to implement the same in my application but in my case, I should click a button on the form (toolstrip button) so that I can have the image window show up. How can I achieve this, meaning how to invoke a method that takes in command line args ?
I have already tried, ContinousCapture.StartCamera(null); I have resolved the problem with PDB file but not able to figure out why the console doesnt show up.

Simple as that ContinousCapture.StartCamera(null);

Related

How can the current barcode scan output the value?

I use a GD4430 handheld scanner from the company Datalogic with the included OPOS driver. With the following code I manage to address the scanner. When I start the program, the scanner becomes active and you can scan. But I can not display the results in a TextBox.
Does anyone see where the error lies?
Visual Studio 2010 C#
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 TestRead
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
axOPOSScanner1.BeginInit();
axOPOSScanner1.Open("USBHHScanner");
axOPOSScanner1.ClaimDevice(0);
axOPOSScanner1.DeviceEnabled = true;
axOPOSScanner1.DataEventEnabled = true;
axOPOSScanner1.PowerNotify = 1; //(OPOS_PN_ENABLED);
axOPOSScanner1.DecodeData = true;
}
void axOPOSScanner1_DataEvent(object sender, AxOposScanner_CCO._IOPOSScannerEvents_DataEventEvent e)
{
textBox1.Text = axOPOSScanner1.ScanDataLabel;
textBox2.Text = axOPOSScanner1.ScanData.ToString();
axOPOSScanner1.DataEventEnabled = true;
axOPOSScanner1.DataEventEnabled = true;
}
}
}
Was not the processing of AxOPOSScanner1.BeginInit() on the source originally in Form1.Designer.cs instead of here?
(I am assuming that the source file name is Form1.cs)
As below(in Form1.Designer.cs):
this.axOPOSScanner1 = new AxOposScanner_CCO.AxOPOSScanner();
((System.ComponentModel.ISupportInitialize)(this.axOPOSScanner1)).BeginInit();
this.SuspendLayout();
There is a possibility that the problem has occurred because you moved it to Form1.cs or calling BiginInit() on both Form1.Designer.cs and Form1.cs.
Or, the following processing does not exist in Form1.Designer.cs, or there is a possibility that the specified function name(axOPOSScanner1_DataEvent) is wrong.
this.axOPOSScanner1.DataEvent += new AxOposScanner_CCO._IOPOSScannerEvents_DataEventEventHandler(this.axOPOSScanner1_DataEvent);
In addition:
What you should do is to temporarily store the return value of all the methods, add a process to determine whether the method was executed normally, likewise It is to read the ResultCode property immediately after setting the property(possibly causing an error) and add processing to judge whether the property setting was done normally.
Also, although not related to DataEvent, PowerNotify setting must be done before DeviceEnabled = true.

Visual C# - Changing button's background image programmatically

So I'm trying to make a simple program in Visual C# that counts the number of "Connected Devices", which can be seen as the amount of buttons clicked.
The code should check which button was clicked and change it's background image. It should also update the count and label on the form.
First of all, here's my 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;
namespace Device_Storage
{
public partial class Form1 : Form
{
int totalDevices = 0;
public Form1()
{
InitializeComponent();
}
private void addDevice(object sender, EventArgs e)
{
try
{
Button clickedBtn = sender as Button;
Image add_image = Properties.Resources.addDevice;
Image remove_image = Properties.Resources.removeDevice;
if (clickedBtn.BackgroundImage == Properties.Resources.addDevice)
{
clickedBtn.BackgroundImage = remove_image;
totalDevices++;
}
else if (clickedBtn.BackgroundImage == Properties.Resources.removeDevice)
{
clickedBtn.BackgroundImage = add_image;
totalDevices--;
}
updateLabel();
} catch (Exception ex)
{
MessageBox.Show(ex.Message, "An Error Occured");
}
}
private void updateLabel()
{
label1.Text = "Connected devices: " + totalDevices;
}
}
}
(I didn't change any of the using statements yet, I usually do that when I'm finished or am 100% sure I won't be using the namespace)
I can't find anything wrong with the code myself and Visual Studio (2015) doesn't give an error.
When I click a button (there are 36 total buttons) nothing happens, the label doesn't update, the image doesn't change, nothing. I don't even get an error, the program doesn't crash.
If anyone can see what I did wrong and can help me fix it that would be really appreciated.
(Edit: My resources folder contains 2 png files, "addDevice.png" and "removeDevice.png")
(New info: all buttons start with the background image "addDevice.png" as to represent an empty slot)

how to use run two processes on visual studio

I am writing a game in XNA, and I have the login screen, which is windows form, and the game itself. I need to go from the login screen to the game, but when I try it says that i can't run more then one thred at the time. how can i solve this?
this is the login screen 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 ProtoType
{
public partial class SighIn : Form
{
public SighIn()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if ((textBox1.Text.Equals("Developer")) && (textBox2.Text.Equals("poxus17")))
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}
}
The XNA Game.Run method executes Application.Run which provides a message pump for the primary thread (UI thread).
At the point in time where your form is running and gets a button click, Application.Run is already executing (possibly through Form.ShowDialog). You cannot have two message pumps in the same thread, at the same time.
The solution is to allow Application.Run to finish, then call Game.Run.
Something like this:
Form form = new SignIn();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.UserName =="Developer" && form.Password == "poxus17")
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
Now your form's button click handler can copy the textbox fields to properties (UserName, and Password) and set this.DialogResult = DialogResult.OK. This will close the form, completing the message pump started by ShowDialog, then, after verification, start a new message pump with Game.Run.

Form freezing when loaded from a DLL that is imported at runtime in a console application

Continuing from my previous question: Trying to show a Windows Form using a DLL that is imported at the runtime in a console application
The form I am showing using the code given in the answer to my previous question by #Ksv3n is freezing (showing a wait cursor over it). For code please check out above link.
Try to use a BackgroundWorker, like this:
(I dind't compiled the code, this is an example for the approach)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
namespace DLLTest
{
class Program
{
static void Main(string[] args)
{
BackgroundWorker m_oWorker;
m_oWorker = new BackgroundWorker();
m_oWorker.DoWork += new DoWorkEventHandler(m_oWorker_DoWork);
m_oWorker.RunWorkerAsync();
Console.ReadLine();
}
static void m_oWorker_DoWork(object sender, DoWorkEventArgs e)
{
string DLLPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\TestLib.dll";
var DLL = Assembly.LoadFile(DLLPath);
foreach (Type type in DLL.GetExportedTypes())
{
dynamic c = Activator.CreateInstance(type);
c.test();
}
}
}
}
Online Resource:Background Worker for Beginners

Why is the program form not loading when accessing file?

With the below code, I've tested it out and the loading of the form works fine standalone, but when the program goes to check if a file exists, the form doesn't load properly and I'm at a loss as to what to do. Is there another method of checking to see if a file exists that I could use in this instance?
EDIT I've made a new 'startup' form to run the file exists check, but it still doesn't work. Again the form loads, but the contents of the form don't and the form itself freezes.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
using System.Windows.Input;
namespace program1
{
public partial class Startup : Form
{
public Startup()
{
InitializeComponent();
}
private void Startup_Load(object sender, EventArgs e)
{
notifyIcons norm = new notifyIcons();
Settings set = new Settings();
set.Show();
string curFile = Environment.CurrentDirectory + "\\age.txt";
if (File.Exists(curFile))
{
norm.Show();
this.Close();
}
else
{
set.Show();
for (;;)
{
if (File.Exists(curFile)) norm.Show(); this.Close();
Application.DoEvents();
}
}
}
}
}
I have no idea what this code is supposed to do.. but I can tell you why its not working.
while (ageFileExists)
That is never false. Therefore, your loop will continually loop... forever. You need to set it false somehow in the loop. I have no idea what sort of rules govern that though.
The reason the form doesn't load is because the loop never exits.. and so the message loop that makes the window do anything can never continue processing window messages.
If you can give more context around what you're trying to do I could help you with a proper solution. As it stands though, I can only see the problem.
while(ageFileExists)
{
if (File.Exists(curFile)) ageFileExists = true;
set.WindowState = FormWindowState.Normal;
}
If that file exists you have an infinite loop. You never set ageFileExists to false and that loop does nothing at all. And where does that label go? I seriously doubt you need to be using goto. Your code doesn't make much sense as it stands.
By using the following code in the main form, it seemed to work a treat! I think the critical part was Application.DoEvents();
Thanks for all of your assistance
InitializeComponent();
set.Show();
set.WindowState = FormWindowState.Minimized;
string curFile = Environment.CurrentDirectory + "\\age.txt";
if (File.Exists(curFile)) goto Labelx;
set.WindowState = FormWindowState.Normal;
for (; ; ) { Application.DoEvents(); if (File.Exists(curFile)) break; }
set.WindowState = FormWindowState.Minimized;
Labelx:TextReader reader = File.OpenText(Environment.CurrentDirectory + "\\age.txt");

Categories

Resources