.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

ช่วยทีครับจะเเสดงlist box ในอีกคลาสนึงอ่ะคับ Options · View
pukpik
Posted: Wednesday, February 06, 2008 8:02:32 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/6/2008
Posts: 7

ปัญหาคือผมจะแสดง out put ในคลาสอีกคลาสอ่าครับแต่ผมก็อ้างอิงจาก form 1 แล้วแต่ไม่รู้เปนไรมาน error คับ

ดูทีนะคับ

 

 

public class Connection

{

 

 

 

 

 

 

{

ip = ip1;

frm = frm1;

}

 

{

 

 

 

 

 

string ip;Form1 frm;int port;public Connection(string ip1, int port1, Form1 frm1)public void Connect()MessageBox.Show(ip);IPHostEntry Tempaddr = Dns.GetHostByAddress(ip);MessageBox.Show("show" + Tempaddr);//frm.listBox1.Items.Add(Tempaddr);

 

//MessageBox.Show("gg");

frm.listBox1.Items.Add(Tempaddr +

 

" port "); ตรงนี้อ่าครับใครรู้ช่วยทีครับ//this.frm.listBox2.Refresh();

 

ball
Posted: Thursday, February 07, 2008 3:39:37 AM

Rank: อาจารย์
Groups: Administration

Joined: 12/1/2007
Posts: 473
Location: Bangkok

แปะโค๊ดมาใหม่ครับ



Imagination is more Important than Knowledge... /A.Einstein
pukpik
Posted: Thursday, February 07, 2008 12:51:15 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/6/2008
Posts: 7
public class Connection
{
    string ip;
    Form1 frm;
    int port;
    public Connection(string ip1, int port1, Form1 frm1)
    {
        ip = ip1;
        frm = frm1;
    }
    public void Connect()
    {
        MessageBox.Show(ip);
        IPHostEntry Tempaddr = Dns.GetHostByAddress(ip);
        MessageBox.Show("show" + Tempaddr);
        frm.listBox1.Items.Add(Tempaddr);// ตรงนี้อ่าผมอ้างอิงให้โชว์ในform ของ form 1 อ่าคับแต่มาน error               
        frm.listBox1.Items.Add(Tempaddr + " port ");//คือว่ามจะแสดงขอมูลใน list box ของ form 1 งัยอ่ะคับ
        frm.listBox2.Refresh();

    }
}
ball
Posted: Friday, February 08, 2008 4:28:47 AM

Rank: อาจารย์
Groups: Administration

Joined: 12/1/2007
Posts: 473
Location: Bangkok

คำสั่งนี้กำลังจะถูกยกเลิก (obsolete)

Dns.GetHostByAddress(ip);

ให้ใช้คำสั่งนี้แทน

Dns.GetHostEntry(ip);

ผมขอแก้โค๊ดคลาส Connection เป็น

public class Connection
{
    string ip;
    Form1 frm;
    int port;
    public Connection(string ip, int port, Form1 frm)
    {
        this.ip = ip;
        this.port = port;
        this.frm = frm;
    }
    public void Connect()
    {           
        IPHostEntry Tempaddr = Dns.GetHostEntry(ip);           
        frm.listBox1.Items.Add(Tempaddr.HostName + " port " + port);
    }
}

คุณจะต้องไปกำหนด Modifiers Properties ของ listBox1 ให้เป็น Public ก่อน

และเข๊ยนโค๊ดที่ Form1 เพื่อเรียกใช้งาน Class Connection ตัวอย่างดังนี้

private void button1_Click(object sender, EventArgs e)
{
    Connection c = new Connection("192.168.1.93", 80, this);
    c.Connect();
}


Imagination is more Important than Knowledge... /A.Einstein
pukpik
Posted: Friday, February 08, 2008 11:47:35 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/6/2008
Posts: 7

 คือว่ามานขึ้น error  หยังงี้อ่าครับผมปรับ Modifiers Properties ของ listBox1 ให้เป็น Public แล้วอ่าครับมันก็ขึ้นแบบนี้อ่าครับ

code Dns.GetHostEntry(ip);

ผมลองใส่แล้วมานไม่ได้อ่าครับผมก็งง

ช่วยทีนะครับ

 

 

 

 

pukpik
Posted: Friday, February 08, 2008 11:56:36 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/6/2008
Posts: 7

คือผมรู้สึกดีจัยมากนะคับที่ผมถามพี่ไปแล้วพี่ตอบเร็วมากเพราะผมมะค่อยเจอแบบนี้อ่าครับ

เเล้วผมเพิ่งเปงสมาชิกด้วยอ่าคับ

ขอบคุงพี่ๆมากนะครับ

ball
Posted: Saturday, February 09, 2008 2:18:35 AM

Rank: อาจารย์
Groups: Administration

Joined: 12/1/2007
Posts: 473
Location: Bangkok

ผมว่า Zip โปรเจ็คมาแล้วโพสมาเลยครับ

ป.ล.ถ้าเก่งแล้วก็มาช่วยผมด้วยนะ มาช่วยกันสร้างสังคมนี้ให้ทุกคนเก่งๆขึ้น



Imagination is more Important than Knowledge... /A.Einstein
pukpik
Posted: Saturday, February 09, 2008 2:39:45 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/6/2008
Posts: 7

file/file/TestQickscan.rar

นี่อ่าครับ

คือที่จิงผมทำโปรเจคสแกนตรวจสอบระบบเครือข่ายโดยมีการสแกนไอพี,พอร์ต,แมค,โฮส,แชร์ไฟล์,os

ที่ทำคือได้หมดแล้วเเต่มันยังทำงานช้าคือผมคิดว่าน่าจะเป็นที่ function ของผมอ่าครับ

เลยจาทำลองทำแบบนี้ดูอ่าครับ

pukpik
Posted: Saturday, February 09, 2008 2:45:08 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/6/2008
Posts: 7
ball
Posted: Friday, February 15, 2008 2:47:55 AM

Rank: อาจารย์
Groups: Administration

Joined: 12/1/2007
Posts: 473
Location: Bangkok

ปัญหาเกิดขึ้นจากคุณใช้ Thread ครับ เอาวิธีแก้ไขแบบง่าย(แต่ยังไม่ถูกต้องนัก)ไป่ก่อนนะ

ที่ไฟล์ Program.cs

namespace TestQickscan
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

ให้ comment บรรทัดนี้ซะ

//Application.SetCompatibleTextRenderingDefault(false);


Imagination is more Important than Knowledge... /A.Einstein
pukpik
Posted: Saturday, February 16, 2008 6:21:49 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/6/2008
Posts: 7

ขอบคุณมากนะครับ

แต่ผมคอมเม้นเเล้วมานก็เหมือนเดิมอ่าครับ

T-T

mrxc
Posted: Friday, March 07, 2008 12:40:27 AM
Rank: มือเทพ
Groups: Member

Joined: 3/6/2008
Posts: 196
Location: TH

เกิดจากการข้าม Thread ครับการแก้ปัญหาอาจจะต้องให้ delegate เข้ามาช่วย แต่ถ้าไม่รุ้เรื่องแนะนำว่าใช้ timer ง่ายที่สุดครับ(อาจจะเป็นการแก้ปัญหาที่ไม่ถูกวิธีนักแต่ก็พอช่วยได้ครับ)

 

ให้ส่งค่าไปเก็บที่ตัวแปรแบบ public ที่ Form ที่เราต้องการอับเดท แล้วให้ Timer ในฟอร์มนั้นดึงค่าเข้าไปอับเดทครับ

 

อย่างที่บอกครับเป้นการแก้ปัญหาอย่างไม่ถูกวิธีที่ควรจะเป็น

 

การแก้ปัญหาแบบนี้ที่ถูกต้องคือ delegate + event ครับ

ball
Posted: Friday, March 07, 2008 12:47:15 AM

Rank: อาจารย์
Groups: Administration

Joined: 12/1/2007
Posts: 473
Location: Bangkok

ขอบคุณครับ



Imagination is more Important than Knowledge... /A.Einstein
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by