|
Is it possible to detect the insertion and removal of Plug and play devices (for example : keyboard , mouse etc) while the computer is still ON. We wanted to do the above in C#. We tried a couple of WMI classes like win32_Keyboard class, but after manually removing the Keyboard, there was no change in the Property "status" of win32_Keyboard. it showed that the status was OK.
We also tried a piece of code which uses win32_DeviceChangeEvent but that also doesnot seem to work for plug and play devices.
Plaese can u suggest some Solution to this problem.,
thanks in advance
|
|
|
|
|
Hello
VS 2008
I have a resource file called Form1.fr-FR.resx which has been added to my project when I set the local and language of the form.
In my Form1.fr-FR.resx I have button1.Text, button2.Text. I have set the culture to fr-FR so when the form starts its displays the french language in the buttons.
However, I would like to include some string of my own in this file. I have added strName, strAddress as I want to display these in a message box. However, when I add more control to the form the string I have added get deleted. When I open the Form1.fr-FR.resx using edit plus the string are there. However, when I try and display them, I just get a blank.
Is there some reason that the strings don't persist in the resource file?
Some code that I am using:
Dim rm As New ResourceManager("LanCulture.Form1", Me.[GetType]().Assembly) <br />
Console.WriteLine(rm.GetString("strName", Thread.CurrentThread.CurrentUICulture))
Many thanks for any advice on this,
|
|
|
|
|
steve_rm wrote: Dim rm As New ResourceManager("LanCulture.Form1", Me.[GetType]().Assembly)
This is C# forum.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi
I've made a graphic simulation with a timer. But now I want to stop the simulation (but not disappear) only freeze the simulation.
I've already tried to use a do-while-loop but then the application crashes.
I've also tried to use a if-loop and in the loop set the length (that the application have to drawn) to zero but it doesn't freeze.
I've also tried to use in a if-loop, to call another function which doesn't do anything but this doesn't freeze the application.
Also I did this in a do-while-loop but then it crashes.
Does someone knows an answer and perhaps knows an example that I can understand what you're trying to say.
PS: The simulation is shown in a pictureBox
|
|
|
|
|
Graphic simulations often depend on calculations done in an Update loop based on the time that elapsed since the last frame. If you set the elapsed time in your update loop to zero (i.e.: "no time elapsed since the last frame"), you can bring your simulation to a halt.
Another possibility would be to set a flag bool paused = true and stop any updates whenever this flag is true .
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you for your reply. Is there also an oposit of Update()? Something like .Pause()? I've tried somethings out but they aren't right.
|
|
|
|
|
Those methods handle completely different functions then what you may thinking. Update() or Invalidate() are used to refresh the entire form based on the information contained in the OnPaint event. Their is no way to pause the OnPaint event unless you write your own graphic logic. One of my articles Basics of Falling Blocks in VB2005[^] has been able help some people understand how the painting system works in WinForms as well as how it should be thought of.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
1. With a System.Timers.Timer just use the Stop() method to stop the timer.
2. With a System.Threading.Timer, just don't use this timer (why? read documentation). Replace with a System.Timers.Timer
3. For good performance forget timers. Force rendering into app's main loop (as Greeeg mentioned)
modified on Wednesday, August 27, 2008 8:03 AM
|
|
|
|
|
This[^] should do the trick.
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Cool. :P
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
As the others suggested, the answer is to stop the actual simulation from taking place by means of something like an internal variable or a timer setting. Simply freezing the application will cause Windows to think it has hung, and which will display the unresponsive program dialog (which I am guessing is what you are calling "crashing"). It will also not allow you to unfreeze it again later.
You might also look into performing the simulation on a separate thread (though remember you will still have to update the picturebox on the main thread), because then you will just be able to pause and resume the simulation thread at will, and without chewing up CPU cycles in an infinite loop.
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
But how can I do this in this code?
[code]
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// opvragen van de burst die momenteel gedaan is
// dit kan via een methode in de Controller te steken
// die controlleerd welke knop (FCFS-SJF) ingedrukt werd
// in deze klasse wordt er dan gekeken naar de eindeburst
// Dat moet dan doorgestuurd worden naar hier.
Graphics g = e.Graphics;
String algoritme = cmbSchedule.SelectedItem.ToString();
int burstlengte = 0;
switch (algoritme)
{
case "FCFS": //burstlengte = Controller.GetInstance(ProcessList).Simulatie(ProcessList[0].lijstvanBursts[0]);
burstlengte = Controller.GetInstance(ProcessList).Hoeveelburst(ProcessList[0].lijstvanBursts[0].Lengte);
foreach (Proces p in ProcessList)
{
foreach (Burst b in p.lijstvanBursts)
{
if (Controller.GetInstance(ProcessList).Teller > p.PAankomst + b.Lengte)
{
// No simulation anymore
//burstlengte = 0;
//pictureBox1.Update();
}
//do
//{
// eind();
//} while (Controller.GetInstance(ProcessList).Teller > (p.PAankomst + b.Lengte) || Controller.GetInstance(ProcessList).Teller == (p.PAankomst + b.Lengte));
}
}
break;
case "SJF": //burstlengte = SJF.getInstance().GeordendeLijst[0].lijstvanBursts[0].Lengte;
//burstlengte = Controller.GetInstance(ProcessList).Hoeveelburst(SJF.getInstance().GeordendeLijst[0].lijstvanBursts[0].Lengte);
break;
}
// Laat de simulatie niet verder gaan als de burst gedaan is
//if (Controller.GetInstance(ProcessList).Teller > burstlengte + ProcessList[0].PAankomst)
//{
// burstlengte = 0;
//}
//int burstlengte = Controller.GetInstance(ProcessList).Simulatie(ProcessList[0].lijstvanBursts[0]);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(20, 20, burstlengte , 100);
Pen redPen = new Pen(Color.Red, 3);
g.FillRectangle(Brushes.Red, 25, 20, burstlengte , 100);
//Graphics g = e.Graphics;
//foreach (Proces p1 in lbProcessName.Items)
//{
// foreach (Burst b in p1.lijstvanBursts)
// {
// int burstlengte = Controller.GetInstance(ProcesList).Simulatie(b);
// g.SmoothingMode = SmoothingMode.AntiAlias;
// Rectangle rect = new Rectangle(20, 20, burstlengte * 2, 100);
// Pen redPen = new Pen(Color.Red, 3);
// g.FillRectangle(Brushes.Red, 25, 20, burstlengte * 2, 100);
// }
//}
}
private void eind()
{ }
[/code]
|
|
|
|
|
First of all, move all of that outside of PictureBox.Paint and into a separate thread that modifies a shared (synchronized) bitmap image. Then run the above and either send events to the main thread to update the picture box with the current state of the bitmap at various intervals, or do this on a timer. Just be sure to use lock() before accessing the shared bitmap on either thread.
In PictureBox.Paint just draw the shared bitmap to the PictureBox.
Now when you pause the simulation, the picturebox should no longer receive signals to update, or if you put it on a separate timer, you should also pause that timer when you pause the simulation.
Logan
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
I have one multiline textbox. I want to open Microsoft word and write textbox contents on MS word.
One more thing : I want to write DataGridview Table onto MS ecxel sheet.
???
thanx in advance....
|
|
|
|
|
You need to use MS Office Interops
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I want a toasted cheese sandwich but sometimes we can't always have what we want.
Look up the interops like t'other member said, and then if you get stuck you can ask about the specific problem you are having and people will be happy to help.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Thanks for quick reply...
Problem of MS Word from C# has been done.
Now i want to Write Tabular data from DataGridView to MS Excel Sheet.
I want Excel sheet also in Tabular format.
Opening of Excel sheet and writing data into it, has also been done.
But format of DataGridView into Excel sheet is not coming.
|
|
|
|
|
Hi,
How can I reach database relation diagram of sql by using smo? I want to learn parent key table of any column if that column is foreign key.
Forexample, in northwind database, in products table, there is categoryid column. This column is related to id in Category table. I want to find this.
Best Regards
THANKS
|
|
|
|
|
It is really rude to repost everywhere.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi..
I want to increment/dercrement the selected Value in the datetimepicker using keys like a to z.. if i press A it should increment the value by 1, if i press B it should decrement the value by 1.
can anyone help me plz..
thanks & regards
vinayskvs
modified on Wednesday, August 27, 2008 8:03 AM
|
|
|
|
|
Hello Everybody,
How can we create a class using ComClass Template.
First of all, I am not able to add the reference of Microsoft.Build.Tasks.V3.5 since it is not being listed out in the Add Reference dialog. So I browsed this dll and added the reference.
Still my problem is not solved. I am getting the following error.
'Microsoft.Build.Tasks.Deployment.ManifestUtilities.ComClass' is not an attribute class
I am not sure.
Here is my code,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Tasks.Deployment.ManifestUtilities;
namespace COMArray
{
[ComClass(ComClass2.ClassId, ComClass2.InterfaceId, ComClass2.EventsId)]
public class ComClass2
{
#region "COM GUIDs"
public const string ClassId = "83a8275f-9282-4257-ba62-afab6ed03beb";
public const string InterfaceId = "e75a1569-f1aa-4bdc-8e39-ae5807ee5baa";
public const string EventsId = "f966bdd3-9c5b-4ad9-8714-bc17d28f7e3a";
#endregion
public ComClass2()
: base()
{
}
private int _test;
public int test
{
get { return _test; }
set { _test = value; }
}
}
[ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)]
public class ComClass1
{
#region "COM GUIDs"
public const string ClassId = "35cf06df-5ed3-431f-9780-1e30d8acb94c";
public const string InterfaceId = "04fcc0fb-da33-4750-bab1-86e3b6d0e300";
public const string EventsId = "e073bca9-3bc5-437a-8c77-a489086c6517";
#endregion
public ComClass1()
: base()
{
}
private ComClass2[] t;
public ComClass2[] myFunction()
{
t(0) = new ComClass2();
t(1) = new ComClass2();
t(0).test = 111;
t(1).test = 222;
return t;
}
}
}
Am I on track? Am I using the ComClass properly.Can anybody guide me through the ComClass attribute usage? I just want to create a class using ComClass Template.
Any help is greatly appreciated.
Cheers,
Saran
|
|
|
|
|
Hi everybody
i want to change machain datetime ,but i dont how
thanks for help
MD_NADA
|
|
|
|
|
md_nada wrote: i want to change machain datetime ,but i dont how
Follow the following steps:
1. Open Notepad
2. Go to Format->Font. Select your favourite font.
3. Look at the time on the Wall Clock at your home/office and write it in on the NotePad.
4. Save the file at C:\ drive with name currenttime.txt.
Or did you expect any other answer
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hi maybe i was not clear , i mean change machain date programaticlly
using C#
MD_NADA
|
|
|
|
|
see the extreme bottom-right of your computer screen(where the system time is displayed),double click the system time being displayed...and make the changes
|
|
|
|