|
nice to know that!
happy coding!
microsoc
|
|
|
|
|
I have an instance of Image class. I want to get values of Red, Green, Blue components from the instance. I'm in dark. Please help me! Thanks!
NPS.
|
|
|
|
|
System.Drawing.Bitmap b = new System.Drawing.Bitmap("yor flene");
System.Drawing.Color color = b.GetPixel(100,100);
color.ToArgb();
|
|
|
|
|
Hi,
I am trying to use the SendMessage API function to send a message to an edit box. The specific message is the EM_GETRECT message to retrieve the rectangle of the edit box for custom painting.
The MSDN library states that I have to send a pointer to a RECT structure as the lParam parameter. I have defined the RECT structure, as I have used it earlier. I just have no idea how to create, find or attach a handle to the RECT structure. If I try to pass just the RECT structure, the SendMessage method returns with a "parameter is incorrect" message.
Any help would be appreciated.
Regards,
Stefan.
|
|
|
|
|
|
Hi folks,
what would be a good way to make a database query cancelable? Purpose is that the user should abort the function if it takes too long.
I've already stuffed the whole database access logic into a separate thread. When the user clicks the abort button then the Thread.Abort function is called.
Problem 1: The thread ignores the Abort call until the query is completely processed.
Problem 2: Somehow I cannot fire a second query while the first hasn't finished (e.g. User quickly clicks Search->Cancel->Search). I'm not sure why - it might be the underlying Access database (please don't mock me for that - the db is set by the customer).
I'm working with .Net 1.1. Any ideas?
|
|
|
|
|
Within your data access class, store a boolean variable such as Cancelling . Now, read your data in chunks using something like a DataReader , except after reading each chunk of data check whether the Cancelling flag has been set to true. If it has, close your data reader and connection and return from the method as quickly as possible.
You can now do exactly as you were, starting that data access on its own thread. When you want to cancel, set the flag in your data access class to true and Thread.Join the data access thread before firing off a new request.In this way, no Thread.Abort will be required.
|
|
|
|
|
A DataReader won't help me in this situation because the request normally returns only one row. Thus the first DaraReader.Read call will block.
Any other ideas?
|
|
|
|
|
Hi,
Wana read a binary file with .DAT extension and convert it into proper ASCII format data.
The same has to be written to a text file.
can someone please help me on that ?
heading towards Geek-Age !
- Prasadd
-- modified at 0:25 Thursday 9th February, 2006
|
|
|
|
|
Open the file with a FileStream object, then read the data into a byte array.
Use System.Text.Encoding.ASCII.GetString to convert the byte array into a string.
Then write the string to a file.
using System.Text;
using System.IO;
...
public static void Convert(string infile, string outfile)
{
if (!File.Exists(infile)) throw new FileNotFoundException();
FileStream fs = new FileStream(infile, FileMode.Open);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, fs.Length);
fs.Close();
fs.Dispose();
string str = Encoding.ASCII.GetString(bytes);
TextWriter t = new StreamWriter(outfile);
t.Write(str);
t.Flush();
t.Close();
t.Dispose();
} Hope this helps,
DigitalKing
|
|
|
|
|
Thank u for the help !
but, i am facing a strange problem with that code.
While taking the data into string it takes it properly but while writing the same string to the file it again writes it in the same way as the original binary file.
Heres the code
ResultString = Encoding.ASCII.GetString(BinDataRead);<br />
TextWriter tw = new StreamWriter(OutFilePath, false, Encoding.ASCII);<br />
tw.Write(ResultString);<br />
tw.Close();<br />
where am i going wrong ?
heading towards Geek-Age !
- Prasadd
-- modified at 2:48 Thursday 9th February, 2006
|
|
|
|
|
How can I add custom cursors to C#? I have the .cr file but I don't know how to use it on my application... thanks a lot!
|
|
|
|
|
Cursor.Current = new Cursor("MyCursorFile.cur");<br />
Note that the Cursor class is limited to non animated two color cursors.
|
|
|
|
|
where must I place the MyCursorFile.cur for C# to be able to access it? Two-color only?
|
|
|
|
|
Put it in the same folder as the executable of your application.
You can also specify an absolute path "C:\\MyCursorFile.cur"
|
|
|
|
|
I am trying to close a form from using this.close inside of an if statement. The if statement is inside of an button_click event. Whne I run the debugger, the apppliction continues through the this.close() command. Here is the code:
DialogResult result = MessageBox.Show(m_strEmpName + " " + DateTime.Now + " Is this correct?","Sign In", MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (result == DialogResult.No)
{
result = MessageBox.Show("Please Re-enter","Error",MessageBoxButtons.OKCancel);
if (result == DialogResult.Cancel)
{
Reader.Close();
conn.Close();
this.Close(); //continues after this
}
}
What am I missing here?
Thanx in advance!
|
|
|
|
|
The form should close correctly but the function will nevertheless continue running until completed. If you walso want to exit the function you will need an additional return; statement.
|
|
|
|
|
Hi,
I find some trouble in implement a managed C++ interface in my C# project, but I can call the static method of a managed C++ class in the same C++ project from my C# project. When I implement the C++ interface, the error is:
-----------------------------------------------
COM Interop registration failed. Could not find a type library for assembly 'MyCSharp'.
-----------------------------------------------
How can I get the type library and why this happened? The basic code is:
C#:
public class FormDelegater : WiDSAddinView.IWiDSForm
{
public void NotifyViewHandler(string funcName, int node, uint LC){
//TODO: ...
}
}
-----------------------------------------------
C++:
public __gc __interface IWiDSForm{
void NotifyViewHandler(String* funcName, Int32 node, UInt32 LC);
};
Thanks a lot!
Dilly
|
|
|
|
|
The first parameter is a string pointer. Declare it as "ref string" in the C# code.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for help, but the following code is generated by the .NET2003 automatic. If I add a "ref" before the "string", the compiler will tell me that I did not implement the NotifyViewHandler() method.
In another case I modified the interface to an abstract class, and the compiler shows no error, but all the global variables and functions in managed C++ code are "out of scope" at runtime. Looking the code below:
_________________________________
C++:
public __gc __abstract class PWiDSForm
{
public:
virtual void NotifyVIewHandler(String* funcName, Int32 node, UInt32 LC) = 0;
};
__________________________________
C#:
public class WF : WiDSAddinView.IWiDSForm
{
#region IWiDSForm Members
public void NotifyVIewHandler(string funcName, int node, uint LC)
{
// TODO: Add WF.NotifyVIewHandler implementation
}
#endregion
}
Dilly
|
|
|
|
|
tiancaidao wrote: COM Interop registration failed. Could not find a type library for assembly 'MyCSharp'.
Why are you using COM? You dont need it. I just did the following and it works.
MC++
namespace interface1
{
public __gc __interface IMyInterface
{
void NotifyViewHandler(String* funcName, Int32 node, UInt32 LC);
};
}
C#
class Test : interface1.IMyInterface
{
public void NotifyViewHandler(string funcName, int node, uint LC)
{
}
}
I just added the dll produced by the MC++ code to the C# project referencing it.
|
|
|
|
|
Oh, yes, you are right.
I created a new solution in .NET2003 and two new projects just now, with C# and C++, they work fine, but my original solution which contains a C# addin still has the error. I use ActiveX in another project in the same solution, and my C# addin project depend on it, like this:
projects:
1.VSUserControlHost--ActiveX
2.AddinProj----C# addin
3.ClassLib----MC++ Class Library
2 is depend on 1 and 3, I define the MC++ interface in 3 which has no relations with 1, my error comes from here?
The compile option went wrong?
And I can not find "/clr" in command arguments, is this abnormal?
Dilly
|
|
|
|
|
tiancaidao wrote: The compile option went wrong?
What is the exact error u are getting? You make no reference to this. We can only guess then, and we dont like to guess.
tiancaidao wrote: And I can not find "/clr" in command arguments, is this abnormal?
It's available at 2 levels, per project and per file. IIRC if its enabled at project level u dont see it file level (or vica versa).
|
|
|
|
|
In fact the error still is this:
COM Interop registration failed. Could not find a type library for assembly 'MyCSharp'.
I do use COM neither in my MC++ project nor the C# project, but when I implement C++ interface with C# exactly like what you has written above, the error comes.
All things go fine, when I do not do the implementation in C#.
(The C# has a reference VSControlHost.dll which is built from an ActiveX(COM/COM+) project, but I don't think this matters.)
And so far, you have help me a lot, Thanks very much!
Dilly
|
|
|
|
|
I forgot to mention, try viewing the output of the MC++ project in Reflector.
|
|
|
|