Gambas/Grid
外观
< Gambas
返回 Gambas
网格有行和列。它们有宽度和高度。您可以用文本、数字甚至图片填充网格。
您需要一个新窗体来运行程序。在这个窗体上,您放置一个网格视图,您可以在工具箱中找到它。您的目录中应该有一个名为 x.png 的图片。否则,它将不会显示。如果没有找到,不会出现错误消息。
STATIC PUBLIC SUB Main()
hForm AS Fmain
hForm = NEW Fmain
hForm.show
END
PUBLIC SUB _new()
GridView1.Columns.Count = 4
GridView1.Rows.Count = 3
GridView1.Columns.Width = 52
GridView1.Rows[1].Height = 52
GridView1[0,0].Text = "0,0"
GridView1[0,0].Alignment = 4
GridView1[1,1].Text = "1,1"
GridView1[0,1].Text = "0,1"
GridView1[1,0].Picture = Picture["x.png"]
END
网格是可以创建的。一个小例子展示了它是如何完成的。
g AS Gridview
PUBLIC SUB _New()
g = NEW Gridview(ME) AS "Gridview1"
g.show
g.Columns.Count = 4
g.Rows.Count = 3
g.Columns.Width = 52
g.Rows[1].Height = 52
END
您只需要一个空窗体来运行程序。
网格的属性
BackColor Background Border ClientH ClientHeight ClientW ClientWidth Column Columns Current Cursor
Design Drop Enabled Expand Font ForeColor Foreground Grid H Handle Height Id Left Mouse Parent Row
Rows ScreenX ScreenY ScrollBar Tag ToolTip Top Visible W Width Window X Y
方法
Clear Delete Drag Grab Hide Lower Move Raise Refresh Resize SetFocus Show
事件
Activate Click DblClick Drag DragMove Drop Enter GotFocus KeyPress KeyRelease Leave LostFocus Menu MouseDown MouseMove MouseUp MouseWheel Scroll
您有一系列值,并且希望将它们放在网格中。该示例向您展示了一种解决方案。仍然不太好,并且包含一些德语单词。
您需要以下控件
- 1 个文本区域
- 1 个网格视图
- 2 个命令按钮
代码
PUBLIC SUB Button1_Click()
textarea1.Text = "114"
textarea1.Text = textarea1.Text & Chr(10) & "135"
textarea1.Text = textarea1.Text & Chr(10) & "104"
textarea1.Text = textarea1.Text & Chr(10) & "118"
textarea1.Text = textarea1.Text & Chr(10) & "125"
textarea1.Text = textarea1.Text & Chr(10) & "121"
textarea1.Text = textarea1.Text & Chr(10) & "122"
textarea1.Text = textarea1.Text & Chr(10) & "96"
textarea1.Text = textarea1.Text & Chr(10) & "118"
textarea1.Text = textarea1.Text & Chr(10) & "120"
textarea1.Text = textarea1.Text & Chr(10) & "112"
textarea1.Text = textarea1.Text & Chr(10) & "127"
textarea1.Text = textarea1.Text & Chr(10) & "122"
textarea1.Text = textarea1.Text & Chr(10) & "128"
textarea1.Text = textarea1.Text & Chr(10) & "120"
END
PUBLIC SUB _new()
GridView1.Columns.Count = 2
GridView1.Rows.Count = 15
GridView1.Columns.Width = 72
END
PUBLIC SUB Button2_Click()
DIM text AS String
DIM Liste AS String[]
DIM Einzelwert AS String
DIM x AS Integer
x = 0
text = textarea1.Text
Liste = Split(text,Chr(10))
FOR EACH Einzelwert IN Liste
GridView1[x,1].Text = Einzelwert
GridView1[x,0].Text = x
x = x + 1
NEXT
PRINT liste.Length
END
当您按下按钮 1 时,文本区域将填充值。当您按下按钮 2 时,它们将被放置在网格中。
如果您愿意,可以改进此程序。它看起来有点像新手。