|
We know that in winform,we can use "Tab" key to move focus,and now I want to move focus when I pressed "Enter" key in C# code project, I had added this code section in my form source,but it doesn't work sometimes.How can I do?
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (keyData == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
return base.ProcessCmdKey(ref msg, keyData);
}
|
|
|
|
|
I haven't tried, but if key is enter, don't call base.ProcessCmdKey .
|
|
|
|
|
Hope this can help..
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
SendKeys.Send("{TAB}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
}
|
|
|
|
|
It can be simplified like this:
8.Kelvin(){
Wont_stop_coding = true;
}
|
|
|
|
|
Hihi, thanks.
Nice coding
*12Code
|
|
|
|
|
I need to break entire method when I click cancel. But when I put break its break if else part only. How can I break entire method?
private void NT_FormClosed(object sender, FormClosedEventArgs e)
{
MessageBox.Show("Do you want to close the program?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2); {
if(DialogResult == DialogResult.Yes)
{
Save(sender);
}
if (DialogResult == DialogResult.Cancel)
{
Break; :doh:
}
}
}
A S E L A
|
|
|
|
|
return;
|
|
|
|
|
No cannot. when i use return still same.its all the way close the application. i want to continue application running when user click cancel.
A S E L A
|
|
|
|
|
FormClosed event handler is too late to cancel form closing. Try FormClosing[^] event. You can use FormClosingEventArgs.Cancel property to cancel the form closing.
|
|
|
|
|
Hello everybody,
My application uses a ListView control to display a list of files. Everything works fine except that when I set the
View property of the ListView to View.List, the list appears but, here's[^] a screenshot of how it looks. I can't understand,
why the filenames are condensed and appended with a "...". I've searched
google and msdn, but couldn't found a solution for the problem. The Large Icon[^] and Details Views[^]
are working perfectly. Just the list view is misbehaving.
My second problem is regarding a BackgroundWorker. I have a BGWKR that I'm using to perform a database transaction.
Now the problem is that the user may close the form while the transaction is in progress.
To handle this, I added code to the form's closing event handler, to inform the user that a transaction is active and ask
him/her, whether to cancel it. If the user affirms, then a call to BGWKR.CancelAsync() is made. Here's the form_closing event.
private void WndSearchResults_FormClosing(object sender, FormClosingEventArgs e)
{
if (bgDatabaseSearcher.IsBusy)
{
if (MessageBox.Show(Resources.msgSearchActive_WindowClosing, "Question",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = true;
return;
}
else
{
bgDatabaseSearcher.CancelAsync();
while (bgDatabaseSearcher.IsBusy)
Thread.Sleep(500);
}
}
}
Here's the BGWKR's Do_Work event
private void bgDatabaseSearcher_DoWork(object sender, DoWorkEventArgs e)
{
VFS virtualFS = new VFS();
foreach (ListEntry entry in imagesToSearch)
{
try
{
virtualFS.OpenConnection(Path.Combine(AppSettingsManager.ImagesDirectory, entry.imageDbPath));
foreach (VFSSearchTerm searchTerm in termsToSearch)
{
virtualFS.SearchVFS(searchTerm, searchOptions, SearchResultProcessor, entry.imageID);
if (bgDatabaseSearcher.CancellationPending)
{
virtualFS.CloseConnection(true);
return;
}
}
}
finally
{
virtualFS.CloseConnection(true);
}
}
}
However, the DoWork methods cancels gracefully if CancelAsync() is called from a button's click event handler.
Please help.
Thanks
Excuse me for buttin' in, but I'm interrupt driven.
modified on Monday, April 6, 2009 11:27 PM
|
|
|
|
|
Hi,
1.
there seems to be no easy solution.
This article[^] is probably the best approach, however I never tried it.
2.
I did not understand the problem; also the post is too wide for easy reading.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
My apologies for the post being too much wide. I've reformatted it now.
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
Hi,
much better now.
I still don't see what your problem #2 is, you say it works??
I do have 3 comments:
1. assuming lViewSResultsBrowser is a ListView, you are not allowed to perform a Groups.Add() operation (or any other Control operation) on it since Controls are not thread-safe. Without an InvokeRequired/Invoke construct it may hang your GUI temporarily or forever.
2. IMO all that is required for the cancellation is a simple
if (bgDatabaseSearcher.CancellationPending) break;
since that will bring you in the finally block, hence close the connection and return.
3. I don't particularly like the loop while (bgDatabaseSearcher.IsBusy) Thread.Sleep(500); since it makes your GUI hang for as long as the BGW takes; you have made your GUI thread a slave of your background worker now, so if the BGW never terminates, your app is stuck while the user wanted it to exit. The minimum I would do is impose an upper limit.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
Thanks for your response.
Well, my problem is not that the BGWKR is not working. Infact, it's working perfectly.
My problem is that if I call CancelAsync() from FormClosing event, the Do_Work method never stops
execution and the .IsBusy property never becomes false. At the same time, the code inside the Do_Work
event seems to be jammed. I can say this as the if(CancellationPending) condition in the Do_Work event is never hit.
The very same architecture works flawlessely, it CancelAsync() is called from a button's click event handler.
Your 1st comment: That Groups.Add() call is nothing. I added it for testing purposes while debugging.
So don't worry about that. I know it's not a thread-safe operation and will remove it.
Your 2nd comment: Doing so will only get me out of the inner foreach loop. What about the outer one?
Your 3rd comment: That i'll replace with code to hide the form and then wait till the BGWKR finishes or a deadline is met.
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
OK,
here is an hypothesis: maybe CancelAsync does not get forwarded to the BGW (or has no net effect) as long as the GUI thread is still busy; when inside a Button_Click handler, it is free right away; in your Form_Closing handler, you keep the GUI thread occupied with the sleep loop.
suggested experiment: rather than the while-sleep loop, set e.Handled true and see if the CancelAsync now works; if it does, it confirms the hypothesis; I then suggest you don't use CancelAsync, instead create your own boolean variable to communicate from Form_Closing to DoWork.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks,
Your hypothesis was perfectly correct. When I removed the while(...)...; loop from the form_closing event, it started working perfectly.
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
I'm following this example:
http://www.geekpedia.com/tutorial179_Creating-a-download-manager-in-Csharp.html
it seems like a really straight-forward tutorial, however, the line "webResponse = (HttpWebResponse)webRequest.GetResponse();" always gives a (407) Proxy Authentication Required exception.
What can I do to make my app pick up the same authentication that Internet Explorer uses ?
Note: Internet Explorer LAN settings is set to:
Checked "Use automatic configuration script"
Address: http://xxxxxxxxxxxxxx.yyyyy.zzzzzzz.net/proxy.pac
|
|
|
|
|
|
GetDefaultProxy() sounds like a dream come true since I don't want the user to have to hassle with copy and pasting their proxy IP and port into my "settings" form. Additionally, I don't want the responsibility of storing their details in an encrypted file.
However, GetDefaultProxy() is now antiquated.
Also, using UseDefaultCredentials = true doesn't work.
Is there an alternate solution to using GetDefaultProxy() ? Maybe reading the registry ?
|
|
|
|
|
WebRequest.GetSystemWebProxy() doesn't work either. I still get the 407 error.
i.e.
webRequest = (HttpWebRequest)WebRequest.Create(strURL);
webRequest.Credentials = CredentialCache.DefaultCredentials;
IWebProxy wp = WebRequest.GetSystemWebProxy();
webRequest.Proxy = wp;
|
|
|
|
|
through trial-and-error I finally got it solved.
On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:
public string GetWebPage(string strURL)
{
string strResult = "";
HttpWebRequest webRequest;
webRequest = (HttpWebRequest)WebRequest.Create(strURL);
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
webRequest.Proxy = proxy;
webRequest.Method = "GET";
webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)";
webRequest.Timeout = -1;
HttpWebResponse webResponse;
webResponse = (HttpWebResponse)webRequest.GetResponse();
using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
|
|
|
|
|
this is also not working boss.M getting error
|
|
|
|
|
I get the Proxy Authentication only when using NUnit; the same code works fine when invoked in the real environment.
Anyway, adding the following lines makes it work in NUnit:
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials;
request.Proxy = proxy;
|
|
|
|
|
Hi, not sure if you're still struggling with this.
Maybe this could help... I was looking at a solution to call a web service from behind a company firewall, but I didn't want to code any proxy settings nor user credentials in my app. The app should simply use my default IE proxy settings.
I'm using .Net 2.0 and here's the C# code to make it work.
<br />
IWebProxy oProxy = WebRequest.GetSystemWebProxy();<br />
oProxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials;<br />
"your WS stub".Proxy = oProxy;<br />
Hope this helps.
|
|
|
|
|
Hi all,
I need help regarding how to communicate with OPCServer. I am developing an application in C#. In project Reference I added OPCAutomation 2.0(COM). I am adding the code which I done.
OPCServer MyServer = null;
OPCGroups MyOPCGroups = null;
OPCGroup MYOPCGroup = null;
MyServer = new OPCServer();
MyServer.Connect(ProgID,NODE);
// till here ok
MyOPCGroups =(OPCGroups) MyServer.OPCGroups;
// but when I tried to create the OPCGroups I am getting casting error saying:
// "Unable to cast object of type 'OPCAutomation.OPCServerClass' to type 'OPCAutomation.IOPCGroups'."
MYOPCGroup = (OPCGroup)MyOPCGroups.Add("MyGroup");
I really hope you can help me!
Regards,
Alessandro
|
|
|
|