I am trying to load Google and get the ID of the searchbox. The ID of the box is "lst-ib". Which when the program goes to debug it is expecting a semicolon.
Is there a way around it to get the element id? So far I have:
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
public void Main(string[] args)
{
Process.Start("www.google.com");
HtmlElement lst-ib = WebBrowser1.Document.All["foo"];
//expects a semi colon on the line above after the element id
if (lst-ib != null)
{
lst-ib.InnerText = "test";
}
Console.ReadKey();
}
}
}
That is C# code and - is not valid in identifiers. Feel free to name the variable as you wish – it has no bearing on what the ID of the element is.
The - is an operator, you cannot use this way!
Here you will find more information about operators:
https://msdn.microsoft.com/en-us/library/6a71f45d.aspx
I recomend you rename - (trace) to _ (underline) or anyway you want
=D
Related
I have couple questions about referencing methods / variables between two or more *.cs files. I know that there are similar topics, but I still don't quite understand what is going on.
I'm using Visual Studio Community 2015.
So here is the problem. I have 2 files, those files are First.cs and Second.cs. They are saved in completely different, known locations on hard disc.
Inside First.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Forum
{
class First
{
static void Main(string[] args)
{
}
public int GiveMeNumber()
{
return 5;
}
}
}
Inside Second.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Forum
{
class Second
{
int number = // method from file First.cs
}
}
How do I access method GiveMeNumber() from First.cs in Second.cs as assignment for int number? How do I tell my compiler where are those files?
Thanks for any help :)
Like Alex said in his comment.
You can create a solution/project, add existing item, and browse to your first.cs and second.cs.
Mark both files with the public-keyword
for example:
namespace Forum
{
public class Second
{
int number = // method from file First.cs
}
}
Then both class can be used within each other.
So you could do
var first = new First();
var number = first.GiveMeNumber();
you probably want to do it the other way around, because I think you have a console app where your First class has a main-method.
does that help>?
Sorry for the title, I had a hard time trying to summarize this.
I'd like to replace an unknown number of instances of a string with a wrapper. So I'd like to replace this:
Test with two:\t\t tab characters
With this:
Test with two:<span class="" style="white-space:pre">\t\t</span> tab characters
There could be any number of \t characters in the given string, and in multiple locations.
The reason I'm trying to do this is our software uses Chilkat to sent emails, and if HTML content contains tabs, these are not shown at the receiving end. When sent, we use \t to represent a tab, and when viewing the source of the received email, the tabs are there, but outside the source they are not:
Outside Source:
Source:
I tested with GMail, and this wraps the tabs:
I understand this maybe be a Chilkat issue, but I can't find much help on the topic, but if I can get around it as above, I'm willing to try it.
Use this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string input = "Test with two:\t\t tab characters";
string output = Regex.Replace(input, #"(\t+)", "<span class=\"\" style=\"white-space:pre\">$1</span>");
}
}
}
This is what I ended up using. The capture group was picking up each repetition individually, and then the replace was only replacing the first found instance, not the entire capture group
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string input = "Test with two:\t\t tab characters";
string output = Regex.Replace(input, #"(\t)+", "<span class=\"\" style=\"white-space:pre\">$&</span>");
}
}
}
I use this service to translate English word:
http://services.aonaware.com/DictService/DictService.asmx?op=Define
I add this link to my windows Form application by click right on References -> Add Service Reference -> and best the URL of service in Address field.
then I write this 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;
using هجوم_الكسر_الأعمى.ServiceReference1;
namespace هجوم_الكسر_الأعمى
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//Definition a = new Definition();
WordDefinition sv = new WordDefinition();
sv.Word="Go";
string b= sv.Word;
textBox1.Text = b; ;
}
}
}
The problem is that I don't have the result, I have the same world witch I write it "Go"?
You're not doing anything here, you're just creating an instance of WordDefinition locally that you set to the word you're trying to search for.
You need to invoke the service call, for example..
using (var dictionaryService = new ServiceReference1.DictServiceSoapClient("DictServiceSoap"))
{
var definition = dictionaryService.Define("Programming");
Console.WriteLine(definition.Definitions.First().WordDefinition);
}
I am not sure if I understand you, but if you would like to have result from sv.Word method I think you shloud try to check if there is some method with Result, for example: sv.WordResult and it will add event handler to this.
EDIT 9:20am CST: It appears you just have to convert
if (d.Name == drvNamefrm2)
to
if (d.Name == (string)drvNamefrm2)
Alright, I am trying to write a small performance monitor. I've done research on here and worked through some walk-thrus. This is probably a small problem with an easy fix, but I can't see it. I was hoping you could take a look.
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.Diagnostics;
using System.IO;
namespace TrafcLightPerfMeter_v1
{
public partial class diskUtilForm : Form
{
It uses two forms and I am bringing over the initial selection from Form1 hence the parameters in the form name below.
public diskUtilForm(int drvNumfrm1, string drvNamefrm1)
{
InitializeComponent();
mainForm test = new mainForm();
**object drvNumfrm2 = (object)drvNumfrm1;
object drvNamefrm2 = (object)drvNamefrm1;
DriveInfo[] allDrives = DriveInfo.GetDrives();
It's this "foreach" section. It is skipping over my "if" even if the d.Name is == to drvNamefrm2 -- I don't understand what I am doing wrong.
The idea here is "if" they match "then" the traffic light background will be green. Then I want to use that little formula to designate the rest of the colors. I just need it to enter the if statement.
foreach (DriveInfo d in allDrives)
{
if (d.Name == drvNamefrm2)
{
labelGreen.BackColor = Color.Green;
long totalAvailable = d.AvailableFreeSpace;
long totalSpace = d.TotalSize;
double percentAvailable = Math.Round(((double)totalAvailable/(double)totalSpace)*100,4);**
}
}
}
}
}
Thank you in advance for any input.
It appears you just have to convert
if (d.Name == drvNamefrm2)
to
if (d.Name == (string)drvNamefrm2)
--The formula also appears to be working now. So, later own I can do comparison and color changing on the "traffic light".
I'm new to C# and I'm new to Speech.Recognition.
I searched very long for tutorials but didn't find that much, I'm even not quiet sure whether I included everything correctly.
I downloaded:
SDK
Runtime
Languages
I'm programming local, I have Windows XP, .net framework 3.5.
Now I just want to get started with some simple lines of code, like to say "hello world" or say one or two words as input.
I tried following, and of course it doesn't work :>
error:
"The Typ- or Namespacename "SpeechSynthesizer" couldn't be found (Is a Using-Direktive or a Assemblyverweis missing?)"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer foo = new SpeechSynthesizer();
foo.Speak("Test");
}
}
}
edit:
hello,
i tried you code,but
using SpeechLib;
couldn't be found :>
well now i wrote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.SpeechLib;
namespace System.SpeechLib { }
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
but I get an error with:
numericUpDown1,SpVoice,SpeechVoiceSpeakFlags,textBox1 and Timeout
Project + Add Reference, .NET tab, select "System.Speech".
A project template pre-selects several .NET assemblies. But only common ones, like System.dll, System.Core.dll, etcetera. You have to add the 'unusual' ones yourself.
you can try this:
get Interop.SpeechLib.dll
using SpeechLib;
private void ReadText(string readText)
{
int iCounter = 0;
while (Convert.ToInt32(numericUpDown1.Value) > iCounter)
{
SpVoice spVoice = new SpVoice();
spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
spVoice.WaitUntilDone(Timeout.Infinite);
iCounter = iCounter + 1;
}
}