2010年6月22日 星期二

Visual Studio 2010

幾個 VB 的技巧…

Callback 函式指定方式

AddHandler _timer.Tick, AddressOf TimerEventProcessor

Private Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
'todo
End Sub



SerialPort1_DataReceived 因為是執行緒非同步在接收 RS232 的資料,而 VB 不允許在執行緒中直接設定一些 Components 的值,因些必須透過代理的方式來處理…

Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
memoMessage.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
End Sub

Public Delegate Sub myDelegate()
Public Sub updateTextBox()
memoMessage.Text = SerialPort1.ReadExisting()
End Sub



String 跟 char array 轉換的方式…

Dim str as String
Dim carr() As Char = str.ToCharArray
str = CStr(carr)



要加快 components 的繒圖速度可以使用 GDI 雙重緩衝,若是繼承自 compnents 可寫在 New() 建構式中…

Public Sub New()
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

沒有留言:

VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...