|
 |
|
สอบถามเรื่องปัญหาการส่งค่าข้อมูล ระหว่าง method c# ว่าส่งอย่างไร |
|
 |
|
|
 |
 |
|
ตรง private void btnReadMap_Click ได้มีการเปิดไฟล์อ่านเค่าเข้ามาเก็บไว้ในตัวแปร MapH, MapW, และ Topo[,] ซึ่งมีข้อมูลเรียบร้อยแล้ว แต่ต้องการส่งข้อมูลเหล่านี้ออกไปใช้ใน private void simpleOpenGlControl1_Paint ซึ่งตอนนี้ไม่สามารถส่งข้อมูลออกไปได้ รบกวนช่วยแนะนำด้วยนะคะว่าเค้าส่งค่ายังไง ขอบคุณมากค่ะ
Code (C#)
namespace Wave_simulation
{
public partial class Form1 : Form
{
float DataMax, DataMin;
int MapH;
int MapW;
float[,] Topo;
float[] TopoFloat;
public Form1()
{
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
}
private void btnReadMap_Click(object sender, EventArgs e)
{
string MapHight = null;
string MapWidth = null;
int i,j;
FileStream FileInput = new FileStream("D:\\Wave_Simulation\\Wave_simulation\\test2.txt", FileMode.Open); /
StreamReader sr = new StreamReader(FileInput);
MapWidth = sr.ReadLine();
MapW = Convert.ToInt32(MapWidth);
MapHight = sr.ReadLine();
MapH = Convert.ToInt32(MapHight);
sr.Close();
FileInput.Close();
string buffer;
buffer = File.ReadAllText("D:\\Wave_Simulation\\Wave_simulation\\test.txt");
TopoFloat = new float[MapH * MapW];
Topo = new float[MapH, MapW];
string[] Z_S = new string[MapH*MapW];
int M = MapH * MapW;
DataMax = -9999;
DataMin = 1F+10;
string[] TopoStr = buffer.Split(' '); //SubString
for (i = 0; i < M; i++)
{
TopoFloat[i] = Convert.ToSingle(TopoStr[i]);
}
for (i = 0; i < MapH; i++)
{
for (j = 0; j < MapW; j++)
{
Topo[i, j] = TopoFloat[i * MapW + j];
Console.Write(Topo[i, j] + " ");
}
Console.Write("\n");
}
for (i = 0; i < MapH; i++)
{
for (j = 0; j < MapW; j++)
{
if (Topo[i, j] == -9999)
{
Topo[i, j] = -3;
}
if (DataMin > Topo[i, j])
{
DataMin = Topo[i, j];
}
else if (DataMax < Topo[i, j])
{
DataMax = Topo[i, j];
}
}
}
}
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
{
Console.Write(MapH + "\n");
Console.Write(MapW + "\n");
for (i = 0; i < MapH; i++)
{
for (j = 0; j < MapW; j++)
{
Console.Write(Topo[i, j] + " ");
}
Console.Write("\n");
}
}
}
Tag : C#

|
|
 |
 |
 |
 |
Date :
2014-06-30 10:44:10 |
By :
nun |
View :
826 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันที่จริงถ้าประกาศไว้บนสุดก็น่าจะเรียได้จากทุก ๆ Method ภายใน Class อยู่แล้วน่ะครับ 
|
 |
 |
 |
 |
Date :
2014-07-01 08:49:39 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|