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;
using System.Diagnostics;
namespace MyProject
{
public partial class MyForm : Form
{
Process MyProcess;
public MyForm()
{
InitializeComponent();
}
private void MyForm_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case 'a':
this.MyPictureBox.Image = null;
this.MyProcess = new Process();
this.MyProcess.StartInfo =
new ProcessStartInfo("\"C:\\Program Files (x86)\\LilyPond\\usr\\bin\\lilypond.exe\"", "--png tmp.ly");
this.MyProcess.Start();
this.MyProcess.WaitForExit();
this.MyPictureBox.Image = new Bitmap("tmp.png");
break;
default:
break;
}
}
}
}
"C:\Program Files (x86)\LilyPond\usr\bin\lilypond.exe" --png tmp.ly command creates tmp.png. When I press a key first time, MyProcess returns 0, but next - returns 1 always. I think the problem is in overwritting file tmp.png, which is using by MyPictureBox, but I have no idea how to repair it. Could you help me?
As far as I know lilypond does not give an option for overwriting using a command line argument. If I'm right then you can include code to delete then png file (if exsists) before MyProcess starts.
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
Related
I'm trying to use
driver.findElement(By.cssSelector("....."));
But it doesn't work(cannot use the FindElement with By). Do you know what can replace it? I'm using visual studio 2019 and write in C#
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
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 WebDriverTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.marketinginternetdirectory.com/submit.php");
//Find form element to auto fill on form page - Right click on input->inspect
var title_field = driver.FindElement(By.)
}
}
}
You can use xpath https://www.w3schools.com/xml/xpath_intro.asp
For your specific example you can locate title by doing this:
var titleElement = driver.FindElement(By.XPath("//input[#name = 'TITLE']"));
// And if you want to go a step further you might after want to do something like this:
element.SendKeys("YOUR-TITLE");
As per the documentation in By Class the notations is as follows:
CssSelector: Gets a mechanism to find elements by their cascading style sheet (CSS) selector.
Your effective line of code will be:
using OpenQA.Selenium;
var title_field = driver.FindElement(By.CssSelector("svg g rect:nth-child(20)"));
Reference
Selenium C# Webdriver Tutorial
I am testing out EMGU for a school assignment, and I am following this tutorial to get a basic understanding with the way EMGU works, but I have a problem.
Here is 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;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
namespace FacialRecognition
{
public partial class Form1 :Form
{
private Capture _capture;
bool CapturingProcess = false;
Image<Bgr, Byte> imgOrg;
Image<Gray, Byte> imgProc;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try {
_capture = new Capture(CaptureType.DShow);
} catch(NullReferenceException ex) {
MessageBox.Show(ex.Message);
return;
}
}
void processFunction(object sender, EventArgs e)
{
imgOrg = _capture.QueryFrame();
if(imgOrg == null) return;
imgProc = imgOrg.InRange(new Bgr(50, 50, 50), new Bgr(255, 255, 255));
imgProc = imgProc.SmoothGaussian(9);
original.Image = imgOrg;
processed.Image = imgProc;
}
}
}
However, I get the error:
The type or namespace name 'Capture' could not be found (are you missing a using directive or an assembly reference?)
and it suggests using System.Text.RegularExpressions;, which is quite strange.
I'm guessing I am missing something, but I referenced all of the DLL's
in the tutorial. Here are some screenshots:
Solution Explorer (They are set to Copy always)
References (Emgu.CV.World.NetStandard1_4.dll and Emgu.CV.World.dll were colliding)
Capture has been renamed to VideoCapture in new versions of EMGU , so try
private VideoCapture _capture;
You might consider using Emgu.CV.VideoCapture in EMGU.CV NuGet package (http://www.emgu.com/wiki/index.php/Main_Page) instead of Capture. So, your declaration becomes:
private VideoCapture _capture;
I have this code that uses NAudio to look for all microphones connected on laptop, andwhen I choose one it shows a meter of the sound in a progressbar.
when I gather all device, I collect them in a dropdwon list, my issue is that when I choose the one microphone from the list it will not be activated and display the sound on a meter unless I start WINDOWS SOUND RECORDER which seems to activate the mic.
how to enable or activate the microphone from the code without starting WINDOWS SOUND RECORDER?
here is 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 NAudio;
using NAudio.CoreAudioApi;
using System.Threading;
using NAudio.Wave;
using NAudio.Mixer;
namespace NaudioVisualizer
{
public partial class Form1 : Form
{
public int a = 1;
public Form1()
{
InitializeComponent();
MMDeviceEnumerator de = new MMDeviceEnumerator();
var device = de.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active);
comboBox1.Items.AddRange(device.ToArray());
}
private void timer1_Tick(object sender, EventArgs e)
{
if (comboBox1.SelectedItem != null)
{
var device = (MMDevice)comboBox1.SelectedItem;
progressBar1.Value = (int)Math.Round(device.AudioMeterInformation.MasterPeakValue * 100);
}
}
}
}
I had the same problem try to use the following code :
var waveIn = new WaveIn();
waveIn.StartRecording();
I'm new here hoping for some help with geckoFX in C#
So I just downloaded the geckoFX and did the following.
Downloaded: geckofx.dll
downloaded: XULRunner
I added the geckofx browser successfully and works fine but when I try to run this code to add JavaScript to the page I get an error.
The error I'm getting is: skybound.geckoFX.AutoJSContext does not contain a definition for evaluate script and jscontext.
Also I don't know if this helps but AutoJSContext and EvaluateScript are not hightlighting.
Here is my code
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Skybound.Gecko;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Skybound.Gecko.Xpcom.Initialize(#"C:\Program Files\xulrunner");
}
private void geckoWebBrowser1_DocumentCompleted(object sender, EventArgs e)
{
string outString = "";
using (AutoJSContext java = new AutoJSContext(geckoWebBrowser1.Window.JSContext))
{
java.EvaluateScript(#"window.alert('alert')", out outString);
}
}
}
You should call EvaluateScript like so:
java.EvaluateScript(#"window.alert('alert')", (nsISupports)geckoWebBrowser1.Window.DomWindow, out result);
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");