Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > [iOS/iPhone] Tutorials - สอนเขียน iPhone App ฟรี เขียน iPad App เรียน iPhone เขียนโปรแกรม iPhone > ตอนที่ 6 : การสร้าง Event Handler และ UIAlertView ของ Xamarin.iOS บน Visual Studio C#



Clound SSD Virtual Server

ตอนที่ 6 : การสร้าง Event Handler และ UIAlertView ของ Xamarin.iOS บน Visual Studio C#

ตอนที่ 6 : การสร้าง Event Handler และ UIAlertView ของ Xamarin.iOS บน Visual Studio C# ในการสร้าง Event บน Xamarin.iOS ด้วย Visual Studio นั้นจะมีรูปแบบการเขียนเหมือนกับการเขียน .NET Application ประเภท Windows Form Application คือ ขั้นแรกจะต้องสร้าง Control ที่ต้องการ จากนั้นค่อยกำหนด Event ให้กับ Control นั้น ๆ ว่าจะมีเหตุการณ์หรือ Event เมื่อคลิกหรือว่ากระทำกับ Control นั้น ๆ แล้วเมื่อเกิดเหตุการณ์นั้นแล้ว เราจะใช้ Method ที่อยู่ใน Class เป็นตัว Handle เพื่อที่จะเขียนคำสั่งให้โปรแกรมทำงานใน Method นั้น ๆ แสดงคำสั่งและทำงานตามต้องการ

Xamarin.iOS  C# Event Handler UIAlertView

Xamarin.iOS UIAlertView and Event Handler


และสำหรับการโต้ตอบพื้นฐานเราจะใช้ Class ของ UIAlertView ซึ่ง Class นี้สามารถแสดง Alert Dialog แบบง่าย ๆ หรือจะ Apply ใช้กับ Confirm Dialog , Custom Dialog หรือจะเป็น Input Dialog ก็สามารถใช้ UIAlertView ได้เช่นเดียวกัน

รูปแบบการใช้งาน Xamarin.iOS กับ UIAlertView ซึ่งเป็น Class สำหรับจัดการกับ Alert Dialog

Alert Syntax
UIAlertView alert = new UIAlertView ("Title", "The message", null, "OK", null);
alert.Show();
Xamarin.iOS  C# Event Handler UIAlertView


Alert Confirm Syntax
var alert = new UIAlertView ("Alert Title", "Choose from two buttons", null, "OK", new string[] {"Cancel"});
alert.Clicked += (s, b) => {
    label1.Text = "Button " + b.ButtonIndex.ToString () + " clicked";
    Console.WriteLine ("Button " + b.ButtonIndex.ToString () + " clicked");
};
alert.Show();
Xamarin.iOS  C# Event Handler UIAlertView


Alert Button Custom Syntax
var alert = new UIAlertView {
  Title = "custom buttons alert", 
  Message = "this alert has custom buttons"
};
alert.AddButton("OK");
alert.AddButton("custom button 1");
alert.AddButton("Cancel");
// last button added is the 'cancel' button (index of '2')
alert.Clicked += delegate(object a, UIButtonEventArgs b) {
    Console.WriteLine ("Button " + b.ButtonIndex.ToString () + " clicked"); };
alert.Show ();
Xamarin.iOS  C# Event Handler UIAlertView








กลับมายัง Xamarin.iOS บน Visual Studio

Xamarin.iOS  C# Event Handler UIAlertView

สร้างหน้าจอ UI ประกอบด้วย Textbox , Label และ Button ดังรูป และสร้าง ID ตามรูปภาพ

Xamarin.iOS  C# Event Handler UIAlertView

เราจะสร้าง Event ของ Button สามารถคลิกที่ Button เลือก Properties -> Event สามารถเลือก Event ต่าง ๆ ได้ตามต้องการ ส่วน Event ของ Button สามารถดับเบิ้ลคลิกที่ Button เพื่อสร้าง Event ได้เช่นเดียวกัน

Xamarin.iOS  C# Event Handler UIAlertView

Event ที่ถูกสร้างจะอยู่ในส่วนของ Class ที่เป็น .cs ที่ถูกภูกไว้กับ View

Xamarin.iOS  C# Event Handler UIAlertView

เมื่อกลับมาดูที่ Properties จะเห็นว่า Event ถูกสร้าง Relation ไว้กับ Method บน Class ของ .cs

Xamarin.iOS  C# Event Handler UIAlertView

เพิ่ม Event โต้ตอบแบบง่าย ๆ

        partial void btnSubmit_TouchUpInside(UIButton sender)
        {
            UIAlertView alert = new UIAlertView("Hello", "Sawatdee Khun : "+ this.txtName.Text, null, "OK", null);
            alert.Show();
        }









ทดสอบการทำงาน

Xamarin.iOS  C# Event Handler UIAlertView

รันโปรแกรมบน iOS Simulator

Xamarin.iOS  C# Event Handler UIAlertView

ทดสอบการ Input ข้อมูล และคลิกที่ปุ่ม Submit

Xamarin.iOS  C# Event Handler UIAlertView

แสดง Event และ Alert Dialog โต้ตอบ

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2014-10-22 21:36:49 / 2017-03-26 08:39:26
  Download : No files
 Sponsored Links / Related

 
ตอนที่ 1 : รู้จัก Xamarin สำหรับ iOS ติดตั้ง Xamarin เขียน iOS Apps ด้วย C# (.Net Framework)
Rating :

 
ตอนที่ 2 : รู้จัก Xamarin Studio IDE บน Mac OS การเขียน iOS บน Xamarin ด้วยภาษา C#
Rating :

 
ตอนที่ 3 : Mac Build Host เตรียมความพร้อม iOS Simulator สำหรับ Visual Studio (C#)
Rating :

 
ตอนที่ 4 : พื้นฐาน Xamarin.iOS บน Visual Studio การสร้าง Run/Project ของ iOS ด้วย C#
Rating :

 
ตอนที่ 5 : โครงสร้าง Xamarin.iOS บน Visual Studio สร้าง View การเชื่อมโยง View ด้วย C#
Rating :

 
ตอนที่ 7 : Xamarin.iOS กับ Visual Studio สร้าง Action Segue ส่งค่า Parameters ข้าม View (C#)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่