Creating Controls Dynamically in C#

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
For(int i = 1; i
Nov 2005 MSc Slide 1 - Another Example of a Structural Pattern Alternative way of adding Functionality to an existing class (alternative to a derived class)
5.04 Apply Decision Making Structures
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
GUI-Labels, TextBoxes and Buttons Label- displays read-only text Common properties:  Font – font used by the text of label  Text – text to appear on.
Expression ISYS 350. Performing Calculations Basic calculations such as arithmetic calculation can be performed by math operators OperatorName of the.
Object Oriented Programming Graphical User Interfaces Dr. Mike Spann
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
ASP Hello, world. ServerClient Response Request A form.
Lecture 4 Advanced Topics Devi, Erick, Reddy. » Declare dynamic component, an example: ˃Create a button Button newBtn = new Button(); ˃Create an array.
CSC 298 Windows Forms.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
Basic WPF Controls Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
.NET 2.0 and Visual Studio 2005 SigWin Outline Language enhancements in C# Language enhancements in C# –Generics –Partial types –Anonymous methods.
Lecture 16: Multithreaded Programming. public partial class Form1 : Form { Thread ct; Thread rt; public static int circle_sleep = 0; public static int.
Rules Two Teams Questions worth 1-3 points – Entire team can confer to answer the question – Max of 2 minutes per question – You can use a computer on.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
C# - FCL/Form & Control Validation John Kelleher.
COMPUTER PROGRAMMING I 3.02 Apply Properties Associated with the Controls.
Controls Part 2. DateTimePicker Control Used for representing Date/Time information and take it as input from user. Date information is automatically.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.
2e – RadioButtons Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);
Lecture 14: File I/O Common Dialogs Toolbox Widgets.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
Objects and Classes Engineering 1D04, Teaching Session 9.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
Radio Buttons. Input/Form/Radio Group Use the dialog to enter label and values for the radio buttons.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
1 Windows Forms II Chapter RadioButton / GroupBox Controls Used to solicit a multiple choice input. Radio buttons work as a group. Selecting one.
1 Working with Controls at Run Time. 2 Objectives You will be able to Add controls to a Windows form at run time. Modify controls at run time.
Programming with Visual Basic.NET. Quick Links Program Code The Code Window The Event Procedure Assignment Statements Using AutoList Radio Buttons Buttons.
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
Array, ArrayList and List ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items.
Timed Math Quiz. In This Part, You Learn How to Generate random numbers by using the Random class. Trigger events to occur at a specific time by using.
Visual Basic.NET Windows Programming
Chapter 9 Programming Based on Events
Expression ISYS 350.
Computing with C# and the .NET Framework
CHAPTER FIVE Decision Structures.
Reference: COS240 Syllabus
Expression ISYS 350.
CHAPTER FIVE Decision Structures.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Conditional Loops.
المحاضرة السادسة.
searching Concept: Linear search Binary search
Expression ISYS 350.
Expression ISYS 350.
Patterns to KNOW.
Control Structures Part C – Groups of Controls
Expression ISYS 350.
Expression ISYS 350.
BMI Form1 Body Mass Index textBox3-4 (readonly) trackBar1
5/6/2019 Session 8.2 Postback, ViewState
Chapter 13: Handling Events
AB form1 Multiplication textBox1 12 textBox2 34 textBox3
Group Boxes, Radio buttons and Checked List Boxes
CHAPTER FOUR VARIABLES AND CONSTANTS
Events, Delegates, and Lambdas
Poker2.jpg Poker14.jpg int num1, num2;
form1 Runner pictureBox1 imageList1 timer1 label1 原地跑步計時 label2 共用了…秒
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Creating Controls Dynamically in C#

Dynamically Generated Controls the user selects the number of radio buttons to generate and then presses the Build Itt button

The Complete Source Code private void btnBuildIt_Click(object sender, EventArgs e) { int hsep = 40; int num = (int)numUDCount.Value; if (numUDCount.Value > 0) Form1.ActiveForm.Height = 115 + num * hsep; GroupBox gBox = new GroupBox(); gBox.Text = "Demo Group"; gBox.Size = new Size(200, 20 + num * hsep); gBox.Location = new Point(20, 20); this.Controls.Add(gBox); for (int i = 0; i < num; i++) rb.Add(new RadioButton()); rb[i].AutoSize = true; rb[i].Location = new Point(15, 20 + hsep * i); rb[i].Name = "radioButton" + Convert.ToString(i); rb[i].Text = "This is Radio Button " + Convert.ToString(i); gBox.Controls.Add(rb[i]); } btnBuildIt.Enabled = false;

num is the number of Radio Buttons to be created private void btnBuildIt_Click(object sender, EventArgs e) { int hsep = 40; int num = (int)numUDCount.Value; if (numUDCount.Value > 0) Form1.ActiveForm.Height = 115 + num * hsep; GroupBox gBox = new GroupBox(); gBox.Text = "Demo Group"; gBox.Size = new Size(200, 20 + num * hsep); gBox.Location = new Point(20, 20); this.Controls.Add(gBox); for (int i = 0; i < num; i++) rb.Add(new RadioButton()); rb[i].AutoSize = true; rb[i].Location = new Point(15, 20 + hsep * i); rb[i].Name = "radioButton" + Convert.ToString(i); rb[i].Text = "This is Radio Button " + Convert.ToString(i); gBox.Controls.Add(rb[i]); } btnBuildIt.Enabled = false; hsep will be used to set the separation in height between the radio buttons num is the number of Radio Buttons to be created

Form1 is resized to hold the new controls private void btnBuildIt_Click(object sender, EventArgs e) { int hsep = 40; int num = (int)numUDCount.Value; if (numUDCount.Value > 0) Form1.ActiveForm.Height = 115 + num * hsep; GroupBox gBox = new GroupBox(); gBox.Text = "Demo Group"; gBox.Size = new Size(200, 20 + num * hsep); gBox.Location = new Point(20, 20); this.Controls.Add(gBox); for (int i = 0; i < num; i++) rb.Add(new RadioButton()); rb[i].AutoSize = true; rb[i].Location = new Point(15, 20 + hsep * i); rb[i].Name = "radioButton" + Convert.ToString(i); rb[i].Text = "This is Radio Button " + Convert.ToString(i); gBox.Controls.Add(rb[i]); } btnBuildIt.Enabled = false; Form1 is resized to hold the new controls a GroupBox is created to hold the Radio Buttons gBox is resized to hold i Radio Buttons gBox is located on the main Form gBox is added the to this Form's set of Controls

this loop will create num Radio Buttons rb[i] private void btnBuildIt_Click(object sender, EventArgs e) { int hsep = 40; int num = (int)numUDCount.Value; if (numUDCount.Value > 0) Form1.ActiveForm.Height = 115 + num * hsep; GroupBox gBox = new GroupBox(); gBox.Text = "Demo Group"; gBox.Size = new Size(200, 20 + num * hsep); gBox.Location = new Point(20, 20); this.Controls.Add(gBox); for (int i = 0; i < num; i++) rb.Add(new RadioButton()); rb[i].AutoSize = true; rb[i].Location = new Point(15, 20 + hsep * i); rb[i].Name = "radioButton" + Convert.ToString(i); rb[i].Text = "This is Radio Button " + Convert.ToString(i); gBox.Controls.Add(rb[i]); } btnBuildIt.Enabled = false; this loop will create num Radio Buttons rb[i] Radio Buttons are separated by hsep in height Radio Button rb[i] is added to gBox.Controls