Dim AA as string="555" Debug.Print(AA.PadLeft(6, "0")) '顯示為000555 Debug.Print(AA.PadLeft(6, "$")) '顯示為$$$555 (注意,後面的字串只能一個位元)
目前分類:VB NET (16)
- Aug 15 Thu 2019 20:00
[VB .NET]指定顯示數字長度,數字前面補0
- Mar 25 Sun 2018 19:00
[VB .NET] 倒數計時器
先在畫面上拉幾個控制項
TextBox => 輸入「分鍾」,例如: 倒數5分鍾
Button => 開始
Label => 顯示倒數開始
Timer => 跑倒數要用的元件
- Mar 17 Sat 2012 00:03
ToolStrip 圖片大小變更、變更按鈕大小、按鈕顯示文字還是文字
- Mar 14 Wed 2012 00:00
MsgBox 確定執行,取消不執行 MessageBox
If MsgBox("確定訊息", MsgBoxStyle.OkCancel, "視窗標題") <> MsgBoxResult.Ok Then
'不執行
Return
End If
If MessageBox.Show("內容", "標題", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) <> MsgBoxResult.Ok Then
- Mar 09 Fri 2012 00:00
DataGridview 選取整列資料
點選 DataGridview 元件
把SelectionMode 屬性改成 FullRowSelect
就可以直接選取一整列囉
- May 12 Wed 2010 07:42
vb .net 限制只能輸入"數字",".","-","刪除鍵"
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Char.IsDigit(e.KeyChar) Or e.KeyChar = "." Or e.KeyChar = Chr(8) Then
If e.KeyChar = "." And InStr(TextBox1.Text, ".") > 0 Then
e.Handled = True
Else
- Apr 13 Tue 2010 00:08
[VB .Net] 禁止 DataGridView 的排序功能
For i As Integer = 0 To DataGridView1.ColumnCount - 1
DataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
Next
- Apr 06 Tue 2010 00:31
VB.NET 改變 DataGridView 行的顏色
If DataGridView1.Rows.Count <> 0 Then
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If (i Mod 2) = 0 Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = System.Drawing.Color.LightGreen
- Feb 18 Thu 2010 00:35
Data table的欄位為DBNull時的判斷要怎麼下
If IsDBNull(dtTable.Rows(1).Item("IsTrue")) = True Then
dtTable.Rows(1).Item("total") = "0"
End If
- Feb 10 Wed 2010 21:24
將Excel上第E3格的內容丟到DataGradView第一格上
Dim xlApp As New Excel.Application
Dim xlBooks As Excel.Workbooks = xlApp.Workbooks
Dim xlBook As Excel.Workbook = xlBooks.Open("C:\Documents and Settings\Administrator\桌面\訂單.xls")
Dim xlSheet As Excel.Worksheet = xlApp.ActiveSheet
DataGridView1.Columns.Add("Test", "Test")
- Jul 01 Wed 2009 00:15
[VB NET]DataGridView - 凍結欄位與記錄
DataGridView 是.NET Framework 2.0 新增的Windows Form 控制項, 這個控制項提供類似Excel 凍結欄位及記錄的功能.
DataGridViewColumn及DataGridViewRow皆有Frozen 屬性, 只要將這個屬性值設為True就可達到凍結的目的.
處理凍結時通常還會將 "分割線" 設為較粗的線條,
DataGridViewColumn有DividerWidth屬性, DataGridViewRow有DividerHeight屬性, 分別將它們設為大於1的值就會有比較明顯的區隔效果.
例如, 在Form_Load 事件處理凍結效果:
- Jun 16 Tue 2009 00:04
[VB.Net]圖元與毫米轉換的方法
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using g As Graphics = Graphics.FromHwnd(Me.Handle)
Dim xv = PhysicalToPixels(1, g.DpiX)
End Using
End Sub
- Jun 01 Mon 2009 00:31
[VB NET]Label 畫邊框
Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
'上
e.Graphics.DrawLine(New Pen(System.Drawing.Brushes.Black, 1), New Point(0, 0), New Point(Label1.Width - 1, 0))
'左
e.Graphics.DrawLine(New Pen(System.Drawing.Brushes.Black, 1), New Point(0, 0), New Point(0, Label1.Height - 1))
- May 26 Tue 2009 00:11
[.net]byte array和string轉換
' VB.Net 把byte array轉成String
Dim b As Byte() = {65, 66, 67, 68, 69, 70, 71}
Dim str As String
Dim enc As New System.Text.ASCIIEncoding()
Response.Write(enc.GetString(b))
- May 21 Thu 2009 00:22
[VB.Net] 關於 PictureBox 圖片 的旋轉 / 翻轉
' Form Load 事件, PictureBox 讀入圖片
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize ' 設定PictureBox 自動調整大小
PictureBox1.Load("C:\Picture\Genius.jpg") ' PictureBox 載入影像
- Feb 24 Tue 2009 14:01
[Vb.net]類別加上Intellisense說明(註解)
在VS.NET 2005裡已經提供了這樣的功能
C#的寫法是 /// (三個/)
VB.NET的寫法是 ''' (三個單引號)
先將類別、屬性、Function建好
最後在你要加上Intellisense說明的地方(類別或屬性或Function的上方)