I'm writing a Form in c# using Emgu, but, when trying to use the function CvtColor, I get the error "CV_RBG2GRAY" does not exist in the current context. I've looked everywhere, but I couldn't find any other occurences of this problem.
The problem occurs in this line:
private void startToolStripMenuItem_Click(object sender, EventArgs e)
{
CvInvoke.CvtColor(Processo.InImage, Processo.BWImage, CV_Rgb2Gray);
}
Could Someone please help me?
That constant is in Emgu.CV.CvEnum.ColorConversion namespace. Try this:
private void startToolStripMenuItem_Click(object sender, EventArgs e)
{
CvInvoke.CvtColor(Processo.InImage, Processo.BWImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Gray);
}
Related
i have a coursework about nfc read and write, but i'm still new using C# and i found some libraries about nfc c#. one of them from h4kbas which I'm currenly using righ now.
the first thing i try is how to read UID, but it seem work fine
private void button1_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
textBox1.Text = NFC.GetCardUID();
}
}
and then i try making read and write :
Read
private void button2_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
NFC.WriteBlock(textBox2.Text, "5");
//Close();
}
}
Write
private void button3_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
NFC.ReadBlock("5");
//Close();
}
}
but after i try making a read and write function above, i don't found any error massage but if i try read or write some string data on running process, forced to close and give massage "The program '[10192] WFANFCReadWriteExecute.exe' has exited with code -1 (0xffffffff)." still..., i don't know the problem is on my code or i have to use "AuthBlock" first.
I have 2 buttons, Connect and Send Command. In the first button I am creating the connection to my server and in the second sending a command. The codes are as below:
public void button1_Click(object sender, EventArgs e)
{
SshExec shell = new SshExec("hostname", "username", "password");
shell.Connect();
}
public void button2_Click(object sender, EventArgs e)
{
shell.RunCommand("ls");
}
Now the error is in "shell.RunCommand("ls");" I am getting "The name 'shell' does not contains in the current context". I am new to C# (mere 2 days) and do not have much idea, so please if anyone can help.
What I am expecting is no error and the command to be sent properly to the terminal when the second button is pressed.
At the end sorry for bad formatting of the code, please inform me if any additional information is required.
Right now, you are declaring the variable shell inside the button1_Click method. That means only that method can "see" the variable and use it.
In order for both of the button methods to use the variable, it must be declared outside/above at the class level.
Try this:
private SshExec shell;
public void button1_Click(object sender, EventArgs e)
{
shell = new SshExec("hostname", "username", "password");
shell.Connect();
}
public void button2_Click(object sender, EventArgs e)
{
shell.RunCommand("ls");
}
I am having an issue with my WinForm application.
Below I have my code for my button that I want to click.
private void button1_Click(object sender, EventArgs e)
{
// Do code.
}
Now I want to run the program on start up, so I have this code below:
private void form_Load(object sender, EventArgs e)
{
this.button1_Click(object sender, EventArgs e);
}
But this does not work. It has red lines under the words: "sender", "EventArgs e"
What am I doing wrong, Please help me?
Any help would be greatly appreciated, thanks!
First if you want to click button that way you should do:
private void form_Load(object sender, EventArgs e)
{
button1.PerformClick();
}
Second,
it is not a good idea to do it anyway, better approach is to create common method that is call in button_click event and form_load event.
I have a class file cls_PurchaseValidae.cs in which i have written a code like below:
public void txtMfgDate_Validating(TextBox txtMfgDate,ErrorProvider errorProvider1,string datetoValidate)
{
//method for validating the text box.
ValidateMfgDate(txtMfgDate, errorProvider1,datetoValidate);
}
and i m calling this event in the code behind frm_Purchase.cs like this:
private void txtMfgDate_Validating(object sender, CancelEventArgs e)
{
objPurchaseValid.txtMfgDate_Validating(txtMfgDate,errorProvider1,datetoValidate);
}
but i m getting the error:
Error 1 The name 'datetoValidate' does
not exist in the current context
How can i resolve it.
Thanks in advance
I am not sure why do you want to pass around both TextBox txtMfgDate, and string datetoValidate? Shouldn’t datetoValidate be always txtMfgDate.Text? Anyway, you can do:
private void txtMfgDate_Validating(object sender, CancelEventArgs e)
{
objPurchaseValid.txtMfgDate_Validating(txtMfgDate,errorProvider1,txtMfgDate.Text);
}
if that is what you want.
now i have the current code o MainUC.cs:
private void tsbNoviRacun_Click(object sender, EventArgs e)
{
if (racunuc == null)
{
racunuc = new RacunUC();
racunuc.Dock = DockStyle.Fill;
Controls.Add(racunuc);
}
racunuc.BringToFront();
The thing i want to do is clean the code from main page/form. I have 2 taskbar and 2 toolbar buttons that are calling the same form (this one above), so i don't want to write the code 4 times. I tried to make new class.cs with properties and do it with return value, but it didn't work. Can someone help me with it, or, is there possiblity to call the same code on current page/form. Something like
private void tsbStariRacuni_Click(object sender, EventArgs e)
{
call tsbNoviRacun();
}
"( this isn't working, i know :p)
EDiT: Oh damn me, thanks guys!
In c# there is no "call" keyword for invoking functions. You just type the name and all required arguments in round brackets.
private void tsbStariRacuni_Click(object sender, EventArgs e)
{
tsbNoviRacun_Click(sender, e);
}
This should do it:
public void tsbNoviRacun()
{
if (racunuc == null)
{
racunuc = new RacunUC();
racunuc.Dock = DockStyle.Fill;
Controls.Add(racunuc);
}
racunuc.BringToFront();
}
private void tsbNoviRacun_Click(object sender, EventArgs e)
{
tsbNoviRacun();
}
You can call that method from all the event handlers you want it to run on. Obviously this function is depended on Controls and DockStyle so you must put it within scope of this.