|
hello ! do any 1 know to how create even_click for dynamic button with C# ? if any1 know , please give me some guide line....
|
|
|
|
|
By "even_click", do you mean an event that fires on every other click of the button?
Click 1: Do something
Click 2: Ignore
Click 3: Do something
Click 4: Ignore
etc...
If this is Windows Forms, then I'd say keep a boolean flag in your form, and toggle it at the beginning of each button click. If your flag is true after the toggle, then continue with your event handler, otherwise return. While this may not be a true "even_click" click, it gives you the same effect. You would of course need a separate flag for each button that has such an event.
void button_Click(object sender, EventArgs e)
{
flag = !flag
if(!flag)
{
return;
}
}
Dybs
|
|
|
|
|
The actual method itself you will have to create beforehand, you cannot do this dynamically (it can be done by dynamcaly generating IL I believe but it's probably not neccesary).
You should create a general method that all your dynamic buttons call, you can retrieve the button from the sender parameter. To identify which button it is, you can use the Tag property (or use your own button class derived from Button and add some unique property to save some boxing/unboxing) if needed.
Button dynamicButton0 = new Button();
dynamicButton0.Click += new EventHandler(Button_Click);
dynamicButton0.Location = new Point(12, 12);
dynamicButton0.Tag = 0;
Controls.Add(dynamicButton0);
Button dynamicButton1 = new Button();
dynamicButton1.Click += new EventHandler(Button_Click);
dynamicButton1.Location = new Point(12, 34);
dynamicButton1.Tag = 1;
Controls.Add(dynamicButton1)
void Button_Click(object sender, EventArgs e)
{
Button clickedButton = sender as Button;
if (clickedButton.Tag is int)
{
int ID = (int)clickedButton.Tag;
MessageBox.Show(ID.ToString());
}
}
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)
|
|
|
|
|
Hi.
I've created this program[^] some days ago. (I've had WinXP then)
It works on XP well , but when I wanna run it on Vista SP1 Ultimate this error[^] occurred.
and there is a link in the error window http://oca.microsoft.com/en/dcp20.asp[^]
What's wrong ?
Could you guide me ?
Thanks
PS : I've installed SQLExpress 2008 on Vista
|
|
|
|
|
It's most likely something that is wrong with your installation.
Normally, a program using a database will not make the database crash for any reason.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: It's most likely something that is wrong with your installation.
You mean SQL Server Installation ?
|
|
|
|
|
Yes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Can I get any advice, please? I need to develop sentence scanning program to match the sentences with defined set of words and do calculations on it. Can anyone please suggest me any reference sites or some functions related to this program? Thanks so much.
|
|
|
|
|
I wonder why all the 1 votes - unless this the the nth time you have asked.
Seems your problem is to identify the sentence terminators within a string . or ? This should define your sentence and doing calcs on the word is easy.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for your reply. Yeah, this is the first time I asked.
My problem is: in my database, I have defined words table selected from english dictionary and a number of product reviews which contains more than one sentence to check how many words can match with each product reviews. It is something like information extraction, but cannot use data mining.
Is that suitable if I use RegularExpression Libraries? I am not asking codes detail, but some references or some tips on the C# String functions. Thanks.
|
|
|
|
|
hey
i have to make a program in which a server send a video stream to client and client fill this stream into a buffer...now problem is i have to play this video stream from circular buffer filled by server...
Please HELP!!!!
|
|
|
|
|
Hi,
this is my last chance to understand how to update a database through a dataset.
My application is here : [1].
I did a simple application to understand the databases and relative classes in C#.
I have seen that VS2008 is not setting the updatecommand in the wizard, so I fill in by hand. Maybe the problem is there.
UPDATE Customers
SET LastName = @LastName, FirstName = @FirstName
WHERE (CustomerID = @CustomerID)
Thanks in advance.
Stefano
[1] http://www.mediafire.com/?3zgfdmzgnyg
|
|
|
|
|
Hello,
C# 2005
I am using a background worker to process some login information. However, the background worker has to stop and wait for 2 events to happen. Once these have finished the background worker can complete its job. They are callbacks that will call the Set() method of the AutoResetEvent.
So I am using AutoResetEvent to set when these 2 events have finished. However, I seemed to be getting this error message
"Exception has been thrown by the target of an invocation."
And Inner exception
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index".
The exception usually fires when the registration success leaves scope.
Many thanks for any advice,
AutoResetEvent[] loginWaitEvents = new AutoResetEvent[]
{
new AutoResetEvent(false),
new AutoResetEvent(false)
};
private void bgwProcessLogin_DoWork(object sender, DoWorkEventArgs e)
{
Console.WriteLine("Wait until event is set or timeout");
loginWaitEvents[0].WaitOne(3000, true);
if (this.accountInUseFlag)
{
if (this.lblRegistering.InvokeRequired)
{
this.lblRegistering.Invoke(new UpdateRegisterLabelDelegate(this.UpdateRegisterLabel), "Account in use");
}
else
{
this.lblRegistering.Text = "Account in use";
}
e.Cancel = true;
this.accountInUseFlag = false;
return;
}
else
{
this.bgwProcessLogin.ReportProgress(7, "Account accepted");
}
Console.WriteLine("Just Wait the result of successfull login or not");
loginWaitEvents[1].WaitOne();
if (this.registerSuccess)
{
this.bgwProcessLogin.ReportProgress(7, "Register Succesfull");
this.registerSuccess = false;
}
else
{
if (this.lblRegistering.InvokeRequired)
{
this.lblRegistering.Invoke(new UpdateRegisterLabelDelegate(this.UpdateRegisterLabel), "Failed to register");
}
else
{
this.lblRegistering.Text = "Failed to register";
}
e.Cancel = true;
return;
}
}
private void VaxSIPUserAgentOCX_OnSuccessToRegister(object sender, EventArgs e)
{
Console.WriteLine("OnSuccessToRegister() [ Registered successfully ]");
this.registerSuccess = true;
this.loginWaitEvents[1].Set();
}
private void VaxSIPUserAgentOCX_OnIncomingDiagnostic(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnIncomingDiagnosticEvent e)
{
string messageSip = e.msgSIP;
string sipErrorCode = "600 User Found";
if (messageSip.Contains(sipErrorCode))
{
this.accountInUseFlag = true;
Console.WriteLine("OnIncomingDiagnostic() WaitEvent.Set() accountInUseFlag: " + this.accountInUseFlag);
loginWaitEvents[0].Set();
}
}
modified on Saturday, May 16, 2009 10:18 PM
|
|
|
|
|
From the exception text, the exception seems to be occurring in UpdateRegisterLabel . Try debugging that method by placing a breakpoint at the start of the method.
|
|
|
|
|
Hello,
I solved my problem. It was something in the RunWorkercompleted.
However, there is one more thing. The registerSuccess and AccountInUse are global because they are been accessed from 2 different threads. Would it be better to put a lock on them?
Many thanks
|
|
|
|
|
Getting a setting a bool is an atomic operation. However, in your code there are gaps between checking the variables for true and setting them to false. It is possible to fall through on true and the variable then gets set to true again, whereupon you set it to false. This may not matter, but is a matter of concern.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hello,
When you say that setting a bool is a atomic operation. Does that mean the the operation will has to complete all of it, or fail? What would be the difference in setting either a string or a integer?
Thanks,
|
|
|
|
|
steve_rm wrote: Does that mean the the operation will has to complete all of it, or fail?
Yes, the CLR guarantees that all operations on datatypes less than or equal to the size of a native pointer will be atomic. So on a 32 bit machine, storing and retrieving integers is atomic, while the same operations on longs (64 bits in size) are not.
|
|
|
|
|
"atomic" means the value will get set at once - other threads reading the value at the same time will either see the old value or the new value, nothing "in between".
Reading/writings strings and ints is also atomic.
However, reading/writing longs (or other value types >32 bit) is NOT atomic: you might end up reading 32 bits from the old value and the other 32 bits from the new value.
But even though it's atomic, I'd suggest that you still put a lock around it.
For example, in this code:
Initialization:
int a = 0, b = 0, c = 0;
Thread 1:
a = 1;
if (b == 0) c++;
Thread 2:
b = 1;
if (a == 0) c++;
From a simple look at the code, it seems that c will be 0 or 1.
c shouldn't be 2 because "c++" cannot run on both threads - it's incremented only if the other thread hasn't set its flag (a or b) yet.
Writes and reads to a,b are atomic. The increment of c is not atomic (read and write of c are atomic, but the combination read-increment-write isn't atomic).
But actually, it is possible for both "c++" to execute, so c could become 2! (though only on dual-core machines)
It's also possible that both "c++" execute but c still becomes only 1.
Both "c++" can execute because x86 CPUs are allowed to move the "read"-instruction from the if-condition above the write-instruction from the assignment above (or they might execute the read and write in parallel). I've tested this myself using hand-written assembler code, an Intel Core Duo WILL move reads above writes where possible!
You'll have to insert a memory barrier instruction to prevent the CPU from doing that.
In C#, the "volatile" keyword can be used for some kinds of memory barriers: volatile writes have release semantics, volatile reads have acquire semantics. That's sufficient for many cases of unsynchronized access to variables, but it doesn't help in the example I gave above - we need a full memory barrier there.
->
If you access shared variables without locks, might have to insert a memory barriers to synchronize the memory between CPUs. It's extremely hard to get those right.
So I would suggest that you keep it simple and always use a lock.
|
|
|
|
|
Without proper formatting this is too hard to read.
Use the PRE tags (not the code tags) to preserve formatting and indentation.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello,
I have aspx web site. There are many files in this website (image files). How can i find a particular file (check if exist) in this site? there are also directories in the site with files inside- Is it possible to search the file recursively inside this directories too (without entering each one)?
|
|
|
|
|
Google Desktop search? Good answer or not?
|
|
|
|
|
No.
I want to put it in my application and file the file if it exist. The file is located in a website , not in the computer.
If there is no way to search for a file in website.
How can i check if a URL exists?
|
|
|
|
|
You can't unless u own the website but u can ping it or use HttpRequest
|
|
|
|
|
OK,
So how can i check if the website works? i mean if URL works...
|
|
|
|