简体   繁体   English

使用 C# 如何使用表单设置变量?

[英]using C# how do i set variables using a Form?

            string Athlete_Year = "2019-20"; // 2019-20, ALL, 2018-20
            string Athlete_Division = "I"; // I , II, III
            string Athlete_Sport = "Women's Cross Country"; // "Men's Cross Country" , "Men's Track, Indoor" , "Men's Track, Outdoor" , "Women's Cross Country" , "Women's Track, Indoor" , "Women's Track, Outdoor"
            string Number_Of_Results = "500 rows";  // 10, 25, 50, 500
            string Athlete_Name = "Ashley Smith";
           //--------------------------------------------------------------------------------------------------
               private void BtnDivision1_Click(object sender, EventArgs e)
                 {
                          LblDivision.Text = "I";
                 }
//set for a button, i don't know how to use drop down options

I have a set of variables that work in my program.我有一组在我的程序中起作用的变量。 if i want to change the variables for example "Number_Of_Results" i need to manually do it within the code.如果我想更改变量,例如“Number_Of_Results”,我需要在代码中手动进行。 im now learning how to use a form interface and was wondering how do i set one of these variables to one of the other options based on the form selections?我现在正在学习如何使用表单界面,并且想知道如何根据表单选择将这些变量之一设置为其他选项之一?

sorry I'm new to this.对不起,我是新手。

For example i made a drop down box where you can select 10, 25, 50, and 500例如,我制作了一个下拉框,您可以在其中 select 10、25、50 和 500

once one of the options are selected how do i make the variable change to the selected amount.一旦选择了其中一个选项,我如何将变量更改为所选数量。

BONUS: from there how do i make a Start button to run the code.奖励:从那里我如何制作一个开始按钮来运行代码。 i originally made the code for this program to run in a console app.我最初使该程序的代码在控制台应用程序中运行。 is there a way to copy paste the source code from the console base one and embed it into a Start button?有没有办法从控制台基础复制粘贴源代码并将其嵌入到“开始”按钮中?

You can perform these tasks from Events.您可以从事件中执行这些任务。 Check out this site for more information on Events.查看此站点以获取有关活动的更多信息。

https://www.tutorialsteacher.com/csharp/csharp-event https://www.tutorialsteacher.com/csharp/csharp-event

Coming back to your questions, For Combo box use the following event.回到您的问题,对于组合框,请使用以下事件。

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.listcontrol.selectedvaluechanged?view=netcore-3.1 . https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.listcontrol.1selectedvaluechanged?view=netcore-3

You can subscribe to the SelectedValueChanged and SelectedIndexChanged events and change the variable values in the Event handler.您可以订阅 SelectedValueChanged 和 SelectedIndexChanged 事件并更改事件处理程序中的变量值。

For start button click, use the following event.对于开始按钮单击,请使用以下事件。

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.click?view=netcore-3.1 https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.click?view=netcore-3.1

Use the button.click event on the start button to run your start code.使用开始按钮上的 button.click 事件来运行您的开始代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM