Starting form to appear before the next form - c#

1I'm making a lottery simulator and I want a new form at the beginning that asks if your are 16 or older before you are taken to the main form. I'm using visual studio 2015 and coding in c#. Can someone tell me how to do this?

If you double click the form that currently shows up first to get the form load method, then place your form you want to show up first within the method, it should display when the main form loads up and hide the first one. Just make it so No exits the environment.
private void Lottery_Sim_Load(object sender, EventArgs e)
{
AgeVerificationForm.ShowDialog();
}

Related

How do I use data from a combo box in another form c#

I'm writing a program in c# (visual studio, windows forms) which involves the user selecting a name from a combo box, and then clicking a button which brings them to a quiz on another form. I want a text file to be created at the end of the quiz showing the name selected and the quiz results, followed by a "~" symbol.
I honestly don't know where to start. I'm using stream reader.
This is the code I used for the combo box and the button that sends you to the next form
private void quizSelectPupilCB_SelectedIndexChanged(object sender, EventArgs e)
{
selectedClass = quizSelectPupilCB.SelectedItem.ToString();
}
private void quizStartBTN_Click(object sender, EventArgs e)
{
Quiz2 formQuiz2 = new Quiz2();
formQuiz2.Show();
this.Hide();
}
How do I use this data on another form?
I don't even know where to start. I tried looking up things like "how to access data from one form and put it in another c#" and similar things but everything I found was either not what I was looking for, or worded in a really confusing way.
As a variant you can save selectedItem to String/StringCollection, then to app settings(Settings.Default). And on another form get this value back.

Preloading a form in WPF c#

I am currently trying to make a Loading form which should stay on screen for 7 seconds before switching to the main form
I cant just simply load the main form directly after the loading bar is full because the Main form takes about 7 seconds to start
Is there i way to "pre load" the main form, but hiding it until the loading form is done?
This is the code for the loading form, simplyfied
private void FormLoading_Load(object sender, EventArgs e)
{
tick.Start();
}
private void tick_Tick(object sender, EventArgs e)
{
loadingbar.Increment(1);
if (loadingbar.Value == 700)
{
this.Close();
}
}
I would add a Splashscreen - this way you do not need to use a timer for waiting until the form is loaded. You simply display the splash screen at startup and close it inside the MainWindows Constructor.
You can add a splash screen by Visual Studio -> Right click your project -> Add new item -> Wpf -> Splashscreen.
If you really want that the form does display there for 7 seconds you can use Thread.Sleep before closing the Splashscreen.

c# code to create a new windows form every click of button

I need help on creating a new form when I click a button.
For example, I have a form named create_form then has a button named Create. What I want is to create a form every time I click the Create button, and the forms created will be independent from each other.
I don't want to create a lot of form in Visual Studio like "Form1, Form2, Form3, Form4..etc.." and call each one every time the button is clicked. Then I'd have to be able to create another form in Visual Studio for each time I wanted to click the button, even if I click it 20 times or more. All I want is to create one windows form (Form3 for example) then every time I click the Create button it will just call it and create a new instance of that form. If I click 20 times then there should be 20 forms created and independent from each other.
Assuming you already have a form named Form3, here is what your button click event will look like:
//use this so you have an easy reference to each of your forms
private myForms As new List<Form3>();
protected void Create_Click(object sender, EventArgs e)
{
var form = new Form3();
myForms.Add(form);
form.Show();
}

Call a new form from current form in c#

I want to create a program which have the same theme and looks like new forms are loading inside the current form from c#. I can do this by using panels but I do not wish to do so since if I had to do a modification it becomes a cumbersome.Instead of using panels I used forms. when i click a button in a form same style form with different values will appear on the current form. But it's looking so untidy and when i want to close the program I have to close every form. Since my final program will contain more than 15 guis it is not a practicle solution .so tried by using following code snippet.
private void ord_Click(object sender, EventArgs e)
{
this.Close();
order frm =new order();
frm.Show();
}
From this code I suppose to close the current form and display the next form. But this code didn't work .It closed both forms.
I can use this.hide() method instead of this.close .but its only hide the current form.When I want to close the Program I have to close each and every form.
I don't wish to use MDI forms. Because it is not suit for my theme. you can get idea about my theme by looking at following image.
GUI of the system
And I want to design a professional looking GUI. I also like to have comments about my GUI. Is it looking professional?
try this
private void ord_Click(object sender, EventArgs e)
{
order frm =new order();
frm.Show();
this.Hide();
}
if its still not working ?
then probably you are using forms in parent child fashion if you close the form which is running at the very start all the forms will be closed, Solution: you should hide child form using .Hide() and for the next form to open declare the parent form as mdi parent of child form hope you understand...

How do I add a Form Load event using the form designer in C# 2015? (like double clicking)?

I am new to C# in Visual Studio 2015. I just realized that the old classical way of adding event handlers by double-clicking on the item no longer works for some items like the form (or the Window).
After some Google searches I still can't figure out a way to add the Load event of the form using the designer.
Do I have to manually write code for that unlike in Visual Basic in Visual Studio 2005?
You can set the Load event of a Control from its properties window here. You create the
private void Form1_Load(object sender, EventArgs e)
{
// my code
}
event in your form class, and fill in its name (Form1_Load) where the arrow points in the picture.
Doing it manually would be something like:
Form1.Load += new System.EventHandler(this.Form1_Load);
considering that you created the Form1_Load event.
But on top of all that, double clicking should work.
You may have an issue with your instillation. However, select the form and go to the actions window and select load. This should give the desired result

Categories

Resources