Public Sub GenerateDynamiceButton()
从策划到设计制作,每一步都追求做到细腻,制作可持续发展的企业网站。为客户提供网站设计制作、网站设计、网站策划、网页设计、申请域名、虚拟空间、网络营销、VI设计、 网站改版、漏洞修补等服务。为客户提供更好的一站式互联网解决方案,以客户的口碑塑造优易品牌,携手广大客户,共同发展进步。
'建立 坐标位置的变数, 方便一会儿安排 自动生产的button 的位置
Dim y As Integer = 15
Dim x As Integer = 0
' 用for loop 来建立 这些button 做 18只button
For ButtonIndex As Integer = 0 To 17
' 建造新的 button
Dim MyButton As New Button
'设定这新的button 的阔度
MyButton.Width = 80
'设定这新的button 的高度
MyButton.Height = 20
'我们暂定每行有4个BUTTON, 当每行有多个4个BUTTON 时重设行距, 令到下一行的和这一行的距离有10 个PIXEL
' 和重设x 坐标` = 0, 令到位置由头开始
If ButtonIndex Mod 4 = 0 Then
'设定 TOP 的 坐标位置令他可以和上一排的有10个PIXEL 的距离
y += MyButton.Height + 10
x = 0
End If
'设定文字 和 位置
' Set the text and set its top and left based on its dimensions and count
MyButton.Text = "My Button" ButtonIndex
'设定 TOP 的 坐标位置
MyButton.Top = y
'下面的CODE 可以令到这个BUTTON 和另一个BUTTON 有5个PIXEL 的距离
MyButton.Left = 26 + (x * (MyButton.Width + 5))
x += 1
'设定 BUTTON CLICK EVENT
AddHandler MyButton.Click, AddressOf MyButton_Click
'把button 加到 form 中
Me.Controls.Add(MyButton)
Next
End Sub
'处理 button click event
Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim btn As Button = sender
'pop up 一个自己button 的字的message
MsgBox(btn.Text)
1. F12:转到定义;Shift+F12:转到引用
2. F5:启动;Ctrl+F5:开始执行(不调试);Shift+F5:停止调试
3. F7:查看代码;Shift+F7:查看视图设计器
4. Ctrl+Alt+L:解决方案资源管理器
5. Ctrl+Alt+J:对象浏览器
6. F4:显示属性窗口
7. Ctrl+Alt+X:工具箱
8. Ctrl+Alt+C类视图
9. Alt+Enter:查看属性
10.F10:逐过程调试
11.F11:逐语句调试
12.Ctrl+B:新断点
13.Ctrl+Shift+F9:清除所有断点
14.Ctrl+Shift+B生成解决方案
15.Shift+Alt+Enter:全屏
16.大纲显示:Ctrl+M, Ctrl+M:切换大纲显示展开;Ctrl+M, Ctrl+L:切换所有大纲显示;Ctrl+M,Crtl+P停止大纲显示;Ctrl+M, Ctrl+O:折叠到定义
17.智能感知:Ctrl+J:列出成员;Ctrl+Shift+空格:参数信息; Ctrl+K,Ctrl+I:快速信息;Alt+右箭头键:完成单词
字符编码转换吗?
1.字符与gb2312(gbk的子集):
Public Function GBKEncode(ByVal sInput As String) As String
Dim ret_GBKEncode As String = ""
Dim i As Integer
Dim startIndex As Integer = 0
Dim endIndex As Integer
Dim x() As Byte = System.Text.Encoding.Default.GetBytes(sInput) '字符以及字符串在vb2008中都是以unicode编码存储的
endIndex = x.Length - 1
For i = startIndex To endIndex
ret_GBKEncode = "%" Hex(x(i))
Next
Return ret_GBKEncode
End Function
'GBK解码
Public Function GBKDecode(ByVal sInput As String) As String
sInput = sInput.Replace("%", "")
Dim ret_GBKDecode As String = ""
Dim sLen As Integer = sInput.Length
Dim n As Integer = sLen \ 2
Dim sBytes(0 To n - 1) As Byte
'转化为字节码
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))
Next
'将字节码转化为字符串
ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)
Return ret_GBKDecode
End Function
2.Unicode字符串为UTF-8
Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
Return bytes
End Function
'这里可以类推出好几种。
(1)在Form1上布置一个Label,用来显示键盘码
(2)窗体代码如下
Imports System.Windows.Forms
Imports System.IO
Imports System.Net
Imports System.Windows.Forms
Imports System.IO
Imports System.Net
Public Class Form1
Private Sub Form1_Load(sender As Object,
e As EventArgs) Handles MyBase.Load
KeyPreview = True
End Sub
Private Sub Form1_KeyDown(sender As Object,
e As KeyEventArgs) Handles MyBase.KeyDown
Label1.Text = e.KeyValue
End Sub
End Class
按键盘上的键,Label1将显示对应键的键盘码