|
I tried it but the program still doesnt read the picture file...I want to access the pic.bmp without directly enforcing the complete filepath (e.g. c:\mydocuments\sample\project\folderiwanttoaccess\pic.bmp <--i dont want to write this in the program source file...)
|
|
|
|
|
I understand what you're trying to do.
You can access files in a higher directory level that the exe using "..\\". So if your .exe file is running from c:\mydocuments\sample\project\bin\debug\test.exe, you can locate the image from your C# code using
// Adjust the line below depending on how many parent directories must be navigated upwards to read the folderIWantAccessTo directory.
stromg pathToImage = "..\\..\\..\\folderIWantAccessTo\pic.bmp";
If you want to see what's going on with those "..\\" things, see what this returns:
string path = Path.GetFullPath("..\\..\\..\\");
It should return your project root. From there the rest is easy, just append the folderIWantAccessTo\pic.bmp to the end of the string and you're good.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I figured out what was lacking in your idea... there should be three "." instead of two. It is now working correctly. Thanks very much
|
|
|
|
|
|
ei guys... i'm having a problem in printing the receipt for my point of sale. Just want to ask you... what tools should i used for the reciept and maybe some codes in printing it... thanks
|
|
|
|
|
Most printers are graphics printers. I have found that I can create class that builds the receipt as an image then send it to the printer. The api's are usually availiable from the mfg to configure the printer and they will give you examples.
I went this direction because getting text lined up is pretty difficult and in the end just looks bad.
|
|
|
|
|
How can i make documentation(*.chm) to descript my dll after build.
Nothing
|
|
|
|
|
|
How about Doxygen,
generate hhp, then Chm
|
|
|
|
|
Hi,
Can you show me any snippet or any library in order to extract text from RTF file ( or you can say, convert RTF file to txt file) PLeaseeeee
Emran
|
|
|
|
|
Hi,
Use rich text box control.
It has a rtf property to which you should set the rtf code and then in the text property of the rich text box you will get the plain code.
But If u want a function or something then sorry I don't know.
Jayvardhan Patil
|
|
|
|
|
I am attempting to write a method to iterate through a xml file that has multiple nodes that match a given type but for some reason it only accepts the first one and then exists. I think I may have my loop wrong or something. Can anyone tell me what the issue may be?
using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Diagnostics;
using System.Threading;
namespace UTS_Batch_Update
{
public class UTSB_Input
{
{
string Path = "C:\\xmlticketID.xml";
// If the user forgets to put in a path, throw a NullException.
if (Path == null)
{
throw new ArgumentNullException();
}
// Load the document.
XmlDocument sourceDoc = new XmlDocument();
sourceDoc.Load(Path);
// Retrieve each ticketID.
//XmlNodeList tickets = sourceDoc.GetElementsByTagName("TicketId");
//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(sourceDoc.NameTable);
foreach (XmlNode node in tickets)
if (node.Name == "TicketId")
{
//using (MemoryStream buffer = new MemoryStream())
string buffer = "c:\\xmlpost.xml";
XmlTextWriter w = new XmlTextWriter(buffer, null);
// Start the document.
w.WriteStartDocument();
w.WriteStartElement("XMLFILE");
w.WriteAttributeString("UserLogName", "REDMOND\\" + UserInfo);
w.WriteAttributeString("FileId", "MSN Search BUU");
w.WriteAttributeString("Action", "Close");
w.WriteStartElement("TICKET");
w.WriteAttributeString("TicketId", node.InnerXml.ToString());
w.WriteAttributeString("CloseControlInd", "No");
w.WriteAttributeString("ProblemResolved", Resolved);//ConvertBoolToYesNo(Resolved));
w.WriteAttributeString("WereProceduresInPlace", ProceduresInPlace);
w.WriteAttributeString("WereProceduresInPlaceNotes", ProceduresInPlaceNotes);
w.WriteAttributeString("WereProceduresAccurate", ProceduresAccurate);
w.WriteAttributeString("WereProceduresAccurateNotes", ProceduresAccurateNotes);
w.WriteAttributeString("WereToolsEffective", ToolsEffective);
w.WriteAttributeString("WereToolsEffectiveNotes", ToolsEffectiveNotes);
w.WriteAttributeString("FalseAlarmInd", FalseAlarm);
w.WriteAttributeString("VerifiedBy", VerifiedBy);
w.WriteAttributeString("NotifyAliases", NotifyAliases);
w.WriteAttributeString("ClosureNotes", Closure);
w.WriteEndElement();
// End the document.
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
w.Close();
XmlTextReader reader = new XmlTextReader(buffer);
XmlDocument outputDoc = new XmlDocument();
outputDoc.Load(reader);
string processpath = "C:\\WINDOWS\\system32\\wscript.exe";
string processargs = "C:\\uts.wsf c:\\xmlpost.xml";
System.Diagnostics.Process.Start(processpath, processargs);
return outputDoc;
}
throw new InvalidOperationException("No XML was converted.");
}
} // end method UTSBFileLoad
}
|
|
|
|
|
dbenisch wrote: I think I may have my loop wrong or something.
Yes, you have. You have the return statement inside the loop.
---
b { font-weight: normal; }
|
|
|
|
|
Is there anyway to set a tooltip for a certain coordinate area of a form and not to a specific control?
|
|
|
|
|
I figured out one way to do it, but I don't know if it's the most efficient.
This is what I did:
<br />
private void Form1_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
if (e.X > 15 && e.X < 45 && e.Y > 35 && e.Y < 60)<br />
trackTip.Show("1", this, 20, 45);<br />
else if (e.X > 45 && e.X < 75 && e.Y > 35 && e.Y < 60)<br />
trackTip.Show("2", this, 55, 45);<br />
else<br />
trackTip.Hide(this);<br />
}<br />
is this the best way to do it?
|
|
|
|
|
I'm trying to capture system messages in my Windows Service. Specifically I want to know when a device is un\plugged into the usb. From what I found is appears that I need to 1) Create a callback HandlerEx, 2)RegisterServiceCtrlHandlerEx and 3)RegisterDeviceNotification.
My Problem is I always get a Error 126 when I call RegisterServiceCtrlHandlerEx. I think something might be wrong with the parameters I am passing it.
Would appreciate any suggestions or any advise on a better way to do this.
First Section of code is my Win32 class and delegate for my callback. Second section is The Service code minus all the windows generated stuff.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace My_Service
{
public delegate int callbackEx(int control, int eventType,IntPtr eventData,IntPtr context);
class Win32
{
[DllImport("kernel32.dll")]
public static extern int GetLastError();
[DllImport("advapi32.dll", SetLastError=true)]
public static extern IntPtr RegisterServiceCtrlHandlerEx(
string lpServiceName,callbackEx cbex,IntPtr context);
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
namespace My_Service
{
public class My_Service: System.ServiceProcess.ServiceBase
{
private System.ComponentModel.IContainer components;
public System.Diagnostics.EventLog eventLog1;
private IntPtr MethodHandle;
private callbackEx myCallback ;
public My_Service()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
this.RegisterCallBack();
}
private int my_Callback(int dwControl,int dwEventType,IntPtr lpEventData,IntPtr lpContext)
{
this.eventLog1.WriteEntry("CALLBACK HIT!!!!!!!!!!");
return 0;
}
void RegisterCallBack()
{
myCallback = new callbackEx(my_Callback);
MethodHandle = Win32.RegisterServiceCtrlHandlerEx(this.StrToByteArray(this.ServiceName),myCallback,IntPtr.Zero);
if(MethodHandle == IntPtr.Zero)
{
this.eventLog1.WriteEntry("RegisterCallBack " + Win32.GetLastError().ToString());
}
}
Thanks, Chris
|
|
|
|
|
Hi all,
I'm really struggling to do something very simple using a DataGridView control. I'm setting the DataGridView DataSource to an existing DataSet. All the data is displayed fine.
I now want to select a range of cells using the DataGridView, and when I click a button, have the selected cells copied to a new (previously empty) dataset. I just can't figure out how to get the data I've selected in the DataGridView control into the new dataset.
By putting a watch on the DataGridView control, I can see the list of items contained in the control, but they're all non-public so I have no way of getting at them programmatically.
Any assistance would be very much appreciated.
|
|
|
|
|
I don't know if I have understood the question right but you can access the cells with
[code]
dataGridView1.Rows[0].Cells[1].Value;
[\code]
hope this helps
|
|
|
|
|
if u are looking for this
on selectedindexchanged of gridview1 write code below
this.textbox1.text = GridView1.SelectedRow.Cells[1].Text
|
|
|
|
|
I'm trying to create a program to make thread-safe calls to form controls, specifically to instances of ToolStripStatusLabel and ToolStripProgressBar. I ran cross this page when VC# told me I was unsafely calling the control. The problem is those two classes aren't derived from Control and don't have the InvokeRequired property. I tried using the forms' own InvokeRequired but it's not working and I don't know what to do. Anyone have any help?
|
|
|
|
|
toolStripProgressBar1.Owner.Invoke((ThreadStart)delegate
{
toolStripProgressBar1.Value = 50;
});
Rather than using Invoke/BeginInvoke, you might want to use the System.ComponentModel.BackgroundWorker class, which raises events for you on the appropriate thread, handling all the Invoke/BeginInvoke for you.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
that's interesting, thanks. I unfortunately got an exception saying not enough arguments were supplied so I added in my arguments for the delegates like this:
_statusbar.Owner.Invoke((ThreadEvent)delegate
{
_statusbar.Text = "test test, started work";
}, new Object[] { this, ThreadEventArgs("test message", 0, TheadStatusType.thread_started) });
In my original delegate, I had it declared object, ThreadEventArgs so I guess that's what it wanted.
This works, and without the form-side needing a delegate. Is that the best though? With it like this, it requires a status bar to exist in order to work. I liked the idea of triggering an event and the form can receive it if it wants to and deal with it as it sees fit.
|
|
|
|
|
I think I found the problem with what I was doing originally, I don't think I was invoking the delegate right. I ran across this page which talks about BeginInvoke. I used the section of code declared as the typical way of using BeginInvoke as my inspiration and got my invoke working pretty well.
I thought anyone reading this and interested in a fix might want to know.
|
|
|
|
|
Like I said, BackgroundWorker is really want you should look at:
backgroundWorker1.DoWork += MyWorkerFunction;
backgroundWorker1.ProgressChanged += MyProgressReported;
backgroundWorker1.RunWorkerCompleted += MyWorkCompleted;
backgroundWorker1.RunAsync(someArgument);
void MyWorkerFunction(object sender, DoWorkEventArgs e)
{
...
backgroundWorker1.ReportProgress(99);
...
}
void MyProgressReported(object sender, ProgressReportedEventArgs e)
{
}
void MyWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I looked at BackgroundWorker after you said it and concluded that using it would require a lot of rewiring of my program, more than I was willing to do. However, I do now know it exists and I'll keep it in mind next time around.
|
|
|
|