|
The best way in VS .NET to add events to WinForm components is to either double click on the object in design view or on the property pane click events (the little lighning bolt) and pick what kind of event you want. Then VS will automaticly generate the code for that event. So you only have to code the functionality for the event. Any code added to the generated methods will be deleted or changed automaticly. So the best way is to make your own method or use VS to add it. Hope this helps.
JProd
|
|
|
|
|
Hello again.
Now I tried the Save and Load routines from the DUMeter project !
They're very good .. and I only gave my FileName and my TreeView-Control as
Object and the saving of the file works fine.
And it looks like the samples in the help.....
But now as I want to load that file again to fill my TreeView
I have a nice Exception :
An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.
I have no idea what causes the error. The file isn't in use and was not edited.
He stops at the command where he starts reading the file :
System.Xml.XmlTextReader reader = new XmlTextReader(filename);<br />
<br />
while (reader.Read()) <-- HERE<br />
{ ....
Could someone please again help me in this case ?
|
|
|
|
|
j-hannemann wrote:
Now I tried the Save and Load routines from the DUMeter project !
They're very good ..
Thanks, but that will only work for flat classes. It was never intended to walk a tree. Here's some code that mite help, but I have not made a FromXml function.
public class HashTree: System.Collections.DictionaryBase
{
char del;
public HashTree()
{
del = (char) 0;
}
public HashTree(char delimter)
{
del = delimter;
}
internal int level = 0;
private HashTree(int level, char del):this(del)
{
this.level = level;
}
public virtual HashTree this[string key]
{
get
{
string[] tokens = key.Split(del);
HashTree outer = this;
foreach (string keyt in tokens)
{
if (!outer.Dictionary.Contains(keyt))
outer.Dictionary.Add(keyt, new HashTree(outer.level + 1, del));
outer = outer.Dictionary[keyt] as HashTree;
}
return outer;
}
}
public virtual System.Collections.ICollection Keys
{
get
{
return this.Dictionary.Keys;
}
}
public virtual System.Collections.ICollection Values
{
get
{
return this.Dictionary.Values;
}
}
private object obj;
public object Value
{
get {return obj;}
set {obj = value;}
}
public string ToXml()
{
StringBuilder output = new StringBuilder();
string pad = "";
for (int i = 0; i < level; i++)
pad += "\t";
foreach (string key in Keys)
output.AppendFormat("{2}<{0}>\n{1}{2}</{0}>\n",
key, (this[key].Count > 0 ? this[key].ToXml() : (pad + "\t" + this[key].Value + "\n")), pad);
return output.ToString();
}
} And the usage is easy.
HashTree tree = new HashTree('.');
foreach(....)
{
tree
["rootlevel"]
["nextlevel"]
["anotherlevel"]
.Value = "somevalue";
tree["rootlevel.nextlevel.anotherlevel"].Value = "somevalue";
}
string xml = tree.ToXml(); This give you a nice tree, but I havent got around to making a load from XML method. If you can make one, I'll give you credit .
Cheers
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hello again
Thanks leppie for you code but I am not that good to write
a load routine for it.
This is my first c# project.
I've done saving now with another more simple solution.
But it works fine.
But I just wanted to try a little with XmlTextReader/Writer --
and again everytime I want to read the file I got an exception.
Saving works perfect ... and the file looks fine...
Has somebody any idea what I can do ??
|
|
|
|
|
Hi
I have a problem with an unmanaged callback. First the C API.
BOOL CALLBACK YourRecordProc(
void *buffer,
DWORD length,
DWORD user
);
...
DWORD CALLBACK MyRecordingWriter(void *buf, DWORD len, DWORD user) {
fwrite(buf,1,len,file);
return TRUE; In C# I define:
public unsafe delegate int UnsafeRecordCallBack(void* pbuffer, int length, int user); And the callback function:
private unsafe int UnsafeProgress(void* buffer, int length, int user)
{
Trace.WriteLine(++COUNT, "caLLBACK count");
return 1;
} Now I debug this with native debugging set as well and this happens:
caLLBACK count: 1
caLLBACK count: 2
caLLBACK count: 3
caLLBACK count: 4
caLLBACK count: 5
caLLBACK count: 6
First-chance exception at 0x001b67b6 in RecordTest.exe: 0xC0000096: Privileged instruction.
Unhandled exception at 0x001b67b6 in RecordTest.exe: 0xC0000096: Privileged instruction.
Like WTF Eisha. Any suggestions? What Win32 Thread of the 2 zillion is the culprit? How can I trace what is happening here? It appears to crash quicker if I move my mouse.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Looks like thread collision. Add a critical section[^], just in case.
|
|
|
|
|
Thanx. Although thats NOT the solution, is that not just the same as Monitor or using the lock command?
Anyways, it works without problems (with "empty method") when passing a static delegate instance. Could it be that .NET is moving function addresses around?
[edit]static as in the delegate itself is static, not just the method[/edit]
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie wrote:
Although thats NOT the solution, is that not just the same as Monitor or using the lock command?
Yes. Your callback being C code, I thought of suggesting WIN32 CriticalSections.
leppie wrote:
Could it be that .NET is moving function addresses around?
From watching sscli code, the only "good" reason for addresses to be rebased on-the-fly would be appdomain switch, but that sounds odd enough.
|
|
|
|
|
.S.Rod. wrote:
From watching sscli code, the only "good" reason for addresses to be rebased on-the-fly would be appdomain switch, but that sounds odd enough.
Too odd But thanks for the info.
I have made and implemetation of the callback and it works flawlessly in a "static" context. O well, I can just internally do that and pass it onto an instance delegate and let consumers of the assembly register that delegate. Maybe an event perhaps...
Cheers
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Here is some info I got from the author:
"Yep, callbacks need to be static member functions. There is no "this" pointer in static functions though, so you should pass "this" as the user parameter in the BASS_RecordStart call. This applies to C++ anyway, but I guess C# too?"
Now it appears that C++ callbacks can be instance delegates, but C callbacks has to be static. Any idea how I could pass this as an int into the start method or will marshalling do its own thing?
Cheers
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie wrote:
Now it appears that C++ callbacks can be instance delegates, but C callbacks has to be static. Any idea how I could pass this as an int into the start method or will marshalling do its own thing?
"this" is on the call stack. (the meaning of all ldarg.0 code ops before each function call).
|
|
|
|
|
.S.Rod. wrote:
"this" is on the call stack. (the meaning of all ldarg.0 code ops before each function call).
English? Is it possible to convert an object to an int? Or do I need to reference something else, like a handle so I can recreate the object in the static function?
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I tried to compile the following pattern to match the filename from a complete file path:
(?!.*\\\\).*
Example:
"C:\My Programs\Office\Word.exe" - match result : "Word.exe"
This works fine when I create an instance of System.Text.RegularExpressions.Regex.
However, in the compiled form the pattern above would always result in:
"C:\My Programs\Office\Word.exe"
Does anybody know what the reason is? Or do you have a better pattern to use?
Thanks!
|
|
|
|
|
Try this one:
.*\\([^\\]*)
Don't forget to duplicate the \ if in C#.
You'll have two matches, the second one is the file name.
It is a bit slower, because it has to do some backtracking, but may work in your case.
I see dumb people
|
|
|
|
|
Thanks for the tip Dan,
I tried the pattern and here's the result:
--------------------
.*\\([^\\]*)
C:\My Documents\foo.doc
Matching: C:\My Documents\foo.doc
0 => C:\My Documents\foo.doc
1 => foo.doc
--------------------
Is there an option I could set so that the first match gives me the intended result right away?
thanks again
|
|
|
|
|
Investigate the Path class for this, instead of using regular expressions. There's a method in there made for what you are trying to do.
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
If the file name is in the middle of a text, the System.IO classes won't help him, e.g., for highlighting paths and URLS on e-mails.
I see dumb people
|
|
|
|
|
I've got a treeview/listview pair in a backup program that acts similar to windows explorer, enumerating all drives,folders and files on a PC. I've set it up so there are checkboxes for entries in both controls, so you can select entire folders or just individual files...
I'm wanting to save all the checked items to a "job" file so the backup component can read the job file and perform the backup according to the selections.
Do I have to build this information dynamically (using an array or collection), or do the treeview/lisview controls keep this info around for me?
thanks.
|
|
|
|
|
The .NET treeview has no built-in serialization feature. For more info[^].
|
|
|
|
|
I am trying to redistribute a program that requires both the .net framework and MDAC version 2.6 or higher. I am trying to use microsofts examples of how to create one setup program that will install these components, but i want to use both together. I can implement both seperately but the moethods they give both create a new exe file that test for either MDAC 2.x or the presence of the .net framwork, installs as needed and then continues with my MSI program. the examples check for one OR the other, and the problem is both programs link to the MSI from my application, and I would like to have one setup that does a MDAC search, then goes to the .net search then installs my apps MSI file. anyone know how to do this?
thanks in advance
dan
|
|
|
|
|
A few hints :
First, use only merge modules (*.msm files) provided by MS.
Second, checking the installed MDAC version does not require a thorough procedure. If you use the MS COM Checker (provided in the MDAC MS portal), it's a total mess and quite honestly for most needs this represents 10x times too much overhead. My hint is to check out the dll file version (xx.xx2.yy.yy2 = major, minor, build major, build minor) of one the dlls which happens to be upgraded with all MDAC version : for instance msado15.dll. You've got a MS online article which tells the public version of that dll for each major MDAC release.
Here is the mapping table I use (C code):
typedef struct _MDACVERSION
{
int nMinor;
int nBuildMajor;
char *szPublicName;
} MDACVERSION;
MDACVERSION tabMDAC[] = {
{ 50, 4403, "2.5 RTM" },
{ 51, 5303, "2.5 SP1" },
{ 52, 6019, "2.5 SP2" },
{ 53, 6200, "2.5 SP3" },
{ 60, 6526, "2.6 RTM" },
{ 61, 7326, "2.6 SP1" },
{ 62, 7926, "2.6 SP2" },
{ 62, 7400, "2.6 SP2 Refresh" },
{ 70, 7713, "2.7 RTM" },
{ 70, 9001, "2.7 RTM Refresh" },
{ 71, 9030, "2.7 SP1" },
{ 0 , 0 , "" }
};
|
|
|
|
|
Owner-Draw TreeView with SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint,true);
Problem with the overriden OnPaint methode:
I added two nodes. When the control appears the first time, the OnPaint() methode panits only the first node!? When I move the mouse over the invisible second node then OnPaint draw the second node(but goes through OnPaint twice!?). So the nodes ar only painted when I move the mouse over the nodes. Refresh() or Invalidate() changes nothing.
What could that be? Any suggestions that the TreeView paints its nodes the first time?
|
|
|
|
|
You cannot be using OwnerDrawn support and "ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint" because they are two different, mutually exclusive things.
In Windows you usually can paint a control in three ways:
1- OwnerDraw which is when you handle the OnDrawItema and OnMeasureItem messages. In this situation the control ask you to do the drawing of a particular item at right time. Some of the oldest controls support this techinque: menus, combo box, etc.
2- Custom draw. This is a more fine grained version of the OwnerDraw version, here you have the oportunity to draw just part of the item instead of assumming full resposabilty for the whole drawing. Some of the more sophisticated common controls support this technique: TreeView, ListView.
3-. User Paint: You do the whole drawing yourself. In this case you don't have any help but you have full control as to what to paint. This is what you need to use when you are going to write a control from scratch. This is by far the best technique to write powerful controls because you have totally control of the painting.
One last thing: how are you using OwnerDraw techinque for the TreeView control? As far as I known the TreeView control does not support OnMeasureItem or OnDrawItem methods. You could use CustomDraw but only if you hack the support yourselve using the fact that the .NET TreeView is just a wrapper for the native TreeView control in the Common Control library.
Regards,
Carlos H. Perez
|
|
|
|
|
Thank you very much for answer!
I found now a Sample Solution which seams to be good.
So I will try it with CustomDraw with WndProc(..). But I fear that it will flicker.
It's really a problem that .NET not supplies OnDrawItem and OnMeasureItem for TreeView; that's why I have problems to solve it. I cannot understand this. OwnerDraw is - as I mean - often used; so why these Microsoft Programmers didn't implement it for us?
One question: to do TreeView OwnerDraw with OnPaint(...); how could I do this?
It would be very usefull because I can set the DoubleBuffer Flag and paintings are without flicker. I've tried but there were unlogical things happening; just the first item was painted. The rest of the items were only drawn when I moved the mouse over the other items? Strange.
Can you help me?
Thanks
Stefan
|
|
|
|
|
I use "CustomDraw" on my sample article TreeView control and flickering is almost non existing due in part to some technique that I use to draw the node in a double buffer that I passed to the tree control itself. I don't know what you are looking for but my article show pretty well how to CustomDraw the items.
Regards,
Carlos.
|
|
|
|