|
In the designer select the control you want an event for. In the property grid switch to "events" and double click the event you want to implement.
|
|
|
|
|
Many thanks to you my friend. You solved my big problem.
Happy Coding
Sheel
sheel
|
|
|
|
|
Though personally i think this approach is perfect (and i admit using it often)... but I'd hate to rely on the UI designer for the control events and such. Most of the times, for the sake of clealiness, I myself associate the events manually. And the C# IDE has a great intellisense for events. As soon as you type "MyControl.Event+=" .. simply press "Tab" twice and it'll do the job.
- Malhar
|
|
|
|
|
I am just starting out in C# and find my self stuck on a problem that looks to me to be a permission problem within my application. Any suggesions on where I should create the instance so both forms can access it?
I am tring to have a single instance of a class be accessable within multible forms.
Dumb version of what Im doing
NameSpace – App
{
Class Testing class
{ create an array of int's}
Form1
{
- Create instance of Testing class
}
Form2
{
- Access class created in Form1 !! ERRROR, I not see the instance..
}
}
|
|
|
|
|
Hi,
Implement your class as a Singleton?
So....
==================
using System;
namespace MyApp
{
public class MyClass
{
private static MyClass myClass;
//Make the constructor private instead of public.
private MyClass(){}
//Call this method to return the same instance to all.
public static MyClass GetInstance()
{
if (myClass == null)
{
myClass = new MyClass();
}
return myClass;
}
}
}
==================
|
|
|
|
|
Hi,
How can I write a timer function in C#, so that the timer
can register the datetime (but not the interval) of the event ?
And if my timer program sleep as the PC sleep while the user away,
how can I alert the timer to re-check the scheduled event to see if
there are any events that is over-due ? (i.e. is there are any
event handling for watching the PC system awaking from sleep ?)
Thanks
|
|
|
|
|
ChristmasTree wrote:
How can I write a timer function in C#, so that the timer
can register the datetime (but not the interval) of the event ?
You can't. The best you can do is to write a frequent timer that checks the date/time to see if it has passed.
ChristmasTree wrote:
And if my timer program sleep as the PC sleep while the user away,
how can I alert the timer to re-check the scheduled event to see if
there are any events that is over-due ? (i.e. is there are any
event handling for watching the PC system awaking from sleep ?)
Same as above - check the time regularly, and if it has passed, then act. It won't matter then if it's passed by 1/2 second, or by 20 years.
<edit>
Of course, Windows HAS a scheduler, I don't know much about it, but I presume you can schedule your own task there, but I take it to mean you want to do something entirely in code within your existing program.
</edit>
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Why c# programs don't run on PCs where there's no a setuped visual studio ????
i tried to run a c# executable file on a pc where there was no setuped visual studio, and i was surprised when the error message appeared.
Don't Smile To The World...It Does Not Smile To You
|
|
|
|
|
comingsoon wrote:
Why c# programs don't run on PCs where there's no a setuped visual studio ????
i tried to run a c# executable file on a pc where there was no setuped visual studio, and i was surprised when the error message appeared.
I'm astounded how many people use the .NET framework and have absolutely no idea how it works.
C# and VB.NET programs compile to an intermediate language called MSIL. The .NET framework installer runs as part of the VS install, obviously. Anyone who wants to run your C# executable needs to also have the .NET framework installed. If you don't want that requirement, use C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Is there any other solution 4 that prob ?
where can i find the .NET framework ???
Thanks for reply, Christian
Good is Good
|
|
|
|
|
comingsoon wrote:
Is there any other solution 4 that prob ?
No, your options are C++ and the .NET framework. If there was any other option, why would anyone download the framework to start with ?
comingsoon wrote:
where can i find the .NET framework ???
Choose[^] any of the hits I got from google, I'm sure at least the first four will give you a download link.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
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
|
|
|
|
|
|