Windows form programming. namespace MyNamespace { public class MyForm : System.Windows.Forms.Form { public MyForm() { this.Text = "Hello Form"; }

Slides:



Advertisements
Similar presentations
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 11 MORE WINDOWS CONTROLS & STANDARD DIALOG BOXES.
Microsoft Visual C#.NET: From Problem Analysis to Program Design1 Chapter 9 Programming Based on Events Microsoft Visual C#.NET: From Problem Analysis.
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
.NET Class 4 – Windows-based Application. WinForm Application Homogeny programming model. Rich class library Classes are shared by all.NET languages.
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
Advanced Object-Oriented Programming Features
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
C# Programming: From Problem Analysis to Program Design1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 3.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 19 Microsoft’s Approach 1 –.NET Mobile Framework part 2 Rob.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Printer & Dialog boxes Engr. Faisal ur Rehman CE-105T Spring 2007.
BIL528 – Bilgisayar Programlama II Introduction 1.
1 Graphical User Interfaces Part 2 Outline Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
ADO.NET By Hanumantha Rao.N MCA By Hanumantha Rao.N MCA.
Dr Dat Tran - Week 4 Lecture Notes 1 MenuStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
Object Oriented Programming Graphical User Interfaces Dr. Mike Spann
Lecture 8 Building an MDI Application. Introduction The MDI (Multiple Document Interface) provides a way to display multiple (child) windows forms inside.
CSC 298 Windows Forms.
Session 08: Architecture Controllers or Managers Graphical User Interface (GUI) FEN AK - IT Softwarekonstruktion.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New.
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling.
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
Visual C# 2012 How to Program 1. 2  A graphical user interface (GUI) allows a user to interact visually with a program.  Figure 14.1 shows a Visual.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
BIL528 – Bilgisayar Programlama II Introduction 1.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Introduction to Windows Programming
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
1 Chapter Nine Using GUI Objects and the Visual Studio IDE.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Lecture 6: Advanced GUI Controls. Up to now we have used simple controls such as buttons and textboxes. Now we will review some interactive (e.g. dialog)
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Developing Windows Applications with Visual Studio Windows Forms Controls and Coding Jim Warren – COMPSCI 280 S Enterprise.
1 Graphic Device Interface (GDI). 2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create.
Dr Dat Tran - Week 2 Lecture Notes 1 Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences & Engineering.
Copyright © 2012 Pearson Education, Inc. Chapter 5 Loops, File, and Random Numbers.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
Introduction to Windows Forms Application By N Hanumantha Rao MCA By N Hanumantha Rao MCA.
Lecture 14: File I/O Common Dialogs Toolbox Widgets.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
1 Printing a Document. 2 Objectives You will be able to print a real multipage document.
BIL528 – Bilgisayar Programlama II Methods 1. Contents Methods 2.
Graphical User Interface Components Version 1.1. Obectives Students should understand how to use these basic Form components to create a Graphical User.
DataGridView. Displaying data in a tabular format is a task you are likely to perform frequently. The DataGridView control is designed to be a complete.
Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.
1 Windows Forms II Chapter RadioButton / GroupBox Controls Used to solicit a multiple choice input. Radio buttons work as a group. Selecting one.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
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.
Module 3: Creating Windows-based Applications. Overview Creating the Main Menu Creating and Using Common Dialog Boxes Creating and Using Custom Dialog.
UNIT 1 Lesson 1 Introduction.
Computing with C# and the .NET Framework
C# & Windows GUI Applications
Object Oriented Programming
Reference: COS240 Syllabus
Picture Viewer.
How to Add Images Using an 'openFile' Dialog
Programming Based on Events
MDI Picture Viewer Application
Copyright © 2006 Thomas P. Skinner
Self Study GUI Properties & Events
Module 8: Creating Windows-based Applications
Based on Murach Chapter 10
Chapter 14 Graphical User Interfaces with Windows Forms: Part 1
How to organize and document your classes
Poker2.jpg Poker14.jpg int num1, num2;
Presentation transcript:

Windows form programming

namespace MyNamespace { public class MyForm : System.Windows.Forms.Form { public MyForm() { this.Text = "Hello Form"; } public static void Main() { System.Windows.Forms.Application.Run(new MyForm()); }

we define a class called MyForm that inherits from the Form class, which is found in the System.Windows.Forms namespace. The period notation is used to separate namespaces and classes, so that the complete, or fully qualified, name for the class is System.Windows.Forms.Form. namespace MyNamespace { public class MyForm : System.Windows.Forms.Form {... } The Form class is the cornerstone of Windows-based applications in.NET. It represents any type of window in an application, from dialog boxes to MDI (Multiple Document Interface) client windows. The Form class provides the ability to display, place controls within, and interact with an application window.

Constructors and methods Take another look at the declaration of our MyForm class. Note how two members of this class are defined, namely the MyForm constructor and the Main method. Both members are declared as public, as is the class MyForm. public class MyForm : System.Windows.Forms.Form { public MyForm() // constructor { this.Text = "Hello Form"; } public static void Main() { System.Windows.Forms.Application.Run(new MyForm()); }

Adding controls Let’s make our program a little more interesting by adding some controls. Throughout the course of the book, we will be building a photo viewing application, so let’s add a button for loading an image file, and a box where the image can be displayed. When we are done, our form will look like figure

namespace MyNamespace { using System; using System.Windows.Forms; public class MyForm : Form { private Button btnLoad; private PictureBox pboxPhoto; public MyForm() { this.Text = "Hello Form 1.2"; // Create and configure the Button btnLoad = new Button(); btnLoad.Text = "&Load"; btnLoad.Left = 10; btnLoad.Top = 10; // Create and configure the PictureBox pboxPhoto = new PictureBox(); pboxPhoto.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; pboxPhoto.Width = this.Width / 2; pboxPhoto.Height = this.Height / 2; pboxPhoto.Left = (this.Width - pboxPhoto.Width) / 2; pboxPhoto.Top = (this.Height - pboxPhoto.Height) / 2;

// Add our new controls to the Form this.Controls.Add(btnLoad); this.Controls.Add(pboxPhoto); } public static void Main() { Application.Run(new MyForm()); }

namespace MyNamespace { using System; using System.Drawing; using System.Windows.Forms; public class MyForm : System.Windows.Forms.Form { Button btnLoad; PictureBox pboxPhoto; public MyForm() { this.Text = "Hello Form 1.3"; // Create and configure the Button btnLoad = new Button(); btnLoad.Text = "&Load"; btnLoad.Left = 10; btnLoad.Top = 10; btnLoad.Click += new System.EventHandler(this.OnLoadClick); // Create and configure the PictureBox pboxPhoto = new PictureBox(); pboxPhoto.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

pboxPhoto.Width = this.Width / 3; pboxPhoto.Height = this.Height / 3; pboxPhoto.Left = (this.Width - pboxPhoto.Width) / 2; pboxPhoto.Top = (this.Height - pboxPhoto.Height) / 2; pboxPhoto.SizeMode = PictureBoxSizeMode.StretchImage; // Add our new controls to the Form this.Controls.Add(btnLoad); this.Controls.Add(pboxPhoto); } private void OnLoadClick(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open Photo"; dlg.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*" ; if (dlg.ShowDialog() == DialogResult.OK) { pboxPhoto.Image = new Bitmap(dlg.OpenFile()); } dlg.Dispose(); } public static void Main() { Application.Run(new MyForm()); }

event private void OnLoadClick(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open Photo"; dlg.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*" ; if (dlg.ShowDialog() == DialogResult.OK) { pboxPhoto.Image = new Bitmap(dlg.OpenFile()); } dlg.Dispose(); }

private void button1_Click(object sender, EventArgs e) { string msg; msg = " ali \r"; msg = msg + " mehmet \n"; msg=msg+" ahmet "; MessageBox.Show( msg,"ali",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Exclamation); MessageBox.Show("The calculations are complete", "My Application", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk); }

private void vScrollBar1_Scroll(object sender, ScrollEventArgs e) { int f; Single c; f = vScrollBar1.Value; c = ((Single)5 / (Single)9) * ((System.Convert.ToSingle(f) - (Single)32)); textBox1.Text = System.Convert.ToString(f); textBox2.Text = System.Convert.ToString(c); }

if (f < 32) { panel1.BackColor = Color.Blue; } if (f >= 32 && f<60) { panel1.BackColor = Color.Green; } if (f >= 60 && f<80) { panel1.BackColor = Color.Yellow; } if (f >= 80) { panel1.BackColor = Color.Red; }

public partial class Form1 : Form { int a, b; Single c; public Form1() private void radioButton1_CheckedChanged(object sender, EventArgs e) { textBox1.Text = " "; button1.Text = "+"; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { textBox1.Text = " "; button1.Text = "-"; }

private void numericUpDown1_ValueChanged(object sender, EventArgs e) { if (button1.Text == "+") { c = System.Convert.ToSingle(numericUpDown1.Value) + System.Convert.ToSingle(numericUpDown2.Value); textBox1.Text = System.Convert.ToString(c); } if (button1.Text == "-") { c = System.Convert.ToSingle(numericUpDown1.Value) - System.Convert.ToSingle(numericUpDown2.Value); textBox1.Text = System.Convert.ToString(c); }

private void numericUpDown2_ValueChanged(object sender, EventArgs e) { if (button1.Text == "+") { c = System.Convert.ToSingle(numericUpDown1.Value) + System.Convert.ToSingle(numericUpDown2.Value); textBox1.Text = System.Convert.ToString(c); } if (button1.Text == "-") { c = System.Convert.ToSingle(numericUpDown1.Value) - System.Convert.ToSingle(numericUpDown2.Value); textBox1.Text = System.Convert.ToString(c); }

using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Show the color dialog. DialogResult result = colorDialog1.ShowDialog(); // See if user pressed ok. if (result == DialogResult.OK) { // Set form background to the selected color. this.BackColor = colorDialog1.Color; }

using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Show the dialog. DialogResult result = fontDialog1.ShowDialog(); // See if OK was pressed. if (result == DialogResult.OK) { // Get Font. Font font = fontDialog1.Font; // Set TextBox properties. this.textBox1.Text = string.Format("Font: {0}", font.Name); this.textBox1.Font = font; }

private void yeniToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Text = " "; } private void açToolStripMenuItem_Click(object sender, EventArgs e) { if ( openFileDialog1.ShowDialog() == DialogResult.OK) { richTextBox1.LoadFile(openFileDialog1.FileName); } private void kaydetToolStripMenuItem_Click(object sender, EventArgs e) { if ( saveFileDialog1.ShowDialog() == DialogResult.OK) { richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.RichText); }

private void çıkışToolStripMenuItem_Click(object sender, EventArgs e) { Close(); } private void kesToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Cut(); } private void kopyalaToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Copy(); } private void yapıştırToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Paste(); }

private void renkToolStripMenuItem_Click(object sender, EventArgs e) { colorDialog1.ShowDialog(); richTextBox1.ForeColor = colorDialog1.Color; } private void yazıToolStripMenuItem_Click(object sender, EventArgs e) { fontDialog1.ShowDialog(); richTextBox1.Font = fontDialog1.Font; } private void yazıToolStripMenuItem_Click(object sender, EventArgs e) { if (fontDialog1.ShowDialog() == DialogResult.OK) { richTextBox1.Font = fontDialog1.Font; }

private void button1_Click(object sender, EventArgs e) { Graphics cizim; cizim = this.CreateGraphics(); Pen kalem = new Pen(Color.Green, 2); SolidBrush firca=new SolidBrush(Color.Red); if (rbdRec.Checked==true) cizim.DrawRectangle (kalem, Convert.ToInt32(txtXK.Text), Convert.ToInt32(txtYK.Text), Convert.ToInt32(txtG.Text), Convert.ToInt32(txtY.Text)); if (rbdLine.Checked == true) cizim.DrawLine(kalem, Convert.ToInt32(txtXK.Text), Convert.ToInt32(txtYK.Text), Convert.ToInt32(txtG.Text), Convert.ToInt32(txtY.Text)); if (rbddolu.Checked == true) cizim.FillRectangle (firca, Convert.ToInt32(txtXK.Text), Convert.ToInt32(txtYK.Text), Convert.ToInt32(txtG.Text), Convert.ToInt32(txtY.Text)); }

private void button1_Click(object sender, EventArgs e) { monthCalendar1.BackColor = Color.Red; monthCalendar1.ForeColor = Color.Green; textBox1.Text = System.Convert.ToString( monthCalendar1.TodayDate); } private void button2_Click(object sender, EventArgs e) { this.dateTimePicker1.CustomFormat = "HH-mm-ss : MMMM/dd/yyyy tt"; this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom; this.dateTimePicker1.Location = new System.Drawing.Point(200, 200); this.dateTimePicker1.Name = "dateTimePicker"; this.dateTimePicker1.Size = new System.Drawing.Size(240, 20); this.dateTimePicker1.TabIndex = 0; dateTimePicker1.CalendarForeColor = Color.Red; dateTimePicker1.CustomFormat = " MMMM/dddd/yy"; }

private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; if (open.ShowDialog() == DialogResult.OK) { pictureBox1.Image = new Bitmap(open.FileName); }

private void button2_Click(object sender, EventArgs e) { pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; } private void button3_Click(object sender, EventArgs e) { pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; } private void button4_Click(object sender, EventArgs e) { pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; }

private void button1_Click(object sender, EventArgs e) { int aci; double sin_deg,radyan; listBox1.Items.Add(" ---- Açı sinüs değeri---") ; listBox1.Items.Add(" "); for (aci = 0; aci <= 360; aci++) { radyan=System.Convert.ToDouble (aci) * / ; sin_deg = Math.Sin(radyan ); listBox1.Items.Add(" aÇI : " + System.Convert.ToString(aci) + " sinüs değeri: " + System.Convert.ToString(sin_deg)); }

private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (colorDialog1.ShowDialog() == DialogResult.OK) { button1.ForeColor = colorDialog1.Color; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (colorDialog1.ShowDialog() == DialogResult.OK) { button1.BackColor = colorDialog1.Color; }

public partial class Form1 : Form { Single maas, kesinti, emekli, netmaas; public Form1() { InitializeComponent(); } private void radioButton2_CheckedChanged(object sender, EventArgs e) { groupBox2.Enabled = false; hesapla(); } private void radioButton1_CheckedChanged(object sender, EventArgs e) { groupBox2.Enabled = true ; hesapla(); }

string msg1,msg; int a, b; msg = textBox1.Text; b = msg.Length; msg1 = msg.Substring(0, b); for (a = b ; a <= 10; a++) { msg1 = msg1 + "_"; } richTextBox1.Text = msg1; msg = textBox2.Text; b = msg.Length; msg1 = msg.Substring(0, b); for (a = b; a <= 10; a++) { msg1 = msg1 + "_"; } richTextBox1.Text =richTextBox1.Text + msg1; msg = textBox3.Text; b = msg.Length; msg1 = msg.Substring(0, b); for (a = b; a <= 10; a++) { msg1 = msg1 + "_"; } richTextBox1.Text = richTextBox1.Text + msg1;

private void textBox5_TextChanged(object sender, EventArgs e) { maas = System.Convert.ToSingle (textBox5.Text); kesinti = maas * (Single )0.10; emekli = maas * (Single)0.20; netmaas = maas - kesinti - emekli; textBox6.Text = System.Convert.ToString(emekli); textBox7.Text = System.Convert.ToString(kesinti); textBox8.Text = System.Convert.ToString(netmaas); }

private void hesapla() { maas = System.Convert.ToSingle(0); if (radioButton1.Checked) { if (radioButton4.Checked) maas = System.Convert.ToSingle(800); } if (radioButton1.Checked) { if (radioButton3.Checked) maas = System.Convert.ToSingle(700); } if (radioButton2.Checked) { maas = System.Convert.ToSingle(700); } if(numericUpDown1.Value==1) maas = maas + System.Convert.ToSingle(30); if (numericUpDown1.Value > 1) maas = maas + System.Convert.ToSingle(60); textBox5.Text = System.Convert.ToString(maas); }

private void numericUpDown1_ValueChanged(object sender, EventArgs e) { hesapla(); } private void radioButton3_CheckedChanged(object sender, EventArgs e) { hesapla(); } private void radioButton4_CheckedChanged(object sender, EventArgs e) { hesapla(); }