|
Ah yes!
I had a look at the Reflection name space, but i've never used it before so i didn't know what to look for.
I've got some ideas i want to try out with reflection, but it's waaaay down on my list of projects at the moment.
Cheers for that mate!
Cata
|
|
|
|
|
Hi,
Anyone knows how can I access a Windows process ?
i.e. Say I'd like to know when Microsoft Word is working or how much CPU is it using right now, or is my screen saver is on...
Thank you in advance,
Nir
|
|
|
|
|
Hi,
If you use the “System.Diagnostics” namespace you can find all the information you need.
Example:
Process [] localAll = Process.GetProcesses();
textBox1.Text = "Total number of processes: " + localAll.Length.ToString();
Process [] has a lot of nice information on what is going on in you operating system.
Hope this helped you a bit.
/ Magnus
|
|
|
|
|
If I load a bitmap and save it to a stream as a BMP and then converts the stream to an array of bytes I will get all my image data without any problems. But if I change the ImageFormat.Bmp to ImageFormat.Gif I will get an empty array of bytes! Help! -anyone?
MemoryStream ms = new MemoryStream();
Bitmap bm = new Bitmap(“test.bmp");
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] imagedata = new byte[ms.Length];
ms.Read(imagedata, 0, (int)ms.Length);
/ Magnus
|
|
|
|
|
Maybe you were lucky the first time with the bitmap
Try putting in a Flush() command after you've written the bitmap.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Thanks for the quick respond, unfortunately it didn’t help much - sorry . I still have the same error with the array (imagedata) being empty. And it still work ok when I formatted it a .BMP instead of .Gif!
This is the code as is:
Bitmap bm = new Bitmap("image1.bmp");
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
ms.Flush();
Console.WriteLine(ms.Length);
// Convert from stream to byte[]
byte[] imagedata = new byte[ms.Length];
ms.Read(imagedata, 0, (int)ms.Length);
ms.Flush();
// Convert from byte[] into a stream again.
ms.Write(imagedata, 0, imagedata.Length);
Bitmap bm2 = new Bitmap(ms);
|
|
|
|
|
|
Hi,
Thanks!!! It works perfect, but I still can’t understand how it worked with the BMP-encoding and not with Gif. Sometimes we must just accept the strange thinks in life
/ Magnus
|
|
|
|
|
Hello,
Can anyone tell me how to prevent my program being killed by pressing "End Task" of task manager ? I have seen that when we try to kill some apps it tells that we cannot terminate it, because of "some" reason.
Thanks James
|
|
|
|
|
Basically, you can't prevent this.
There are various reasons for not being able to kill the process, like the process is running under a priviledged or system account, is a system service where Windows cannot work without it, there is a debugger attached to the process, ...
But in all these cases, you're application would not be running under these circumstances. I've "heard" of a couple people doing this, but noone has ever come up with any code examples demonstrating it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
If you want to do this for a security program of some sort, you can have the program called under the user Administrator, and leave the computer on with a user account that doesn't have administrative rights.
Another way, depending on what you're trying to do, might be to start the program as a Windows service, and again, use a user account that doesn't have access to the Services control panel.
|
|
|
|
|
Why are you telling me this? I didn't post the question.
Also, I can't quite understand what your saying in the first paragraph, but it doesn't sound like a good idea. You NEVER use the Administrators account for anything other than system administration. Applications/Services/Servers should NEVER use this account.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Oops, sorry. Does a notification get sent to the original poster, or just to you?
And you're right, Administrator isn't the rght place to do it. How about a user specifically for the task, like what ASP does?
My bad on both the post and the idea.
|
|
|
|
|
Only the person you reply to gets a notification email.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm really curious what you want this for.
|
|
|
|
|
Hi!
In my program I'm using a class, which can nested like the TreeNodes in a
TreeView, thus I also want to use a TreeView to display some of the content
(a short string) of these nested classes. The user shall then be able to take
further actions when by clicking on the TreeNodes. Here comes the problem:
How do I map the currently selected TreeNode to the appropriate instance of
the nested class?
|
|
|
|
|
You need a reference to the TreeView, and to set a TreeViewEventHandler for its AfterSelect event. TreeViewEventArgs has a Node property that returns the selected TreeNode.
|
|
|
|
|
Or, the other way around, you can inherit from TreeView, create its nodes dynamically, and set each node's Tag property with an appropriate nested class instance.
|
|
|
|
|
Thanks a lot! That's exactly what I was looking for.
Now I've discovered another problem: The TreeView apparently always selects one node, no matter where I click. I, however have a context menu, which has to react differently, depending on whether the user clicks on a node or in some empty space. So I tried to determine the node at the clicking position with the GetNodeAt() method. This weardily always returns null.
Here's the code (tvAlbums is the TreeView and contMenu the contextMenu):
private void tvAlbums_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
Point pos = new Point(e.X, e.Y);
contMenu.Show(tvAlbums, pos);
pos = tvAlbums.PointToClient(pos);
if(tvAlbums.GetNodeAt(pos) != null)
{ /* a node was selected - adjust contMenu accordingly */}
else
{ /* no node is selected - adjust contMenu accordingly */}
}
}
|
|
|
|
|
Try checking the tvAlbums.SelectedNode property instead of calling GetNodeAt - does it give you the correct Node reference?
whoops -- i mean "in addition to calling GetNodeAt"
|
|
|
|
|
tvAlbums.SelectedNode does return a correct referece to a node, the problem however is that it always returns a node reference, even if the user clicked into the void.
|
|
|
|
|
In that case, a call to
tvAlbums.SelectedNode.Bounds.Contains(new Point(e.X, e.Y))
should tell you whether the node was clicked.
|
|
|
|
|
I forgot to add that you might want to change the value of tvAlbums.FullRowSelect and see what effect that has.
|
|
|
|
|
I've just found a working solution, which for which I cannot find any logical reason though:
When I create a point based on some EventArgs e, I first have to let the point go through a PointToClient operation and let it go through PointToScreen to make the GetNodeAt method to work properly:
Point p = new Point(e.X, e.Y);
p = tvAlbums.PointToClient(p);
p = tvAlbums.PointToScreen(p);
// now tvAlbums.GetNodeAt(p) will work properly
Thanks once again for your help!
|
|
|
|
|
you're very welcome.
Also, I realize upon reading your last message why you need to convert the Point. The MouseEventArgs X and Y properties relate to screen co-ordinates. Controls use co-ordinates based on their parent control's ClientRectangle. The conversion forces the TreeView to determine the screen co-ordinates of its own ClientRectangle, which it otherwise has no need to know.
I don't suppose you know a fast and reliable way to serialize rich text, do you?
|
|
|
|