|
Well, that's interesting. It's like the click is cached and processed once the control is re-enabled.
I used the following:
private void button1_Click ( object sender , System.EventArgs e )
{
System.Windows.Forms.Button button = sender as System.Windows.Forms.Button ;
System.Console.Beep() ;
if ( ( button != null ) && ( button.Enabled ) )
{
button.Enabled = false ;
System.Threading.Thread.Sleep ( 2000 ) ;
button.Enabled = true ;
}
return ;
}
|
|
|
|
|
hi
thanks for your quick reply. i have tried the code, but unfortunately it does not work. if you click the button twice within two seconds, you would hear two beeps meaning that the event has been fired, even though the second click was on a disabled button
this is a very strange issue, i guess the event queue is not cleared. if one does not enable the button at the end of the function, only one event will occur. for instance the following has the same consequences:
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
System.Console.Beep();
Thread.Sleep(2000); // could be a blocking function
button1.Enabled = true;
}
thanks
|
|
|
|
|
The problem here is you are disabling the button and then 'freezing' the UI thread.
So when you click the button, or anything in the form then that click can not be processed until the form unfreezes. The form will only unfreeze once the thread sleep has finished and the Tick event is complete (at which point the button is re-enabled) so the 'Click' is effectively done on an enabled button.
Basically it is the form that is processing your click and is can only do so when it the UI thread is free to do so.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Right, I hadn't meant that as a solution.
|
|
|
|
|
Here's a quick example of using a thread to do the task:
private void
button1_Click
(
object sender
,
System.EventArgs e
)
{
System.Windows.Forms.Control control =
sender as System.Windows.Forms.Control ;
if ( ( control != null ) && ( control.Enabled ) )
{
control.Enabled = false ;
(new System.Threading.Thread ( this.DoStuff )).Start ( control ) ;
}
return ;
}
private void
DoStuff
(
object Control
)
{
System.Windows.Forms.Control control =
Control as System.Windows.Forms.Control ;
if ( control != null )
{
System.Console.Beep() ;
System.Threading.Thread.Sleep ( 2000 ) ;
this.Enable ( control ) ;
}
return ;
}
private delegate void EnableDelegate ( System.Windows.Forms.Control Control ) ;
private void
Enable
(
System.Windows.Forms.Control Control
)
{
if ( Control != null )
{
if ( this.InvokeRequired )
{
this.Invoke
(
new EnableDelegate ( Enable )
,
new System.Windows.Forms.Control[] { Control }
) ;
}
else
{
Control.Enabled = true ;
System.Console.Beep ( 440 , 100 ) ;
}
}
return ;
}
|
|
|
|
|
Hi everyone out there !!!!
around 2-3 days back I wrote an article here, after which I received a mail that I got to explain it a bit more....... I did it......but it isn`t added yet.
can someone here pls tell me that how much time do they usually take to accept an article?
its my first time .... so am quite a novice here at codeproject
|
|
|
|
|
It won't be publicly visible until it's approved. I'll have a look at it now and post back through the article's forum, not through here. The correct place for questions such as this is probably Site Bugs / Suggestions[^] for future reference
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
It's still sitting there waiting for approval (by a gold+ member). Indeed it is better than when you first published it.
I promised myself I wouldn't approve any articles, but I guess I will, just this once.
|
|
|
|
|
Usually Articles are posted within a day
|
|
|
|
|
its has been added now....... thnx to all who wrkd!!!!
|
|
|
|
|
I have a windows forms application which does invoicing among other things.
When a new invoice line is created the user can request a modal form with article numbers. On this article select form I want to create a "new" button which loads another modal form on which the new article is defined.
C# says it can't launch a modal form from a modal form.
Does anyone have a solution ?
I'm flexible in architecture of the application so a different approach is fine.
Thanks in advance,
Rob
|
|
|
|
|
well I can use Form.ShowDialog() inside a Form which is displayed itself using Form.ShowDialog()... same thing you are looking for me thinks
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi,
Works for me with the following code where Form1 has one button.
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
Form1 f = new Form1();
f.ShowDialog(this);
}
}
How are you creating and showing the forms?
Alan.
|
|
|
|
|
PosiRob wrote: C# says it can't launch a modal form from a modal form.
What are you telling?
How are you opening a modal form. Is it using
form.ShowDialog() [ where form is an object of your form ]
By this way you can open as many modal forms as you want.
|
|
|
|
|
Thanks for the quick replies. I created a simple application to test your comments, and it proves you are right.
I get the run time error when I want the modal form to be a child in an MDI application, and I misinterpreted the error message.
Problem solved, thanks again.
Rob
|
|
|
|
|
You are most welcome.
you can also rate the answers if it really helped you ..
|
|
|
|
|
I have a large xml document and I am extracting out individual nodes from it. I don't want any manipulation.
its like
start-large
start-small
.
.
close-small
start-small
.
.
close-small
and so on.
It works fine if I do.
XmlDocument xmlDoc= new XmlDocument();
xmlDoc.Load(xr.ReadSubtree());
xmlDoc.Save("c:\\one.xml");
But for the following the XMl document I get it messed up.
XmlTextWriter xw = new XmlTextWriter("C:\\two.xml", null);
xw.WriteNode(xr.ReadSubtree(), true);
I get errors like "end element missing" or "not properly closed".
What am I doing wrong in case of text writer? xr is the xmltextReader which is reading the large file.
Your help is appreciated.
|
|
|
|
|
Check if all your begin tags have closing tags in your XML file.
|
|
|
|
|
can someone explain if i need to use all the three lines of code mentioned below to disable the cache in a page.actually if i am using only Response.CacheControl = "no-cache" then also page is working properly.then what is the use of another two line..and also is it a server side cache or client side?
Response.CacheControl = "no-cache"
Response.AddHeader("Pragma", "no-cache")
Response.Expires = -1
|
|
|
|
|
If you are talking about ASP.NET, then please post it in ASP.NET forum
|
|
|
|
|
How i can get Hardware seail number of hard disk byc# code?
|
|
|
|
|
If you google using serial instead of seail, you will find many results.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
mht2008 wrote: How i can get Hardware seail number of hard disk byc# code?
You can read it easily using WMI .
Try this
using System.Management
Public string GetHDDSerialNumber(string drive)
{
if (drive == "" || drive == null)
{
drive = "C";
}
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive +":\"");
disk.Get();
return disk["VolumeSerialNumber"].ToString();
}
Source : Use WMI to get HDD's serial number
Note : You have to add System.Management.Dll from Reference
[EDIT]
For Exploring WMI : Please Download WMI Code Creator
[/EDIT]
Hope this will help you
|
|
|
|
|
|
Thanks
|
|
|
|