|
One way is use the Cursor.Position property followed by
the Control.PointToClient() method.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes got it too !
But when I try it first I thought it does not work because in debugger the mouse was still active and I was getting another position that I was expecting !
Good to know !!
|
|
|
|
|
I have been trying to do this for some time now, and at one time, before I gave up, had code from 2 different people, 1 in VB for detecting the thumb drive being inserted, and 1 in C# for suppressing Autorun.(Could have been the other way around.) Since then, I have lost both files, and I'm simply wondering if it is possible to code something in C# to do both, and then run a program on that drive(PortableApps). My biggest problem is that I know very little C# or any other language for that matter. I do have a friend that is really good at it, but he hasn't been able to figure it out either.
Thanks in advance, for anyone who takes the time to read this.
|
|
|
|
|
This article covers device insertion detection, not sure about preventing autorun, however.
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
thanks for the tip. The autorun suppression has proven to be a problem, as nobody seems to be able to code it in C#, only VB.
Does anybody have a solution to this?
|
|
|
|
|
hi,
this is exactly my first program, i will be using C#. The device i am using is a usb connected PC digital TV receiver this receiver software actually have a function which measure the signal strength, BER and these data are save into an log file (thus it real time measurement data) once i start the device (start watch TV).
I am suppose to use C# to get the real time measurement and convert it into graphic (line chart).
I have try to get the data for the log file and display it in the textbox using the following code
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Testing_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
StreamReader objstream = new StreamReader("c:\\measurement.log");
textBox1.Text = objstream.ReadToEnd();
}
but this is the error i got : the file been use by another program.
I also try another method which is directly from the usb port which the device is connected to but i am unable to start working on it coding. i had been looking into example of usb_hib and ICSHARPUSBlib but i was unable to get anything out.
Thus please help me, if i am in the right direction (get the data from usb directly?) or do you have any better item on how i should get this done, any code to refer to.
thank so much
|
|
|
|
|
Because your new here and to programming i wont be too sarcastic but here area a few pointers when posting here...
1.) Please use a subject related to your question
2.) Please use pre tags when posting code
Have a look at my article - How to use the code project forums[^]
Now on to your question
Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time. Thats why you get the FileAccessException, because the program that logs the signal strenght is constantly updating the file.
Now that i think about it, you can open a file that a program is writing too and view it in notepad... so u might be able to do this, as long as you dont try to write to the file. What strikes me as strange in your code is your using just the stream reader... maybe this is the problem... try this
FileStream fs = new FileStream(@"c:\measurement.log", FileMode.Open);
StreamReader reader = new StreamReader(fs);
string fileContents = reader.ReadToEnd();
as for the graphical part, have a look at GDI+
it involves the use of the OnPaint(object Sender, EventArgs e) event handler of a component like a panel, because youll be updating it continuously your going to have to paint on a Double Buffered Panel so that it wont flicker!
Well that should keep u busy for a while if this is your 1st C# program, if u have any questions ill be glad to help if i can.
Good luck!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Harvey Saayman wrote: Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time
Not strictly true. It is possible to set a sharing mode for the file. If you open the file as Exclusive (aka DenyAll or ShareNone) then nothing else can access it. If you open the file as ShareRead then multiple things can open the file as Read Only (so long as they all allow other processes to read the file too)
Harvey Saayman wrote: What strikes me as strange in your code is your using just the stream reader
What struck me was that the file never gets closed. The OP needs a using block around that stream. That is the most likely reason as the program that generates the file is probably expecting readers simultaneous with it writing the file and will have the file open accordingly.
|
|
|
|
|
hi Colin Angus Mackay
thank for your reply
I am not very sure and clear on what you are trying to tell me as I am very new to programming sorry about it.
|
|
|
|
|
hi,
I had try the code you have given to me but I get the following error
IOException was unhandled
Is there an solution for my problem?
Thanks
|
|
|
|
|
Hi all...
I'm writing a small application, that monitors the active excel workbook (The excel window that is currently opened and active). The applicatition then monitors the active-row, get the data from the first coloumb of that row and looks it up in a database.
I have managed to get a reference to excel, using Interop-marshal (see code below), but this only gives me a reference to the first excel workbook opened. If the user switches to another excel workbook, I want to change my reference as well.
Second question: Is there a way to detect if the active-cell has changed. currently I have to read the active-cell continiously to see if it has changed.
Thank you very much, (in advance)
(sorry about my english)
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
Excel.Application oExcelApp;
try
{
oExcelApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
debugLabel.Text = "Lookup ID: " + oExcelApp.get_Range("A" + oExcelApp.ActiveCell.Row.ToString(), Missing.Value).Text;
oExcelApp = null;
}
catch (Exception)
{
debugLabel.Text = "Lookup ID: Ikke Fundet";
}
|
|
|
|
|
Hi all!
Is there a way to capture in C# the user click on a link (in any window) in order to open a web page?
I'd like to code a simply application that make you can choose the browser in which you want to open that page...
Thank you in advantage!
|
|
|
|
|
Use a LinkButton control instead of a normal url-tagged link.
And you should ask asp.net questions in the asp.net forum.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I am a Dot Net Developer. I want to integrate MultiQC with my application. I have downloaded the trial verision of MultiQC. I have also downloaded the 'QC File-Link A' for interfacing the file to MultiQC.
I have succeed to retrieve data from .cnx file to 'QC File-Link A' but how it could be reflected on MultiQC screen.
Any Idea!!!!!!
|
|
|
|
|
[Interface]
Name = File-link A
Default section = ABC
[Fields]
Section = 1
Analyte = 2
Date = 3
Time = 4
QC material = 5
Value = 6
Flag = 7
[Format]
Delimitor = #9
Date = DD/MM/YYYY
Time = hh:mm:ss
[Sections]
[Tests]
4=Test1/QC1,QC2,QC3
[Flags]
$t=My Data
|
|
|
|
|
ABC 4 21/09/2008 09:09:09 QC1 0.10 $t
ABC 4 21/09/2008 09:09:09 QC1 1.01 $t
ABC 4 21/09/2008 09:09:09 QC1 2.02 $t
ABC 4 21/09/2008 09:09:09 QC1 3.03 $t
ABC 4 21/09/2008 09:09:09 QC1 4.04 $t
ABC 4 21/09/2008 09:09:09 QC1 5.05 $t
ABC 4 21/09/2008 09:09:09 QC1 6.06 $t
|
|
|
|
|
Thanks Deepak.
I have already reached the solution.
Thanks for ur efforts.
Regards
Dinker Batra
|
|
|
|
|
I have gotten just about everything i need for my application but i want to be able to programmatically read/write to the field description using C#.net. I have googled this but came up with nothing. please help, this will really make my app shine if i can do this.
|
|
|
|
|
djjedi wrote: read/write to the field description
what field description
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
The description for the column name. I'd like be able to access it (read/write)
|
|
|
|
|
ah, i didnt see that in the subject line!
when you select the data, u can specify the column name the user will see
like this
SELECT columnOne AS 'My First Column', columnTwo AS 'My Second Column'
FROM myTable
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
I guess maybe im missing something.
im able to retrieve the tables using
private void GetTables()
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataBaseFile;
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connectionString);
try
{
this.cboSections.Items.Clear();
conn.Open();
DataTable schemaTab =conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new Object[] {null, null, null, "TABLE"});
DataTable schemaTable =conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new Object[] {null, null, null, "TABLE"});
conn.Close();
for (int j = 0;j < schemaTable.Columns.Count; j++)
{
Console.WriteLine(schemaTable.Columns[j].ToString());
for (int i = 0; i < schemaTab.Rows.Count; i++)
{this.cboSections.Items.Add((schemaTab.Rows[i].ItemArray[2].ToString()));}
if (this.cboSections.Text.Equals(""))
this.cboSections.SelectedItem = this.cboSections.Items[0];
}
}
catch(Exception ex){Console.WriteLine(ex.Source);}
}
and im able to retrieve tthe columns im looking for using
private void GetColumns()
{
string TableName = this.cboSections.SelectedItem.ToString();
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataBaseFile ;
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connectionString);
DataRowView drvCols = null;
DataTable dtCols = null;
DataView dvColumns = null;
// Get the list of tables that there are.
try
{
this.liFields.Items.Clear();
this.liValues.Items.Clear();
conn.Open();
DataTable schemaTab =
conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new Object[] {null, null, null, "TABLE"});
for (int i = 0; i < schemaTab.Rows.Count; i++)
{
if (this.cboSections.Text.Equals(schemaTab.Rows[i].ItemArray[2]))
{
// Get the column name and its type and sort them
// according to their position in the table.
dtCols = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns,new Object[]{null,null, schemaTab.Rows[i].ItemArray[2].ToString(), null});
dvColumns = new DataView(dtCols);
dvColumns.Sort = "ORDINAL_POSITION";
// Get the column names and their types.
for (int j=0; j< dvColumns.Count; j++)
{
// Get the name of the column.
drvCols = dvColumns[j];
if ((! drvCols.Row.ItemArray[3].ToString().Equals("ID") )&& (! drvCols.Row.ItemArray[3].ToString().Equals("")))
{
this.liFields.Items.Add(drvCols.Row.ItemArray[3].ToString());
this.liValues.Items.Add(ini.IniReadValue(cboSections.Text,drvCols.Row.ItemArray[3].ToString()));
}
}
}
}
}
catch(Exception ex){Console.WriteLine(ex.Source);}
conn.Close();
}
but im unable to get the descriptions for those columns.
|
|
|
|
|
Hi all..
I am trying to write to a xml file...
The problem i am facing is....I am writing in a for loop..
Each time it is replacing with the old one..
I am trying with the code..
for (int indx = 0; indx < contact.Fields.Count; indx++)
{
StreamWriter sw = new StreamWriter(@"D:\Temp\File.xml");
sw.WriteLine(contact.Xml);
sw.Flush();
sw.Close();
}
what i wanted is change the file name with File1.xml,File2.xml,....etc
can anyone help..
thank you
manju
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
Depends on whether you want to overwrite the files written from an older for loop. If this is the case, then you can just write the filename as
@"D:\Temp\File.xml"+i
If you don't want to overwrite files at all, then you'd first have to examine all filenames in the directory (via Directory.GetFiles() ) and get the highest file id ever assigned, and start the counter from there.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
@"D:\Temp\File" + i + ".xml" is probably more useful.
|
|
|
|