|
i dont see anything wrong there...
but thinking about it a little more, the for loop MIGHT be holding up the UI thread, which MIGHT mean that the Form1_KeyDown handler only gets called after the for loop is finished executing.
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
FWIW, when I feel the need to capture command keys in a program, I like to do so via the ProcessCmdKey override because I've had issues with those captures in other available handlers. So, you might want to take a look at ProcessCmdKey and see if that will help.
|
|
|
|
|
What excactly are you trying to achieve? Is it that once the user has pressed the escape key, you want the application to terminate as soon as possible? Or do you have a longish OnPaint method which you want interrupted when the escape key is pressed?
The first would be much easier. The second I think cannot work without polling for the EXIT variable within the OnPaint procedure everywhere it could be interrupted, and even then I'm not sure it could work. A call to Application.DoEvents won't help cause in OnPaint you're right within handling the windows message queue and have to finish the loop anyway. The keyboard action only puts a message to the end of your form's message queue, which will not be processed before you leave the OnPaint method. Either you do some crazy unmanaged subclassing, or you split your painting logic into "atomic" operations which you instigate (via this.BeginInvoke) from a different thread. In this thread you can capture the EXIT flag set by the main thread via the escape key and if it's true stop pouring BeginInvoke(PaintNextPart) delegates to the main thread.
You need a little more then, of course, and a firm grip of threading and locking mechanisms, or you'll freeze your form.
|
|
|
|
|
Hi Guys,
Once again I humbly beg u to aid my rescue. Is it possible for me to alter the items in a datagrid based on input in a texbox?
onLoad of the form i fill the datagrid with all names from the DB. But, how do i remove items from the list based on the input of the datagrid?
He who goes for revenge must first dig two graves.
|
|
|
|
|
This sounds like you load the grid with names from the DB, but do not actually bind it to a DB datasource. If that is true, you might want to consider making this a data bound grid, bind it to a dataview, and then use the RowFilter property of the dataview to manipulate what is shown in the grid.
|
|
|
|
|
it's databound, but how do i implement the rowfilter as text is being inputed in the textbox?
He who goes for revenge must first dig two graves.
|
|
|
|
|
If it was me, I would probably refresh the grid after the text box entry is validated (e.g., on the Validated event of the text box). If you have a need to refresh the grid as each character is entered in the text box, then you can do it on the TextChanged event of the text box. That seems like a bit much to me, but I don't entirely know what you are trying to accomplish.
In either case, your code might look something like the following where oDataView is your DataView, LookupField is the data bound field you are searching on, textBox is your text box and DataGrid1 is your grid...
oDataView.RowFilter = "LookupField = '" + textBox.Text + "'";
DataGrid1.DataSource = oDataView;
|
|
|
|
|
This is kinda weird. When I run this:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = "explorer.exe";
psi.Arguments = @"C:\Data\Workshop";
System.Diagnostics.Process.Start(psi);
I get an error saying the path does not exist or is not a directory. However, if I just run:
System.Diagnostics.Process.Start(@"C:\Data\Workshop");
it runs fine. Why is that?
|
|
|
|
|
Either way works fine for me.
Dave
|
|
|
|
|
It could be that your not passing in the correct arguments for Explorer.
http://support.microsoft.com/kb/314853[^]
I haven't tried this out in C#, but I ran it from the command line with:
explorer /root,c:\
and it displayed correctly.
|
|
|
|
|
That would be why Knew it had to be something stupid. Thanks mate.
|
|
|
|
|
Huy everybody.
I have a little problem. I need to change a decimal symbol in Regional Settings programmatically on C#. Please help who know how to do this.
Thanks.
modified on Monday, July 14, 2008 10:37 AM
|
|
|
|
|
To change it for your app define a culture.
To change it for the system, I think you have to use SetLocaleInfo in kernel32.dll.
MSDN[^].
Dave
|
|
|
|
|
Thanks. You helped a lot.
|
|
|
|
|
Hello
I am working in C# and developing a desktop application. The main tasks of my application are Live Video Capturing, recording, transmission over LAN and motion detection. All are doing fine. But sometimes while grabbing a frame; it throws memory exception i-e
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt"
at line
b.Save("C:\\abc.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);// b is a bitmap object
///// other code
b.dispose();
and after that it throws exception i-e "A generic error occurred in GDI+". As I m continuously grabbing frames in a loop. So once it throws an exception, it stops working. I m searching over it but still didn't get any solution.
plz help me out
thx
Shanzay
|
|
|
|
|
Does your code interact with other non-managed code? I've seen this when using a C++ DLL from C#.
When the error occurs, what field values does the debugger show in the bitmap object? If they're all the same weird byte value, it may mean that object was already Disposed by another part of the code.
If this is happening, you need to trace backwards to locate where it occurs.
|
|
|
|
|
Hi,
Is there a good way of getting command line paramters into a windows forms app?
I can do this with a console app, obviously, but i'm not sure where to begin to allow a windows forms app to accept params.
thanks,
Jason
|
|
|
|
|
the same way youd get the prams in a console app, accept youll have to send them to the form at Application.Run();
i see the IDE does not give you the string[] in the main method but you should be able to add it like so
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain(args));
}
remember to catch the string[] args in the constructor of you main form
hope it helps
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
How can i find the main? It's not under Form1.cs obviously.
|
|
|
|
|
its in program.cs
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Oh i found it nevermind,.
What do you mean the constructor? In my case, Form1_Load?
|
|
|
|
|
in Form1.cs
namespace yourNameSpace
{
public partial class Form1 : Form
{
public From1(string[] myArgsFromProgramDotCS)
{
InitializeComponent();
}
}
}
i suggest you get and read a beginners book, hope this helped
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Environment.CommandLineArguments IIRC
|
|
|
|
|
|
Example is what? It shows the same stupid approach previously mentioned.
|
|
|
|