It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am working on a C# windows form application. How can i edit my code in a way that when more than 2 faces is being detected by my webcam.
More information:
When "FaceDetectedLabel.Text = "Faces Detected : " + cam.facesdetected.ToString();" becomes Face Detected: 2 or more...
How can i do the following:
Minimize all program running except my application.
Here is my code:
namespace PBD
{
public partial class MainPage : Form
{
//declaring global variables
private Capture capture; //takes images from camera as image frames
public MainPage()
{
InitializeComponent();
}
private void ProcessFrame(object sender, EventArgs arg)
{
Wrapper cam = new Wrapper();
//show the image in the EmguCV ImageBox
WebcamPictureBox.Image = cam.start_cam(capture).Resize(390, 243, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC).ToBitmap();
FaceDetectedLabel.Text = "Faces Detected : " + cam.facesdetected.ToString();
}
private void MainPage_Load(object sender, EventArgs e)
{
#region if capture is not created, create it now
if (capture == null)
{
try
{
capture = new Capture();
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
#endregion
Application.Idle += ProcessFrame;
}
check this post:
How to programmatically minimize opened window folders
You'll have to enumerate all processes and exclude the current one (yours) instead of getting the "explorer" one. I'd suggest also putting exception handling and some checks in place since not all processes have windows to be minimized
Also this post for the log off part:
Log off user from Win XP programmatically in C#
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want my ProgressBar starting in some point in my code and run total of seconds until my file finish, and of course I know how long the run of my file will take.
I try to read on MSDN but I did not understood how to use it.
My application run files (wireshark file, send the packet using bittwist) and each file will run few seconds and I want the option to see the progress ongoing.
For example I want to set my ProgressBar running for 30 seconds.
How can I do it?
Maybe you want something like this:
public void AnimateProgBar (int milliSeconds)
{
if (!timer1.Enabled) {
progressBar1.Value = 0;
timer1.Interval = milliSeconds / 100;
timer1.Enabled = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100) {
progressBar1.Value += 1;
progressBar1.Refresh();
} else {
timer1.Enabled = false;
}
}
Then you just have to call AnimateProgBar(2000) to have your ProgressBar animated during 2 seconds.
EDIT: Sorry, I posted code in VB.NET. Modified to C#.
EDIT: You can add the handler and call the function in this way (for example):
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
AnimateProgBar(2000);
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm learning threads in C# so my first program will be 2 images that will be moving. But the problem is that I get an error when I try to do a new point in a thread:
Here's my code:
namespace TADP___11___EjercicioHilosDatos
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int x = 0;
int y = 0;
private void Form1_Load(object sender, EventArgs e)
{
Thread Proceso1 = new Thread(new ThreadStart(Hilo1));
Proceso1.Start();
}
public void Hilo1()
{
while (true)
{
x = pictureBox1.Location.X - 1;
y = pictureBox1.Location.Y;
pictureBox1.Location = new Point(x, y);
}
}
}
}
You can only update a control from the thread that control was created on. Controls do have an Invoke method that you can call from another thread. This method takes a delegate that specifies the work you would like to do on the control's thread:
var updateAction = new Action(() => { pictureBox1.Location = new Point(x,y); });
pictureBox1.Invoke(updateAction);
You have to Invoke it. For [obvious] reasons, you can't access controls created by a different thread so you have to use a delegate. Several similar SO questions:
How to update the GUI from another thread in C#? (111 upvotes)
Writing to a textBox using two threads
How to update textbox on GUI from another thread in C#
Writing to a TextBox from another thread?
If you check out the first link, Ian's great answer will demonstrate how you should do this in .Net 2.0 and 3.0. Or you can scroll down to the next answer, Marc's, which will show you how to do it in the simplest way.
Code:
//worker thread
Point newPoint = new Point(someX, someY);
this.Invoke((MethodInvoker)delegate {
pictureBox1.Location = newPoint;
// runs on UI thread
});
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I need to develop a simple attendance system for a company. I am interested to develop this software in C# because I heard that .NET framework provides Barcode Scanner Libraries which makes this task easier. I have been given barcode scanner of AURORA. I have configured this scanner with my system and it reads when i swipe card before it.
I have no idea how to capture barcode information!! This is a completely new task for me and I don't know the methods which I can use to read barcode.
I know that Scaner usually read data as string, keeps it in clipboard and paste it in
active editbox or whatever it active.
For example, if I open notepad and scan card, in notepad I see the number 00004 (which i think is barcode)...
I have few questions:
1. What is the best way to read barcode value which appears on editbox (My application will have an editbox), I need to control the Scanner Event so that It should not paste barcode value in editbox by iteself, rather than I will use that value...
2. What will be the code which will fire an event when someone swipe card?
Kindly provide some working sample code(C#).Your help will be highly appreciated.
public partial class Form1 : Form
{
SerialPort _serialPort;
// delegate is used to write to a UI control from a non-UI thread
private delegate void SetTextDeleg(string text);
private void Form1_Load(object sender, EventArgs e)
{
// all of the options for a serial device
// can be sent through the constructor of the SerialPort class
// PortName = "COM1", Baud Rate = 19200, Parity = None,
// Data Bits = 8, Stop Bits = One, Handshake = None
_serialPort = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);
_serialPort.Handshake = Handshake.None;
_serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
}
private void btnStart_Click(object sender, EventArgs e)
{
// Makes sure serial port is open before trying to write
try
{
if (!_serialPort.IsOpen)
_serialPort.Open();
_serialPort.Write("SI\r\n");
}
catch (Exception ex)
{
MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");
}
}
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(500);
string data = _serialPort.ReadLine();
this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });
}
private void si_DataReceived(string data)
{
textBox1.Text = data.Trim();
}
private TextBox textBox1;
private Label label1;
private RichTextBox richTextBox1;
private Button button1;
}
Well, usually MSRs (Magnetric Stripe Readers) will dump the output to your STDIN - which means it acts like a keyboard.
You'll have to capture keyboard events in your application in order for it to read the data, start with that.
BTW:
How about your try working out some code before asking for samples?
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
In a Windows Forms app, I am using Quartz.NET to run some tasks every few minutes. Previously, this application was a console application that was invoked based on a schedule but for various reasons this wasn't ideal - back then all debug info was outputted to the console.
In this version, I need a way to show the debug information for a job on the user's screen. My initial idea was a new form that is shown when a job is run, and all debug information is appended to a multiline textbox on that form. However, this doesn't work as most of the app seems to crash when I do this.
Any other ideas?
EDIT: Sorry for any confusion. This is what's called when a job executes:
public virtual void Execute(JobExecutionContext context)
{
RunJob jobForm = new RunJob();
jobForm.Show();
jobForm.JobLabel = context.JobDetail.JobDataMap.GetString("Name");
for (int i = 0; i < 100; i++)
{
jobForm.WriteLine(i.ToString());
}
jobForm.Hide();
}
And this is the contents of the 'RunJob' form:
public partial class RunJob : Form
{
public string JobLabel
{
get
{
return lblJobName.Text;
}
set
{
lblJobName.Text = value;
}
}
public void WriteLine(string text)
{
textBox1.AppendText(text + Environment.NewLine);
}
public RunJob()
{
InitializeComponent();
}
}
Basically, the RunJob window freezes when the text is being appended, when ideally it'd just add the text smoothly. I understand 'crash' was a very poor choice of word! My excuse is that it's early in the morning, ahem
i dont see anything wrong in above code that could lead it to deadlock or whatever it is, except this line: jobForm.JobLabel = context.JobDetail.JobDataMap.GetString("Name");
what does this line does, there must be something wrong in this line,
try putting some hard coded string instead of context.JobDetail.JobDataMap.GetString("Name"); and tell me if it still doesn't work.
Job and UI form should obviously be at separate threads. Job thread should write to the form and then close it when unneeded.
Presuming you have an Action action that is invoked on UI thread:
public virtual void Execute(JobExecutionContext context)
{
RunJob jobForm;
var name = context.JobDetail.JobDataMap.GetString("Name");
action(()=> { jobForm = new RunJob(); jobForm.Show(); jobForm.JobLabel = name;});
for (int i = 0; i < 100; i++)
{
var txt = i.ToString();
action(()=>{ jobForm.WriteLine(txt); });
}
action(()=> { jobForm.Hide(); });
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
i am using visual studio 2008 c# winform. . i've make sudoku game which is working well . . i want to make best player screen for it and score depend on how much time the player take to complete game . .
i am using another form to take player name when he meets the condition for best player and give the name to label on main form but its not working.here is my code:
private void button1_Click(object sender, EventArgs e)
{
Form1 main = new Form1();
main.lbBEN.Text = textBox1.Text;
this.Close();
}
and this on another form:
if (emint<bmint)
{
best b = new best();
b.ShowDialog();
}
please guide me. . .THANK you
Add a public property to the second form and just below the ShowDialog(), sets the form1 label.Text to that property containing the name of the user.
public partial class Form2 : Form
{
string _highestScoreUser = string.Empty;
public Form2()
{
}
public string HighestScoreUser
{
get{ return _highestScoreUser; }
set{ _highestScoreUser = value; }
}
}
In Form1 code after ShowDialog is called like
{
Form2 form = new Form2();
form.ShowDialog();
form1.label.Text = form.HighestScoreUser;
}
Hope this help
You've created a brand new Form1 object unrelated to the Form1 that is already on the screen. You need to somehow pass a reference to the real Form1 the the secondary form.