|
Isn't it also astounding how many people don't know how to use the Internet, or more specifically, a search engine?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yeah, that's also a good point.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Hi,
what is the most proper right to create a synchronized arrayList
that can allow different threads to access it ?
Thanks
|
|
|
|
|
|
All,
Just wondering if it is possible to parse XML from a string in memory, as opposed to a file? I'm getting XML data over a TCP/IP connection, and it is read into a string in memory. I could dump the string to a file, then parse the filename to XmlTextReader, but that seems like a waste of resources.
Any pointers would be appreciated.
Cheers,
Andrew
|
|
|
|
|
Hi Andrew,
there are some solutions:
1st)
If you only want an XmlDocument, use the methode LoadXml of the XmlDocument class.
<br />
string myXmlContent = @"<GoodSides><Side name='CodeProject'>http://www.codeproject.com</Side></GoodSides>";<br />
XmlDocument xmlDoc = new XmlDocument();<br />
xmlDoc.LoadXml(myXmlContent);<br />
2nd)
Copy the bytes (or strings) to a MemoryStream.
<br />
byte[] myContent = ...;<br />
MemoryStream memStream = new MemoryStream(myContent);<br />
XmlTextReader xmlReader = new XmlTextReader(memStream);<br />
or
<br />
MemoryStream memStream = new MemoryStream();<br />
StreamWriter memWriter = new StreamWriter(memStream);<br />
memWriter.Write(@"<GoodSides>");<br />
memWriter.Write(@"<Side name='CodeProject'>http://www.codeproject.com</Side>");<br />
memWriter.Write(@"</GoodSides>");<br />
memStream.Position = 0;
XmlTextReader xmlReader = new XmlTextReader(memStream);<br />
3rd)
Implement a own class with Stream as BaseClass.
This class can read the datas direct from TCP/IP.
<br />
class MyOwnStream: Stream<br />
{<br />
int Read(byte[] buffer, int offset, int count)<br />
{<br />
...<br />
}<br />
};<br />
MyOwnStream myStream = new MyOwnStream(...);<br />
XmlTextReader xmlReader = new XmlTextReader(myStream);<br />
4th)
Use the SocketStream direct. (If the stream contains only the xml data and no more.)
<br />
NetworkStream myNetworkStream = new NetworkStream(mySocket);<br />
XmlTextReader xmlReader = new XmlTextReader(myStream);<br />
Hope, it helps
Niedzi
|
|
|
|
|
how can I get message I want in a textbox after checking a chekbox?
|
|
|
|
|
Use CheckBox.CheckedChanged event:
checkBox1.CheckedChanged += new EventHandler(CheckBoxOnCheckedChanged);
And then implement this handler:
void CheckBoxOnCheckedChanged(object obj, EventArgs ea) {
textBox.Text = message;
textBox.Invalidate(); // you shouldn't use this line, but...
}
|
|
|
|
|
I have a hierarchy of objects. For simplicity's sake, let's say I have a TreeView containing a hierarchy of TreeNodes.
I'd like to add these TreeNodes to an ArrayList, with the top-most level TreeNodes being added at the beginning of the list, 2nd-level TreeNodes added next, 3rd level nodes after that, and so on.
Anyone know of an efficient algorithm to do this? Or should I just resort to manually going down each hierarchy level, adding each node to the list as I go along?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
This is not a depth-first tree traversal, so you probably need to create array of arrays:
<br />
ArrayList[] lists = new ArrayList[DEPTHS_COUNT];<br />
then go through all nodes using recursion:
<br />
void Traverse(TreeNode tn, ref ArrayList[] lists, int depth) {<br />
<br />
lists[depth].Add(tn);<br />
<br />
if (tn.Nodes.Count > 0)<br />
foreach (TreeNode node in tn.Nodes)<br />
Traverse(node, ref lists, depth + 1);<br />
}<br />
...and the last step is to split lists into one list:
<br />
ArrayList nodeList = new ArrayList();<br />
<br />
foreach (ArrayList list in lists)<br />
foreach (TreeNode tn in list)<br />
nodeList.Add(tn);<br />
Is that what you need?
|
|
|
|
|
Hi Judah,
It's not difficult.
Use following call
ArrayList = ListOfTree(myTree);
and implement ListOfTree with this:
static ArrayList ListOfTree(TreeView tree)
{
ArrayList list = new ArrayList();
<small>
list.AddRange(tree.Nodes);
<small>
for (int idx = 0; idx < list.count; idx++)
{
list.AddRange(((TreeNode)list[idx]).Nodes);
}
<small>
return list;
}
Example:
You have this tree:
Tree
|-A1
| |-B1
| | |-C1
| | +-C2
| +-B2
| +-C3
+-A2
+-B3
First you add the Nodes of the tree:
List := A1 A2 [from Tree]
Second you add each child of the already listed nodes: A1 A2
List := A1 A2 B1 B2 [from A1]
List := A1 A2 B1 B2 B3 [from A2]
And so on for each child of B1 .. B3
List := A1 A2 B1 B2 B3 C1 C2 [from B1]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from B2]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from B3]
And so on for each child of C1 .. C3
List := A1 A2 B1 B2 B3 C1 C2 C3 [from C1]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from C2]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from C3]
Have fun,
Niedzi
|
|
|
|
|
|
|
How to show information about a picture in a picture box when put mouse over?
|
|
|
|
|
Label myLabel = new Label();
myLabel.Text = "here is an interesting pic";
myPictureBox.Controls.Add(myLabel);
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
Hi
Okay, this is my first post so please bear with me..
Anyhow. I'm working on an oldish MFC application that uses dlls as 'plugins' - similar to Photoshop, Cubase etc. Now as part of my attempts to bring some of this kicking and screaming up to date, I'm trying to add another dll for use, written in C#.
I've done the 'use managed extensions' trick, and can instantiate the C# dll by adding it as a reference, and all seems to behave as expected - but I'm having some difficulty then handling the C# form's OK/Cancel. Ideally, I'd like any information or data contained within the C# form to be passed back to the MFC form - more as a verification that whatever the dll is supposed to do has been carried out successfully or not (plus as a demo of language interoperability it seems a good idea to persuade the nay-sayers).
I figure it's going to be done through interop - so pass a handle to the parent CWnd to the the C# dll, and then post a message to it once the dll 'ok' button is pressed - but where is my main starting point for going about this? Is this the best way to go about it, or is there something I've overlooked?
thanks,
benwalker
|
|
|
|
|
Do you have control over when the C# form is launched? If so, can't you just go (in Managed C++):
DialogResult result = launchedForm->ShowDialog();
if(result == System.Windows.Forms.DialogResult::OK)
{
}
Maybe I'm not understanding your problem.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
hmm. now why didn't I think of that one - well, it saves going through interop or something else. I forget the fact that managed c++ has access to the same type of messages.. anyway - that seems to work:
thanks
benw
|
|
|
|
|
Hi,
My application needs to login to a web site automatically. Is it a way to programtically fill in the username and password web fields from a .NET windows form?
Thanks.
|
|
|
|
|
Is there a program where I allow the user to pick an Image from a Windows form and allow them to make that into a desktop WallPaper.
sahoREGS
|
|
|
|
|
I'm not sure if there is something in the .NET library, but if all else fails you can use the API call SystemParametersInfo() to do it.
Matt Gerrans
|
|
|
|
|
There's a registry key for something like that:
HKEY_CURRENT_USER\Control Panel\Desktop\
There you've got some values like ConvertedWallPaper, OriginalWallpaper, Wallpaper enz.
Hope this helps!
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
hi
can anyone tell me that can we create a button array if we can then how we will display a button using that array on the form or write text on that button.
please tell me soon
|
|
|
|
|
Why do you need to create button array? I don't know what are you working on, but array of buttons can be initialized as well as any other array:
Button[,] abtn;
of if you want jagged array, use:
Button[][] abtn;
Then traverse all buttons using for cycle and set their properties:
Button btn = Button[3, 2];
btn.Size = btnSize;
btn.Parent = this;
...
|
|
|
|