|
AndyASPVB wrote: Also I noticed that won't work because the function is fired twice, which must be because there is two key strokes?...
Have you tried running the code without stepping through the debugger? I believe ProcessCmdKey may fire twice under this scenario with the first firing showing keyData as the modifier key values summed (e.g., Keys.Control + Keys.ControlKey), and the second firing being, from my code example (Keys.Control + Keys.C).
At any rate, I know the sample I gave you works for me with VS 2003 or VS 2005 for capturing modifier key combinations in ProcessCmdKey (whether it be Alt or CTRL with another key). If it really is not working for you, I'm sorry I don't know why. I have not tried this under VS 2008 and, if that is what you are working under, maybe there is some slightly different behavior.
|
|
|
|
|
Yes, I am working under VS 2008.
And what I wrote was in debugger mode and this is what was happening. When I switch off debugger, and just run it, nothing fires. I know nothing is firing because nested inside the if statement is a messagebox with a little message.
Could the type of machine the code is running have any influence?
|
|
|
|
|
Thanks this worked for me in c++ to be able to enabling panning with arrow keys. Holding ctrl at the same time enables micro panning.
|
|
|
|
|
I've done a lot of research into this problem and I'm not exactly sure how to tie all I've found together into a cohesive app...
Here's my situation. I built a rather simple web app that has a textbox and a button. If you put HTML code in the box and click the button, it embeds the code into the page. Simple, right?
Well I had this idea that instead of just embedding the code into the page, it stored the code for later usage, like an RSS feed. Well...not like an RSS feed, A RSS feed.
But here's the deal, HTML doesn't store well in XML. There are multiple ways of doing so (like CDATA), but I'm not sure which is best for later retrieval and embedding.
Is someone willing to assist me in learning which methods are best for storing HTML code in an RSS feed and how to later parse and embed the code written to it?
|
|
|
|
|
HttpUtility.HtmlEncode is probably what you are looking for.
|
|
|
|
|
Hello everyone
I'm working on a large project wich involves voice command. I've made the basic things (dictation, commands hardcoded with general Grammar) however now i wanted to implement my custom grammar XML file but i keep getting an error. I've gone over almost all the tutorials and scripts i could find on the matter (2 days of nearly non-stop research). So i finaly desided to post here for help.
I'm getting the "ComException was unhandled - Exception from HRESULT: 0x80046052" error on the following code:
Grammar.CmdLoadFromFile("C:\Grammar.xml", SpeechLoadOption.SLOStatic)
Here is a scaled down version of the problem:
Imports System
Imports System.Data
Imports System.Deployment
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Xml
Imports SpeechLib
Public Class Form2
Dim WithEvents RecoContext As SpSharedRecoContext
Dim Grammar As ISpeechRecoGrammar
Private Sub initialize()
If RecoContext Is Nothing Then
RecoContext = New SpSharedRecoContext
Grammar = RecoContext.CreateGrammar(1)
Grammar.CmdLoadFromFile("c:\Grammar.xml", SpeechLoadOption.SLOStatic) 'Error here
Grammar.DictationSetState(SpeechRuleState.SGDSInactive)
Grammar.CmdSetRuleIdState(1, SpeechRuleState.SGDSActive)
End If
End Sub
Private Sub btnInit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInit.Click
initialize()
End Sub
End Class
Any help would be appreciated!
Thanks in advance
p00m
|
|
|
|
|
I admit that this is just a bit of a wild guess, but I have had some very remotely similar problems when reading from XML files.
Considering the line of code where you have the error happening, and it then claiming that it is unhandled, suggests to me that the error is not actually happening in that line of code itself, but in the code that you are calling with the CmdLoadFromFile method.
In my case, after lots of research and hair pulling, I found that it all came down to some field in the xml file containing a naughty character like / or ' or & or <, etc. These characters would throw of the xml reader, and therefore cause an error in the code that called the reader.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi,
I have created a Access Table database. In the Visual Basic 2008 Express, i have created a windows form and i put datagridview into this form. The datagridview is bind to the database.
I want to select multiple cells in the table (shown in datagridview) and then copy these multiple cells' data into a text file.
Can anybody advise me the sample code to do this? Thanks.
|
|
|
|
|
Take a look at the DataGridView.MultiSelect and/or the DataGridView.SelectMode properties.
That should help with the first part.
Then look at the DataGridView.SelectedCells property. This returns a collection of cells, all you have to do is work out how to iterate through the collection. I'll leave you to work that bit out.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
I have built my own web browser in Visual Studio 2008, and what I would like to do is to close the browser if there is no activity.
How do you do this? Do you have to detect whether there is any key press or mouse movement, and then close?
Can someone please help me.
Thanks
|
|
|
|
|
AndyASPVB wrote: Do you have to detect whether there is any key press or mouse movement, and then close?
Yup. Put a timestamp on the last activity (meaning that each keypress and mousemove cause an update of that variable) and use the Application.Idle event to check whether there has been any activity between (Now - timestamp).
Alternatively, you could write a screensaver that simple loops all active processes and kills the browser
I are troll
|
|
|
|
|
Hi Everyone
I am looking if someone can give me some guidance.
Can someone explain to me how I can disable some hot keys, because the application I am building needs to be fairly secure. The keys I am looking to switch off are
1) Ctrl & C
2) Ctrl & X
3) Print Screen
4) Delete
They only need to be turned off for the duration of when the application is running.
How do you do this?
Thanks
|
|
|
|
|
Try taking a look at Global Windows Hooks[^]
When the corresponding key combinations are pressed, use e.Handled = True . Do read the article before using, so that you know what you're doing
Greets,
Zaegra
Motivation is the key to software development.
|
|
|
|
|
AndyASPVB wrote: 4) Delete
What's unsafe about the delete button?
I are troll
|
|
|
|
|
AndyASPVB wrote: 3) Print Screen
How are you going to deal with a screen capture utility?
What happens if someone has a custom mapped keyboard?
If someone is serious about snaffling your screens and text data, you are not going to stop them with this type of fix, you only get the casual users and annoy them into using more advanced tools if it is important to them.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi
All I am going to do is to set the clipboard to empty. None of these keyboards have a custom keyboard as they are a basic MS keyboard. None of the users are super geeks (this has already been confirmed). The environment in which the app will be used is super secure and the app itself has to be likewise.
|
|
|
|
|
I have an application that has a simple user interface but quite a bit of code under the hood. The interface is a file processing form where the user chooses a file and then clicks a button to process the selection. The code disables all buttons on the form and has at it. Quite a bit of the code is reading from the file and I report how many records every 100 count and then call Application.DoEvents (I know this is bad that is why I am here).
Part of this application uses BackGroundWorkers to run long SQL queries/updates where I use the .IsBusy property in a while loop and update a time elapsed message then call Application.DoEvents. I have a continuous progress bar that just runs all the time to show that something is happening but not necessarily reporting actual progress.
I also have true multi-threading where I kick off threads and I have a few steps in the process where I wait for a few of those threads to complete before starting others, as part of that waiting process I call the Application.DoEvents call again.
I have found many many articles online and forums where people say not to use Application.DoEvents, you should use backgroundworkers with ProgressChanged events. Well even though I implemented the Delegate step that they mention to set the value on the status bar for time elapsed, as soon as I take out the Application.DoEvents the form will report that it is not responding and if the user clicks on it they get the typical whited out form.
What should I use instead to guarantee that I dont have code stepping on itself?
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
CleaKO wrote: Well even though I implemented the Delegate step that they mention to set the value on the status bar for time elapsed, as soon as I take out the Application.DoEvents the form will report that it is not responding and if the user clicks on it they get the typical whited out form.
Can you post an example of that loop?
I are troll
|
|
|
|
|
Hi,
your GUI contains one or more handlers to react on user input such as buttons being clicked. For each of these handlers you should make sure they finish in "no time", no matter what.
"No time" means much less than one second if your prime concern is perfect GUI responsiveness,
or whatever your users will find acceptable.
Achieving that probably implies:
- not using any Thread.Sleep()
- not executing any loop waiting for something
- not performing synchronous I/O (unless a small timeout is applied)
- not waiting on something (such as a ManualResetEvent).
Everything that will, is likely to, or might, take longer must be delegated to another thread/threadpool/backgroundworker, and you cannot wait for it, since that would be the same as doing it yourself in the handler.
So it is not enough to use some backgroundworkers here and there, you must delegate everything that may take to long to threads/backgroundworkers.
|
|
|
|
|
Hi again,
I'm adding a standard text of mine about cross-thread access to GUI Controls, since you will probably need such info anyway:
Controls are not thread-safe, hence they should be touched (that is: their methods or properties called) only by the thread that created them, which normally is the main thread (aka GUI thread). Creating some controls on a different thread is unlikely to be successful, since all Controls get linked somehow: they reside on Forms, Forms are related to each other (by Parent, by Z-Order, etc), so normally all are created on a single thread.
If you violate the “don’t touch Controls from another thread” rule and are running .NET version 2.0 or above you will get an InvalidOperationException (“Cross-thread operation not valid”), which should be remedied by changing the code.
Do not set Control.CheckForIllegalCrossThreadCalls false, since that does hide the exception but does not cure the fundamental flaw in your code, so it just postpones the moment of failure, which typically will show as a non-responsive and possibly badly painted GUI.
Here are some ways to get another thread:
- explicitly launching a Thread instance
- explicitly delegating some work to a ThreadPool thread
- using a BackgroundWorker; a BGW is a separate thread with the advantage that two of its events (ProgressChanged and RunWorkerCompleted) execute on the GUI thread; however the bulk of the work normally is handled in the DoWork handler which runs on a distinct thread.
- using timers other than System.Windows.Forms.Timer; the Forms timer ticks on the GUI thread, all other use different threads to handle the periodic event;
- using asynchronous input/output, such as the DataReceived event of the SerialPort class
Any of these touching a single method or property of a Control is sufficient to create havoc; there are 5 exceptions:
- the InvokeRequired property
- the Invoke, BeginInvoke, EndInvoke and CreateGraphics methods (the latter only if the handle for the control has already been created).
If there is a need to touch the Control from another thread, one must use an Invoke pattern, which basically looks like this (using C# code, same can be done in VB.NET):
public void SetText(string text) {
if (myControl.InvokeRequired) {
myControl.Invoke(new Action< string >(SetText),
new object[] {text});
} else {
myControl.Text=text;
}
}
PS: if you follow my earlier advice you should not need Application.DoEvents() at all.
|
|
|
|
|
Hi,
Is there an event whether the mouse is over the form or not?
The normal mouseleave or mouseenter isn't exactly enough
if there are many controls on the form it is horrible...
|
|
|
|
|
architecton wrote: Is there an event whether the mouse is over the form or not?
Yup: Control .<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousemove.aspx">MouseMove</a>[<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousemove.aspx" target="_blank" title="New Window">^</a>] .
Good luck
I are troll
|
|
|
|
|
You are right but then i have to write this for each visible control on my form and this is not good because i only need one event and not x.
Example: Action mouse over form
Action mouse not over form
and not
Action mouse over control x
and Action mose over control y
...
Is there a better method?
It's difficult i know but i tried it and tried it
|
|
|
|
|
architecton wrote: You are right but then i have to write this for each visible control on my form and this is not good because i only need one event and not x.
You could opt to let all those controls MouseMove events point to the same eventhandler. E.g.,when you put two buttons on the screen, they can share their OnClick handler. Same can be done with the MouseMove event.
I are troll
|
|
|
|
|
Eddy Vluggen,
Mycroft Holmes,
Do you mean something like this?
Public sub Test () handles button1.mouseclick , button2.mouseclick
end sub
if yes, this is my problem and i try to avoid this
if no, could you write a short example like ton the top, please?
|
|
|
|