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 > .NET Framework > Forum > ช่วยหน่อยครับ....ผมเขียนให้โปรแกรม C# วนลูปไม่ได้ครับ...



 

ช่วยหน่อยครับ....ผมเขียนให้โปรแกรม C# วนลูปไม่ได้ครับ...

 



Topic : 072993



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์




Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BluetoothOPPClientDemo
{
    public partial class fmMain : Form
    {
        public fmMain()
        {
            InitializeComponent();
        }

        private void fmMain_Load(object sender, EventArgs e)
        {
            wclAPI.Load();
        }

        private void fmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            wclAPI.Unload();
        }

       

        private void btDiscover_Click(object sender, EventArgs e)
        {

            wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
            if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
            {
                Radios = null;
                return;
            }

            wcl.wclErrors.wclShowError(wclBluetoothDiscovery.Discovery(Radios[0]));
            Radios = null;
        }

        private void wclBluetoothDiscovery_OnDiscoveryStarted(object sender, wcl.wclBluetoothDiscoveryStartedEventArgs e)
        {
            lvDevices.Items.Clear();
           
        }

        private void wclBluetoothDiscovery_OnDiscoveryComplete(object sender, wcl.wclBluetoothDiscoveryCompleteEventArgs e)
        {
            if (e.Devices == null)
                MessageBox.Show("Error discovering");
            else
                if (e.Devices.Count == 0)
                    MessageBox.Show("Nothing found");
                else
                    for (uint i = 0; i < e.Devices.Count; i++)
                    {
                        wcl.wclBluetoothDevice Device = e.Devices[i];
                        ListViewItem Item = lvDevices.Items.Add(Device.Address);
                        string str = "";
                        Device.GetName(e.Radio, ref str);
                        Item.SubItems.Add(str);
                    
                    }
            //__________________________________วนลูปทั้งชุดด้านล่างพร้อมทั้งเพิ่มค่า [ ] ในฟังก์ชัน ขึ้นรอบละหนึ่ง lvDevices.Items[0].Text; จนครบจำนวน Items ใน  lvDevices
            
                if (lvDevices.Items.Count == 0)
                    MessageBox.Show("Select device");
                else
                {
                    wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
                    if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
                    {
                        Radios = null;
                        return;
                    }
                    string DeAddress = lvDevices.Items[0].Text; 
                    wclClient.BluetoothParams.Address = DeAddress;
                    wclClient.BluetoothParams.Radio = Radios[0];
                    wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
                    wcl.wclErrors.wclShowError(wclClient.Connect());

                    Radios = null;
                }
        }

        private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
        {

        }

        private void wclClient_OnDisconnect(object sender, EventArgs e)
        {
            
        }

        private void btDisconnect_Click(object sender, EventArgs e)
        {
            wclClient.Disconnect();
        }
              private void btOpenOBEX_Click(object sender, EventArgs e)
        {
      
            wcl.wclErrors.wclShowError(wclClient.OpenOBEXSession());
            if (OpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                System.IO.FileStream Stream = new System.IO.FileStream(OpenFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                String AFile = System.IO.Path.GetFileName(OpenFileDialog.FileName);
                wcl.wclErrors.wclShowError(wclClient.Put(AFile, Stream));
            }
        }

        private void wclClient_OnOBEXConnect(object sender, wcl.wclConnectEventArgs e)
        {

        }

        private void wclClient_OnOBEXDisconnect(object sender, EventArgs e)
        {
    
        }

        private void wclClient_OnOBEXProgress(object sender, wcl.wclOBEXProgressEventArgs e)
        {
            ProgressBar.Maximum = (int)e.Size;
            ProgressBar.Value = (int)e.Position;
        }

        private void wclClient_OnOBEXPutComplete(object sender, wcl.wclConnectEventArgs e)
        {
            ProgressBar.Value = 0;
            if (e.Error == wcl.wclErrors.WCL_E_SUCCESS)
                MessageBox.Show("Put complete with success");
            else
                MessageBox.Show("Put complete with error: " + e.Error.ToString());
            wclClient.Disconnect();
            wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
        }  
    }
}




Tag : .NET, C#, VS 2008 (.NET 3.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-01-31 17:04:14 By : konmuen View : 1218 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Error ตรงไหน และ Error ว่าอะไรครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-31 19:31:43 By : webmaster
 


 

No. 2



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


//วนลูปทั้งชุดด้านล่างและเพิ่มค่า [ ] ในฟังก์ชัน ขึ้นรอบละหนึ่ง lvDevices.Items[0].Text; จนครบจำนวน Items ใน lvDevices

if (lvDevices.Items.Count == 0)
MessageBox.Show("Select device");
else
{
wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
{
Radios = null;
return;
}
string DeAddress = lvDevices.Items[0].Text;
wclClient.BluetoothParams.Address = DeAddress;
wclClient.BluetoothParams.Radio = Radios[0];
wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
wcl.wclErrors.wclShowError(wclClient.Connect());

Radios = null;
}
}

private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
{

}

private void wclClient_OnDisconnect(object sender, EventArgs e)
{

}

private void btDisconnect_Click(object sender, EventArgs e)
{
wclClient.Disconnect();
}
private void btOpenOBEX_Click(object sender, EventArgs e)
{

wcl.wclErrors.wclShowError(wclClient.OpenOBEXSession());
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream Stream = new System.IO.FileStream(OpenFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
String AFile = System.IO.Path.GetFileName(OpenFileDialog.FileName);
wcl.wclErrors.wclShowError(wclClient.Put(AFile, Stream));
}
}

private void wclClient_OnOBEXConnect(object sender, wcl.wclConnectEventArgs e)
{

}

private void wclClient_OnOBEXDisconnect(object sender, EventArgs e)
{

}

private void wclClient_OnOBEXProgress(object sender, wcl.wclOBEXProgressEventArgs e)
{
ProgressBar.Maximum = (int)e.Size;
ProgressBar.Value = (int)e.Position;
}

private void wclClient_OnOBEXPutComplete(object sender, wcl.wclConnectEventArgs e)
{
ProgressBar.Value = 0;
if (e.Error == wcl.wclErrors.WCL_E_SUCCESS)
MessageBox.Show("Put complete with success");
else
MessageBox.Show("Put complete with error: " + e.Error.ToString());
wclClient.Disconnect();
wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
}
}
}

ในส่วนฟังก์ชันด้านล่างนี้จะเป็นการคอนเนคและส่งไฟล์ในหนึ่งครั้ง...แต่ตอนนี้ต้องการเขียนให้คอนเนคและส่งไฟล์ไปจนครบจำนวน Items ที่คนหาเจอแล้วมาแสดงใน lvDevices (ListView) และในแต่ละรอบที่ทำจะต้องให้ค่าใน [ ] ที่ฟังชัน lvDevices.Items[0].Text เพิ่มขึ้นจาก 0,1,2,3,ไปจนครบเท่ากับจำนวนที่มันมีใน lvDevices (ListView)


ประวัติการแก้ไข
2012-02-01 03:11:33
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-31 22:32:29 By : konmuen
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยครับ....ผมเขียนให้โปรแกรม C# วนลูปไม่ได้ครับ...
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
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 อัตราราคา คลิกที่นี่