Back to the beginning of the code with several events? [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'm a beginner in C# and I make a quiz. My problem it is that when a question is asked that should make a loop so that the second question can be asked. I had the idea to use goto or return to turn over to the beginning but I have several events of clicks.
Here is an example:
private void Event1
{
//do something..
}
private void Event2
{
//do other things
}
private void Event3
{
//Here I want to return to the event 1 to make a loop
}
Is that possible?
If no are there other solutions?

I assumed that you want to bulid 3 question in series, enable the next options when current question is answered correctly.
If I'm right, first of all you should enable the first button only.
When first event raised and the answer was right , disable first button, then enable next one,so on until all questions were finished.

Related

if statement not executing in c# unity [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 2 years ago.
Improve this question
I am trying to make a character move a certain distance then change direction when they travel a certain distance... the logic here in my code might be wrong I still have to work on that that's not the issue, the problem is my if statement doesn't execute
public class EnemyControl : MonoBehaviour
{
private int xMoveDirection=-1;
private float x;
void Start()
{
x=gameObject.transform.position.x;
}
void Update()
{
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(xMoveDirection,0);
if(x==0.00){
Debug.Log("helloimhere");
xMoveDirection=0;
x=x+1;
}
Any direct comparisons against floating point values will most likely fail, you're better off defining a range of values that are "close enough", for example Math.Abs(x) < 0.0001.

c# winforms how to make foreach that calls every form (literally foreach(Form) ) [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 5 years ago.
Improve this question
I want to call every form that exist in the Program/Project,
As i say in the title literally
foreach(Form){
//do somting
}
You can iterate all open forms owned by your application like this:
foreach (Form form in Application.OpenForms){
//do your thing
}
Note: this will only iterate the forms that have instances created.

Adding text to a TextBlock, one character at a time [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 6 years ago.
Improve this question
I'm posting this so that the code is available to whomever finds it helpful.
Slightly reduced code based on Noctis's suggestion.
StringBuilder DescriptionText = new StringBuilder();
async void RunDescription(StringBuilder description)
{
DescriptionText = description;
await Task.Delay(1000); // Short delay before the text starts printing so the window has time to load
new Thread(AddTextToTextBlock).Start();
}
void TextBlockDispatcher(string text)
{
TextBlock1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => TextBlock1.Inlines.Add(text)));
}
void AddTextToTextBlock()
{
foreach (char c in DescriptionText.ToString())
{
Thread.Sleep(30);
TextBlockDispatcher(c.ToString());
}
}
Sounds like the usual hoops you need to jump through. The only thing i might consider changing is instead of calling the dispatcher, and then checking if it has access, simply calling it directly on your object.
It should look kinda like :
TextBlock1.Dispatcher.BeginInvoke((Action)(() => /* logic here */ )
Saves you an call, but same same really.
You'll need to massage it in, since this is from the top of my head, but it should point you in the right direction.

Simulate keyboard typing without using SendKeys [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 have a random text, which can include special (for sendkeys) symbols like ), ( etc (obvious book, for example). Screening unsuitable too, becouse string send through the internet, so the size of string important. Can you suggest some decision?
Try this and see if your problems go away:
public void TypeCustomMessage(string message)
{
SendKeys.SendWait(Regex.Replace(message, #"(\+|\^|%|~|\(|\)|\[|]|\{|})", "{$1}"));
}

Checking Variable before allowing click [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
How do I have it check my variable before allowing a click.
Example :
_StartControl.Click += new EventHandler(StartControl_Click);
I only want them to be able to do that if my variable "isValid" is equal to 1.
I'm not very good at forms.. Have always learned just console apps.
You can check the value of your isValid field inside StartControl_Click method. If the value is 1, you can allow the method to proceed, if it's not 1, you can simply return from the method before anything gets executed.
You can do it like this.
if(isValid==1)
_StartControl.Click += new EventHandler(StartControl_Click);

Categories

Resources