How do I make background code? [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 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)

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;

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();
}

How can i do this in C#? [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 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
}

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

Infinite Longlistselector [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 want to implement infinite scroll to a webclient uri download. But i can not find a working example for longlist selector.
Currently my longlistselector lists limited number of results, if i can implement php pages to query how can i do this in windows phone?
Take a look at this sample from Microsoft. It is a twitter example that has infinite scrolling.
In the sample, they listen to the ItemRealized event to load more items from the viewmodel. The viewmodel then adds items to the end of an observable collection.
void resultListBox_ItemRealized(object sender, ItemRealizationEventArgs e)
{
if (!_viewModel.IsLoading && resultListBox.ItemsSource != null &&
resultListBox.ItemsSource.Count
= _offsetKnob)
{
if (e.ItemKind == LongListSelectorItemKind.Item)
{
if ((e.Container.Content as
TwitterSearchResult).Equals(resultListBox.
ItemsSource[resultListBox.ItemsSource.Count - _offsetKnob]))
{
Debug.WriteLine("Searching for {0}", _pageNumber);
_viewModel.LoadPage(_searchTerm, _pageNumber++);
}
}
}
}

Categories