How can i do this in C#? [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to do something like this:
Button button = new Button("Button");
button.addClickListener(new ClickListener(){
//Implement required methods here..
});
How can i do this in C#?

Attach the event handler:
button.Click += myClickEvent;
...
protected void myClickEvent(Object sender, EventArgs e)
{
// do your thing
}

Related

Is there a way to perform a type specific action in a generic class? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
class Class1<T>
{
T Value;
void Method1()
{
if(Value is int)
Value = 42;//CS0029
}
}
Is there any way to make code like this work?
It is possible, but usually there is something wrong with the code if you need to do this in a generic class.
if (Value is int)
Value = (T)(object)42;

How do I make background code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to make background code that checks if someone hit "H","D", or other letters. Like This,(I mean a background code that is checking this.)
if(e.KeyCode == Keys.U)
{
code;
}
In WinForms you can override onKeyDown() like so:
protected override void onKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.YourKey)
{
// Do something
}
}
Where you substitute YourKey with desired key from Keyboard. (You can use intellisense to see all available options)

Count number of clicks on picture box [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
With each click on the picture box the number in the output label must decrement by one.
You need an event handler for the clicking of the image, and an int to keep track of how many times it was clicked; here is some pseudocode to get you started:
int timesClicked = 42;
private void Img_Click(sender object, eventargs e)
{
timesClicked--;
UpdateLabel();
}
internal void UpdateLabel()
{
label.Caption = timesClicked.ToString();
}

Error in edit button "Only assignment, call, increment, decrement, and new object expressions can be used as a statement" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
private void button1_Click(object sender, EventArgs e)
{
string StudentNo = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString();
frmEdit EditForm = new frmEdit();
EditForm.StudentNo;
EditForm.ShowDialog();
}
You probably meant to write
EditForm.StudentNo = StudentNo;
instead of just
EditForm.StudentNo;

C# How to pause program [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have simple question. How do I pause program? I want to change pictures very slowly.
My code:
private void button2_Click(object sender, EventArgs e){
Image picture1 = Program.Properties.Resources.picture1;
Image picture2 = Program.Properties.Resources.picture2;
Button1.Image = picture1
//Here I want pause
Button1.Image = picture2
}
If you want procedural code (like in your example), without timers and without locking the UI:
await Task.Delay(1000)
You can use Threads or Timers.
http://msdn.microsoft.com/en-us/library/swx5easy.aspx
http://programmingbaba.com/how-to-stop-system-threading-timer-in-c-do-net/
Or you can use Sleep method to puase your program.
http://www.dotnetperls.com/sleep

Categories