|
Hi all,
Is there an equivalent in C# to the old, stupendously useful C++ __FILE__ and __LINE__ (and __FUNCTION__) preprocessor macros?
At the moment, I'm creating a StackFrame and reading information out of that, but it seems a bit silly to do that when the code location is known by the compiler at compile-time.
Thanks in advance
|
|
|
|
|
|
hmm thanks. the solutions proposed all use the stack frame I ended up using. Sounds like a good feature to add to the preprocessor next time around (because the stack frame hack obviously won't work consistently in release builds).
|
|
|
|
|
It should work consistently in release builds provided you supply the app's .pdb with the release build, I believe.
|
|
|
|
|
Release build optimisations (at the very least, inlining code) will screw with the expected stack. I wouldn't hold out any hope of stack frames acquired in release builds to be accurate.
|
|
|
|
|
|
Hi,
I'm currently making an application that simulates a virtual drive using a file as storage and FAT32 as filesystem. I've made an explorer-like user interface, and I want to implement drag and drop from my application to explorer, but I cannot use the .net drag and drop directly since I store the items with a custom format as I said above.
I've thought of using the DragLeave event to create the dragged file as a temporary file and actually drop this temporary file.
Is this ok? Or is there a better way of doing it?
Thanks in advance.
|
|
|
|
|
you can Use MemoryStream to stroe your File Bytes in it
I know nothing , I know nothing
|
|
|
|
|
Hi...
Newbie to C#..so please be kind...
I am trying to get a list of files that start with letters only (avoiding files that start with ~ for example). Here is my simple code, which of course does not work:
<br />
DirectoryInfo dir = new DirectoryInfo("C:\Some Directory");<br />
FileInfo[] files = dir.GetFiles("[^a-zA-Z]*.doc");<br />
What am I missing?
TIA for any help. Sorry if this has been posted. I searched, but could not find....
J
|
|
|
|
|
Hi,
AFAIK you can use wildcards in GetFiles, the same you can in a DOS window,
or the Explorer's search pane, but nothing more fancy.
So you end up with two choices:
- do GetFiles("*.doc") and skip the files you dont like; (you would need
Path.GetFileName to extract the short file name again);
- create a loop with myChar going from 'a' to 'z' and do GetFiles(""+myChar+"*.doc"),
or alternatively construct a constant string that holds acceptable starting letters
and do a foreach myChar on it.
|
|
|
|
|
Thanks! Thats kinda what I thought, but figured I would ask to see....
|
|
|
|
|
Hi,
I'm implementing a drag object operation with panels.
The code i'm using for that is:
<br />
private void panel_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
Panel region = (Panel)sender;<br />
<br />
drag = true;<br />
panelBeingMoved = region;<br />
<br />
x = e.X;<br />
y = e.Y;<br />
}<br />
<br />
private void panel_MouseUp(object sender, MouseEventArgs e)<br />
{<br />
drag = false;<br />
panelBeingMoved = null;<br />
}<br />
<br />
private void panel_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
if (drag) {<br />
panelBeingMoved.Left += e.X + x;<br />
panelBeingMoved.Top += e.Y -y;<br />
<br />
x = e.X;<br />
y = e.Y;<br />
}<br />
}<br />
The problem is that the panel behaves in a very strange way. Instead of coming togheter smoothly with the mouse it is always jumping around with some pattern that i can justify.
Is there any simple explanation for this bahaviour?
What am i missing?
Thx,
Nuno
|
|
|
|
|
Hi
this is a different , method to move Control
hope it will help ,
Class1.cs
<br />
using System;<br />
using System.Runtime.InteropServices;<br />
<br />
public class Class1<br />
{<br />
public static int HTCAPTION = 2;<br />
public static int WM_NCLBUTTONDOWN = 0xA1;<br />
[DllImport("user32.dll")] <br />
public static extern int ReleaseCapture () ;<br />
[DllImport("user32.dll")] <br />
public static extern int SendMessage (IntPtr hWnd, int wMsg , int wParam, ref int lParam ) ;<br />
public Class1()<br />
{<br />
}<br />
}<br />
Example :
private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
<br />
int reflParam = 0;<br />
Class1.ReleaseCapture ();<br />
Class1.SendMessage (panel1.Handle , Class1.WM_NCLBUTTONDOWN , Class1.HTCAPTION , ref reflParam );<br />
}<br />
P.S
JUST TRY IT ... it's work like charming even if it look dos not
Have a good day ....
I know nothing , I know nothing
|
|
|
|
|
Hi,
Yes, this solution worka like charms. The only problem is that i don't understand what i am doing.
How can i get reference documentation for this? How can i know what more can i do with this?
I would love to be able to resize for example. Like you do when you choose a transform operation in Photoshop for example.
Thx,
Nuno
|
|
|
|
|
hi ( and thank you for testing my code )
no worries , if you don't understand it ...
cause my code was C++ and Win32 API , more than C# code
you can find many of this stuff ,
by searching in ( MSDN , Win32 API , C++ code .... etc )
have a good day
I know nothing , I know nothing
|
|
|
|
|
Hi guys,
I need some help please, I have a treeview and for each node I want to show tooltip data; this data is stored in a table and I don't think querying the table everytime the mouse is moved is a good idea. I was wondering if anybody knew a different way of showing the tooltip with database table data.
Please help!!!
sasa
|
|
|
|
|
hi
when you building your treeview
try to store your tooltip in ArrayList
then query the tooltip from this ArrayList
Have a good day ....
I know nothing , I know nothing
|
|
|
|
|
Thank you for your response. I have never used an arraylist before I googled and found some information but none shows on how to query an arraylist. Could you please give me an example.
sasa
|
|
|
|
|
Query the table just once when the treeview is loaded and store it in a datatable. After that display the data when the mouse is moved.
|
|
|
|
|
Thank you for your response. I believe I know how to do this. Either way once I have the datatable in order to get the tooltip data for that particular node, do I use datarow.select based on the ID of the data that I want to show?
Please advice
sasa
|
|
|
|
|
Thanks buddy. I got it to work with your suggestion.
sasa
|
|
|
|
|
You are welcome
|
|
|
|
|
I faced a problem when connting wiht Oracle9i. Plz somebody give me the instruction.
How can i get connected with Oracle9i.
sarwarmdgolam
|
|
|
|
|
What kind of problem are you facing?
|
|
|
|
|
OK, this is probably the C++ programmer in me still trying to break through the C# fog (so far it's been quite a pleasant learning curve though).
I woud like to "give names" to the values that my functions return. In my C++ days I would have used something like
#define OK 0<br />
#define ERR_PORT_NOT_OPEN -100<br />
#define ERR_NO_CARRIER -101
etc.
A function can then return ERR_PORT_NOT_OPEN if the port is not open as opposed to a meaningless int value of -100.
So I thought I'd go with enumerated types in C# and while it works I do feel that it could be a little more elegant.
I wrote a class called Defines with an enumerated type resembling this:
public enum ERR<br />
{<br />
OK = 0,<br />
PORT_NOT_OPEN = -100,<br />
NO_CARRIER = -101,<br />
}
so now a function can return Defines.ERR.PORT_NOT_OPEN as opposed to -100.
My gripe with this approach is that I'm constantly having to typecast this enumerated type to (int) . In other words the function has to return (int)Defines.ERR.PORT_NOT_OPEN and if I want to compare the outcome of a function with a switch for instance I have to do something like:
switch (myFunc())<br />
{<br />
case (int)Defines.ERR.PORT_NOT_OPEN:<br />
...<br />
break;<br />
case (int)Defines.ERR.NO_CARRIER:<br />
...<br />
break;<br />
}
I don't want to change the return type of the functions from int to Defines.ERR because I still have to use native functions which return int values (corresponding to the #define values of course).
So what do you guys do to achieve what I'm trying to?
|
|
|
|