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".
Related
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
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>?
I'm attempting to grab a device handle on the Synaptics Touchpad using the Synaptics SDK, specifically using methods in the SYNCTRLLib.
However, the SYNCTRL method failed to find it, returning -1.
Syn.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;
namespace TP_Test1
{
class Syn
{
SynAPICtrl SynTP_API = new SynAPICtrl();
SynDeviceCtrl SynTP_Dev = new SynDeviceCtrl();
SynPacketCtrl SynTP_Pack = new SynPacketCtrl();
int DeviceHandle;
//Constructor
public Syn ()
{
SynTP_API.Initialize();
SynTP_API.Activate();
//DeviceHandle == -1 ? Can't find device?
DeviceHandle = SynTP_API.FindDevice(new SynConnectionType(), new SynDeviceType(), 0);
//Below line causing Unhandled Exception
SynTP_Dev.Select(DeviceHandle);
SynTP_Dev.Activate();
SynTP_Dev.OnPacket += SynTP_Dev_OnPacket;
}
public void SynTP_Dev_OnPacket()
{
Console.WriteLine(SynTP_Pack.FingerState);
Console.WriteLine(SynTP_Pack.X);
Console.WriteLine(SynTP_Pack.Y);
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;
namespace TP_Test1
{
class Program
{
static void Main(string[] args)
{
Syn mySyn = new Syn();
mySyn.SynTP_Dev_OnPacket();
}
}
}
I see that you are using the C# wrappers for Synaptics SDK. Even though CPP code might be not trivial to you, you might want to take a look at the file Samples/ComTest.cpp. It contains some example logic in order to find devices, more specifically at lines 66-76:
// Find a device, preferentially a TouchPad or Styk.
ISynDevice *pDevice = 0;
long lHandle = -1;
if ((pAPI->FindDevice(SE_ConnectionAny, SE_DeviceTouchPad, &lHandle) &&
pAPI->FindDevice(SE_ConnectionAny, SE_DeviceStyk, &lHandle) &&
pAPI->FindDevice(SE_ConnectionAny, SE_DeviceAny, &lHandle)) ||
pAPI->CreateDevice(lHandle, &pDevice))
{
printf("Unable to find a Synaptics Device.\n");
exit(-1);
}
Also, make sure you have registered the dlls. According to the ReadSynSDK.txt file:
For certain purposes it may be necessary to register the dlls
that are provided with the SDK. This can be done with the windows regsvr32
utility.
I have to make a program to back up my IDM download list every day, because there is other ones using my computer and they removing my download list.
IDM API only lets me add download to IDM list, so is there any library or other way to back up my IDM download list using C#?
thanks for helping
Thanks to #Setsu found out a solution. there is a key in registry which contains all of the URLs. the key is HKEY_CURRENT_USER\Software\DownloadManager and it contains keys which contains values named Url0 with the URL in it.
As an example HKEY_CURRENT_USER\Software\DownloadManager\85\Url0 contains one of added link to IDM download list.
So I searched all of the HKEY_CURRENT_USER\Software\DownloadManager subkeys for Url0 and saved the values to a list box using 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 Microsoft.Win32;
namespace IDMListSaver
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\DownloadManager");
string[] keys = key.GetSubKeyNames();
for (int i = 0; i <= key.SubKeyCount-1; i++)
{
key = key.OpenSubKey(keys[i]);
Object o = key.GetValue("Url0");
if (o != null)
{
listBox1.Items.Add(o);
}
key = Registry.CurrentUser.OpenSubKey("Software\\DownloadManager");
}
}
}
}
It definitely can get better, but it solved my problem until here.
So thanks again #Setsu
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.