發表文章

目前顯示的是 2008的文章

使用VS2008 搭配 sql compact V3.5 SP1 要留意版本

Sql server compact edition 是微軟對於資料庫的另一種解決方案,而當你預計使用是sqlCE V3.5 SP1的時候要留意一下版本的問題,尤其是開發裝置應用程式的時候;我自己目前是使用VS2008在開發,VS2008也裝了SP1,原先以為這樣我的開發也升級到SP1的版本了.. 事情就這麼發生了.. 好,我們來解決問題吧,首先要確認你的裝置上SqlCE的版本,可以用登錄檔編輯器到下面位置看板本 \HKEY_LOCAL_MACHINE\SPFTWARE\MICROSOFT\MICROSOFT SQL SERVER COMPACT EDITION\V3.5 SP1的版本號是3.5.5692.0,如果你是3.5.5382.0那麼就是V3.5不含SP1的版本;確認完版本正確之後,我們到微軟的網站下載SP1的安裝檔,位置是 http://www.microsoft.com/downloads/details.aspx?familyid=FCE9ABBF-F807-45D6-A457-AB5615001C8F&displaylang=zh-tw ,那麼要怎麼確認開發電腦裝過了沒呢?可以到下面位置看DLL的版本 C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Devices\System.Data.SqlServerCe.dll 還沒有安裝過SP1的話這個dll會是3.5.5386.0,安裝完畢就會看到相關檔案升級了;好,環境裝好了之後記得要到你的專案裡面把相關的參考給更新喔;大功告成,收工。 另外,如果想知道為什麼VS2008 SP1裡面沒有幫含這部分的話,可以參考下面這邊 http://blogs.msdn.com/stevelasker/archive/2008/08/13/why-doesn-t-visual-studio-2008-sp1-installer-update-sql-server-compact-3-5-for-devices.aspx  

How-to 單一執行個體的裝置應用程式(CE)

一般PC的應用程式在專案屬性中就有一個樣目可以勾選目前這個應用程式是不是"只能夠執行一次",而到了裝置專案中,卻沒有這個項目可以用,那麼該怎麼辦呢? 首先是一些參考資料,下面提到的解決方式也是利用搜尋來的;利用"PrevInstance"的關鍵字到MSDN上去搜尋就會有很多資料可以參考了,相關網址是這邊 http://social.msdn.microsoft.com/Search/zh-TW/?query=PrevInstance&addEnglish=1&ac=3 再來我們看看解決方式,首先再專案屬性中的"起始物件"我們要設定成"Sub Main",之後新增一個模組,模組內要包含Sub Main這個"方法"喔,之後利用下面程式碼的方式就可以了(這邊說明以VB為主,用C#的朋友請自行轉換一下) Declare Function FindWindow Lib "coredll.dll" (ByVal className As Char(), ByVal WindowsName As Char()) As Integer Declare Function SetForegroundWindow Lib "coredll.dll" (ByVal hwnd As Integer) As Boolean Public Sub Main() Dim hWnd As Integer hWnd = FindWindow(Nothing, "你的應用程式標題名稱".ToCharArray) If hWnd <> 0 Then SetForegroundWindow(hWnd) Application.Exit() Exit Sub Else Application.Run(New Form1) End If End Sub

How-to 抓取CE裝置的畫面

圖片
一般如果說我們要抓取裝置(mobile)的畫面的時候會先用ActiveSync跟裝置連線,之後使用Remote Tool中的"遠端放大工具來抓畫面,那麼如果說我的裝置是透過Tcp/IP連接的,那怎麼辦? 請你跟我這樣做 ~ 首先,跟要進行遠端偵錯時同樣的動作,我們需要將相關的檔案先複製到裝置上;偵錯所需的檔案有哪些呢?請到 C:\Program Files\Common Files\microsoft shared\CoreCon\1.0\Target\wce400資料夾中,你會看到很多資料夾,依照你使用的CPU類型將資料夾裡面的檔案複製一份到裝置上,等一下我們會用到這些檔案。 之後開啟你的Visual Studio,VS2008和VS2005過程是一樣的,Visual Studio開啟之後選擇功能表"工具"-->"選項",之後在右邊列表找到Windows CE裝置,之後選擇"屬性",在傳輸部分是選$擇"TCP連接傳輸",右邊有一個"設定"按鈕,點下去之後將裝置IP位址設定為"使用特定IP位址",並在下方設定你的裝置IP,像下圖這樣 IP設定好了之後就可以將Visual Studio關閉了;之後執行 Remote Tool,你可以在下面這邊找到相關工具 執行遠端放大工具後會看到像下面的畫面 先別急著點OK,我們還要到裝置上執行相關的工具程式; a. 開啟你的Windows CE裝置(在CE裝置上操作),利用檔案總管進到之前一開始複製檔案的地方,先執行"ConmanClient2.exe",之後執行"CMAccept.exe",這兩個執行後都是沒有介面(UI)會跑出來的,所以確定有去執行它就可以了 在3分鐘之內(第一次連接做驗證有3分鐘限制,連接上之後就沒關係),按下遠端放大工具的OK鈕就會從TCP/IP去對裝置作連線並抓取目前畫面,要注意的是只會抓一張,按下refresh會重抓;抓下來會像下面這樣 大功告成,相關的Remote Tool要使用時也是比照辦理的方式嚕 ~

插入資料到資料庫中時部分中文字變成"?"

最近做專案把人員相關資料從AD轉換到SQL中發現部分人員的中文姓名變成了"?",想說奇怪.net不是都已經是unicode的編碼方式,應該不太會遇到這狀況才對;確認了一下來源,是 "綉" 這個字,這個字也不特殊啊,是什麼道理會塞到資料庫就變成"?"呢.. 好吧,程式下個中斷來瞧瞧吧;嘿嘿,中斷之後在程式碼中出現的字也是正常的,我勒..是怎樣,後來有其他東西要趕,就先放著..就這麼過了兩天...兩天後突然間一到耀眼的金色光芒閃過眼前,印象中插入中文字要加個"N"字喔...對了一定是這個,於是乎在Inser Into裡面加了"N",嘿嘿,搞定收工;可得好好記起來才行。 所以在插入中文字的時候記得要確認欄位類型是n開頭的欄位,像是nChar或是nVarChar,而在Insert的時候要加上"N"這個關鍵字,可以用下面的方式來比較看看 Update myTable Set ChName='王綉綉' Where ID=1 Update myTable Set ChName=N'王綉綉' Where ID=1 相關參考 Insert 中文字到Database的Char資料型別的某特定中文字會變成"?",如何解決?

使用user setting來存放資料

圖片
Note:本篇使用工具為VS2008,.Net framework 2.0 在 前面這篇 有提過設定檔的使用方式,在Visual Basic中有更簡單的方式可以去使用,下面我們來看看使用的方式 首先,開啟專案的屬性頁籤,加入兩個設定,像是下面這張圖 要特別注意,這邊要將範圍設定為"user",在程式碼中你會發現,如果你將範圍設定為"application"的話那麼,它會是 ReadOnly 的;設定完成之後,我做了像下圖簡單的Form 很簡單的介面,取得或是儲存的程式碼也相當的簡單 Private Sub btnReadSetting_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadSetting.Click txtSetting1.Text = My.Settings.Setting1 txtSetting2.Text = My.Settings.Setting2 End Sub Private Sub btnSaveSetting_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSetting.Click My.Settings.Setting1 = txtSetting1.Text My.Settings.Setting2 = txtSetting2.Text End Sub 就這樣,我們就可以利用config檔來儲存程式要用的相關設定了。點開設定檔(app.config)你會看到像下面這樣的xml設定 有另外一點要特別注意,一般的設定檔會放在跟exe檔同樣的目錄中,而使用像上面的方式去儲存之後,你會發現"奇怪,檔案內容怎麼沒有變化呢?",原因是當經過儲存動作之後,會將設定檔放到使用者資料存放區去了,也就是 C:\Documents and Settings\使用者登入名稱\Local Settings\Application Data\公司名稱\應用程式名稱_XX\版本資料夾 ,所以去直

安裝部屬-設定啟動條件

圖片
呼~好久沒貼文了,這個月趕案子真是快爆了... 不過因為沒接觸的東西多,學到的東西也多,之後在來好好整理一下;下面這邊剛好是過程中遇到的問題之一,其實也是個小問題;當用VS2008來作封裝時專案是使用.net framework 2.0,沒有用到3.5的東西,奇怪,怎麼安裝檔(msi)一下去安裝居然說要安裝.net framework 3.5呢?事情就這麼開始了.. 下面就來看看怎麼解決這個問題了 首先在安裝部屬專案的名稱點一下右鍵,之後選擇屬性,把必要條件設定這邊設定一下,像是下面這張圖 接下來開啟"啟動條件編輯器"的視窗,你會看到一個.net framework的項目,點一下它,之後看屬性視窗,把Version的項目修改成你要的,像是下面這張圖 設定完成之後重新編譯,這樣就可以解決問題了,搞定收工。

禁止遁地 !?

圖片
今天在車上停紅燈的時候突然間看到這個指示牌 不過沒看到它的中文說明,為了避免大家不清楚,特別在這裡補上說明給大家參考 禁止遁地 !! 哈~博君一笑..XD PS:照片是在車子裡面有手機拍的,有些倒影,大家可別覺得是靈異照片啊...XD

利用"字串"來叫出專案中的Form

今天碰巧看到網友問相關問題,搜尋了一下,在美國的MSDN論壇有這樣的做法(針對Form),在這邊列出給大家參考 Dim myF As Form = _ CType(Activator.CreateInstance(System.Reflection.Assembly.GetExecutingAssembly.GetType("YourAssemblyName." & "YourFormName")), Form) myF.Show() 這樣就可以叫出對應的form了,今天又學了一招..嘿嘿... 美國論壇搜尋的結果可以參考這邊

MS SQL Server 2008 Express

很久沒灌灌水了,最近事情太多了,忙著弄其他的東西...累啊... 話說SQL Server 2008 RTM版本已經發行,同樣的Express的版本已經出來了,喜歡嘗鮮的朋友可以去看看;不過安裝上有些部份要注意的,請到 Alex前輩的blog 上去看看吧,下載可以到 express網站 下載。

WPF - 利用資料繫結顯示DataSet的資料

殘念啊...由於XAML Code的關係,請各位到 點部落看相關文章 吧~感恩

簡單的XML R/W 範例

Note:.net compact framework 2.0,Windows mibile 5.0 這篇主要是回復網友問題時做的測試程式,原文在 這邊 ,下面來看看測試的程式碼 XML內容是像下面這樣 程式碼部分 Imports System.Xml Public Class Form1 Dim xmlDoc As XmlDocument Dim strTmp As String = "" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load xmlDoc = New Xml.XmlDocument() ''載入XML文件 xmlDoc.Load(GetAppPath() & "\test.xml") End Sub Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click Dim xnodelist As Xml.XmlNodeList = xmlDoc.SelectNodes(txtXPath.Text) If xnodelist.Count > 0 Then DisplayXmlNode(xnodelist) Else TextBox1.Text = "Not found" End If End Sub Private Sub DisplayXmlNode(ByRef xNodeList As XmlNodeList) For Each x As Xml.XmlNode In xNodeList If x.HasChildNodes Then

WPF - Resource

這篇大部分是XAML Code,所以這邊就只留轉向了,請有興趣的朋友到 點部落看相關文章 吧,感恩。

WPF - SkewTransform

這篇測試一下SkewTransform的功能,做了一個"丟猴"的按鈕,有興趣的朋友可以跑程式測試看看 測試的程式碼是下面這些,另外由於這邊貼XAML真的是很頭大,到 點部落看完整的文章 吧 Class Window1 Dim st As New SkewTransform Dim myT As Threading.DispatcherTimer Dim R As New Random Dim tmpTop As Double = 0 Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btn1.Click ''Timer相關設定 myT = New Threading.DispatcherTimer myT.Interval = New TimeSpan(0, 0, 0, 0, 100) AddHandler myT.Tick, AddressOf Timer_Tick myT.Start() End Sub Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) If Canvas.GetTop(btn1) >= cv.ActualHeight Then myT.Stop() End If Randomize() st.AngleX = (0.5 - R.NextDouble) * 30 st.AngleY = (0.5 - R.NextDouble) * 50 System.Threading.Thread.Sleep(30) btn1.RenderTransform = st Canvas.SetLeft(btn1, R.NextDouble * 50) tmpTop = tmp

WPF - RotateTransform

圖片
這篇來測試一下旋轉的效果,旋轉的效果是將RotateTransForm設定給控制項的RenderTransForm屬性,執行的結果像下面這樣 下面我們就來看看測試的程式碼吧 Imports System.Windows Imports System.IO Imports System.Reflection Class Window1 Dim cv As Canvas Dim myT As Threading.DispatcherTimer Dim btnOther As New Button Dim rotatePoint As Double = 0 Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded cv = New Canvas Me.Content = cv For z As Integer = 0 To 9 Dim btn As New Button btn.Name = "btn_" & z ''設定旋轉的原點 btn.RenderTransformOrigin = New Point(0, 0) ''設定旋轉的角度 btn.RenderTransform = New RotateTransform(z * 36) btn.Content = "Button" & z & " Rotate=" & Format(z * 36, "000") btn.Background = Brushes.LightPink Canvas.SetLeft(btn, 150) Canvas.SetTop(btn, 150

WPF - 簡單的圖檔瀏覽程式

圖片
這篇當作練習題,把之前的稍為回憶一下,來作個簡單的圖檔瀏覽程式,完成之後是像下面這樣 介面的部分就改用XAML Code來作了,下面我們來看看相關的程式碼吧 Imports System.Windows Imports System.IO Imports System.Reflection Class Window1 Dim smallImg() As Image Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded RefreshImage() End Sub Private Sub wpSmallImg_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles spSmallImg.MouseDown If e.OriginalSource.GetType.Name = "Image" Then LargerImg.Source = CType(e.OriginalSource, Image).Source End If End Sub Private Sub btnSelect_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSelect.Click Dim dlgOpen As New Windows.Forms.FolderBrowserDialog If dlgOpen.ShowDialog = Forms.DialogResult.OK Then txtSource.Text = dlgOpen.SelectedPath RefreshImage() End If End S

WPF 教學短片

各位鄉親阿,由曹祖聖老師錄製的一系列有關WPF的教學短片已經放上MSDN了,千萬不要錯過啦,快點去瞧瞧吧 MSDN WPF 教學短片

WPF - Expander

圖片
Expander也算是一種容器,下面我們簡單的用程式碼來測試一下Expander的功能,執行結果畫面大概是像下面這樣 Imports System.Windows Imports System.IO Imports System.Reflection Class Window1 Dim sp As StackPanel Dim exp As Expander Dim chsp As StackPanel Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded sp = New StackPanel Me.Content = sp chsp = New StackPanel For z As Integer = 0 To 4 Dim rdo As New RadioButton rdo.Name = "rdo" & z rdo.Content = "RadioButton" & z chsp.Children.Add(rdo) Next exp = New Expander exp.Content = chsp exp.Background = Brushes.AliceBlue sp.Children.Add(exp) ''設定展開的方向 ''exp.ExpandDirection = ExpandDirection.Right exp.Header = "Header" End Sub End Class

Tools

本篇是給自己備忘的,有興趣的朋友也可以看看 AutoRuns for Windows v9.21 此公用程式 (具有任何啟動監視器之自動啟動位置的最完整知識) 顯示設定在系統開機或登入期間執行的程式,以及顯示舊版 Windows 中項目的處理方式。這些程式包含啟動資料夾、Run、RunOnce 和其他登錄機碼中的程式。您可以設定 Autoruns 顯示其他位置 (包含檔案總管殼層延伸、工具列、瀏覽器協助程式物件、Winlogon 通知、自動啟動服務等)。Autoruns 與 Windows Me 和 XP 提供的 MSConfig 公用程式不同。 Autoruns 的 [隱藏簽署的 Microsoft 項目 (Hide Signed Microsoft Entries)] 選項可協助您專注在已新增至系統的協力廠商自動啟動影像,且支援查看系統上其他帳戶設定的自動啟動影像。下載套件中還包含 Autorunsc,這是具備相同功能但可以用 CSV 格式輸出的命令列公用程式。 您會十分驚訝有這麼多可以自動啟動的執行檔! Autoruns 可在所有版本的 Windows 上執行,包含 Windows XP 64 位元版本 (適用 x64) 和 Windows Server 2003 64 位元版本 (適用 x64)。 AccessChk v4.1 為了確保所建立之環境的安全性,Windows 系統管理員必須經常瞭解特定使用者或群組對資源的存取權限,這些資源包括:檔案、目錄、登錄機碼、全域物件以及 Windows 服務。AccessChk 會使用易於瞭解的介面和輸出來快速回答這些問題。 Process Monitor v1.33 Process Monitor 是一種進階的 Windows 監視工具,可顯示即時檔案系統、登錄和處理程序/執行緒活動。Process Monitor 不但綜合了兩個舊版的 Sysinternals 公用程式功能 (Filemon 和 Regmon),還新增了一連串的增強型功能,這些功能包括豐富和無破壞性的篩選、詳盡的事件內容 (如工作階段 ID 和使用者名稱)、可靠的處理程序資訊、含每個作業整合符號支援的完整執行緒堆疊、同步記錄到檔案以及其他功能。這些強大的功能可讓 Process Monitor 成為系統疑難排解和惡意程式碼捕捉工具組的核心公用程式。

WPF學習日誌 ~ RadioButton ~

RadioButton與之前在Windows Form的時候使用上沒有太大的差異,下面這邊我們特別說明一個GroupName這個屬性;在以往,同一個群組的項目我們會把它放到容器中,用容器來作分割;而在WPF裡面則是用GroupName來作分割,下面我們來看看測試的程式碼 Imports System.Windows Imports System.IO Imports System.Reflection Class Window1 Dim spMain As StackPanel Dim wpChild_1 As WrapPanel Dim wpChild_2 As WrapPanel Dim rdoA(2) As RadioButton Dim rdoB(2) As RadioButton Dim tbMsg As TextBlock Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded spMain = New StackPanel Me.Content = spMain For z As Integer = 0 To 2 rdoA(z) = New RadioButton rdoA(z).Content = "RadioButton-A-" & z ''不指定GroupName的話預設是"" 'rdoA(z).GroupName = "A" rdoA(z).Margin = New Thickness(3) AddHandler rdoA(z).Checked, AddressOf RadioButton_Checked rdoB(z) = New RadioButton rdoB(z).Content = &qu

WPF學習日誌 ~ RepeatButton ~

RepeatButton也是Buton其中的一種,主要的差別是在於當你按住RepeatButton不放的時候,Click事件會被重複的觸發;下面是測試的程式碼,可以測試壓著Button不放的時候TextBox的變化 Imports System.Windows Imports System.IO Imports System.Reflection Class Window1 Dim wp As WrapPanel Dim txtInput As TextBox Dim btnAdd As Windows.Controls.Primitives.RepeatButton Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded wp = New WrapPanel Me.Content = wp txtInput = New TextBox txtInput.Width = 200 txtInput.Text = "0" wp.Children.Add(txtInput) btnAdd = New Windows.Controls.Primitives.RepeatButton btnAdd.Content = "Press Me" wp.Children.Add(btnAdd) AddHandler btnAdd.Click, AddressOf Button_OnClick End Sub Protected Sub Button_OnClick(ByVal sender As Object, ByVal e As RoutedEventArgs) txtInput.Text = CInt(txtInput.Text) + 1 End Sub End Class

WPF學習日誌 ~ 只能輸入數字的TextBox ~

在Windows Form常常有一些驗證輸入的需求,限制只能輸入某些字的TextBox在WPF中跟之前沒有太大的不同,下面簡單的列出處理部分的程式碼 AddHandler txt.PreviewKeyDown, AddressOf TextBox_PreviewKeyDown 這裡我們在PreviewKeyDowm的事件中處理,處理的程式碼像下面這樣 Protected Sub TextBox_PreviewKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) If (e.Key < Key.D0) OrElse (e.Key > Key.D9) Then e.Handled = True End If End Sub 要特別注意的是在PreviewKeyDown事件中不要直接抓TextBox.Text來作處理喔,因為這個事件中抓到的Text是"還沒有把輸入文字附加到Text屬性上"的

WPF學習日誌 ~ 事件傳遞 ~

這篇簡單的說明一下在WPF中事件傳遞的部分,下面是測試的程式碼 Class Window1 Dim sp As StackPanel Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded sp = New StackPanel Me.Content = sp Dim tb As New TextBlock tb.Text = "I am a TextBlock" sp.Children.Add(tb) Dim btn As New Button btn.Content = "Button" sp.Children.Add(btn) Dim txt As New TextBox txt.Text = "Test words" sp.Children.Add(txt) AddHandler Me.MouseDown, AddressOf El_OnMouseDown End Sub Protected Sub El_OnMouseDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs) If e.ChangedButton = MouseButton.Right Then Me.Title = "Source:" & e.Source.ToString & " OriginalSource:" & e.OriginalSource.ToString If CType(e.Source, FrameworkElement).Margin = New Thickness(5) Then CType(e.So

利用IP位置取得對方的Mac

要取得本機的MAC位置我們可以利用WMI或是.Net framework提供的相關功能來作,例如下面這兩篇 請問在 VB2005 中, 如何得知對方 MAC Address vb.net 2005如何獲取本機以下信息 那如果要得知遠端的MAC位址應該怎麼做,雖然可以利用arp的指令並將結果輸出到文字檔,但這樣有點麻煩,找了些參考資料後,我們可以用下面的程式碼來取得 首先是一些參考資料 RtlMoveMemory SendARP Function How to get mac address with input ip address 下面是測試的程式碼 Private Const No_ERROR = 0 _ Private Shared Function inet_addr(ByVal s As String) As Integer End Function _ Private Shared Function SendARP(ByVal DestIp As Integer, _ ByVal ScrIP As Integer, _ ByRef pMacAddr As Long, _ ByRef PhyAddrLen As Long) As Integer End Function _ Private Shared Sub CopyMemory(ByVal dst As Byte(), ByRef src As Long, ByVal bcount As Integer) End Sub Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, ByRef sRemoteMacAddress As String) As Boolean Dim dwRemoteIp As Integer Dim pMacAddr As Long = 0 Dim bpMacA

掃描裝置上的GPS是哪一個COM

在" 在PDA上開發GPS的程式問題 這篇文章中,有提到要如何去看GPS是在哪一個COM Port上面;一般來說有兩個方式,一個是自己去掃描,另一種方式就是借助別人的軟體去看了;下面這邊我做了一個簡單的掃描程式,有興趣的朋友可以參考看看 Imports System.IO.Ports Imports System.Text Public Class Form1 Dim strPortName As String = "" Dim strTmp As String = "" Dim B(199) As Byte Dim intReturn As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.BaudRate = 4800 SerialPort1.DataBits = 8 SerialPort1.Handshake = Handshake.None SerialPort1.StopBits = StopBits.One SerialPort1.Parity = Parity.None SerialPort1.ReadTimeout = 2500 For Each s As String In SerialPort.GetPortNames SerialPort1.PortName = s Try SerialPort1.Open() Threading.Thread.Sleep(200) intReturn = SerialPort1.Read(B, 0, B.Length) If intReturn > 0 Then strTmp = Encodi

Form.Show ? Form.ShowDialog ?

在討論區 請問close, dispose與form的關係 這篇文章中,提到有關Form的一些關閉事件的問題,其中有關ShowDialog的部分在Windows Form上面也是相同的,大家可以參考一下 你可以用下面程式碼來觀察事件發生的順序(我使用的是VB) Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed Debug.WriteLine(Now.Ticks & ": Form Closed..") End Sub Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Debug.WriteLine(Now.Ticks & ": Form Closing..") End Sub Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed Debug.WriteLine(Now.Ticks & ": Form Disposed..") End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.MinimizeBox = False End Sub 另外預設Form的右上角會是"X"(也就是允許最小化),在"X"的時候點下去,這時候是不會把Form關閉的,而是讓Form躲起來;而設定Me.MinimizeBox = False(不允許最小化),這時候右上角會變成"OK",這時候點選的時候會把Form關閉。 要特別注意的一點,當用ShowDialog的方式去呼叫表單出來的時候,要自行在關閉Form

DataGridView欄位計算總合

在 關於DataGridView的問題 這篇問題中,有網友提到了DataGridView總和的部分要如何去做,chhuang大有回覆了一篇,真是太神了,節錄問題與解決方式如下 問題 我想要計算DetailDataGridView金額的總計 還有就是以蛋糕為例 5*30=150 計算好填回金額內 然後總計的270元 我要寫入另外的textbox內 例如: 商品 數量 單價 金額 -------------------------------------------------- 牛奶 1 20 20 咖啡 2 50 100 蛋糕 5 30 150 總計 270 元 使用VB2005 解答 private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("C1", typeof (string)); dt.Columns.Add("C2", typeof (int)); dt.Columns.Add("C3", typeof (int)); dt.Columns.Add("C4", typeof(int)); dt.Columns["C4"].Expression = "C2 * C3"; dt.Rows.Add("牛奶", 1, 20); dt.Rows.Add("咖啡", 2, 50); dt.Rows.Add("蛋糕", 5, 30); dataGridView1.DataSource = dt; textBox1.Text = dt.Compute("Sum(C4)", null).ToString(); } 相關參考 DataTable.Compute 方法 DataColumn.Expr

腦力激盪 - 我可以拿到幾個糖果?

今天看電視看到這個題目還滿有趣的,沒看過的朋友可以玩玩看;題目是這樣的 用1塊錢可以買到一個糖果,今天店家大優惠,3個糖果紙可以換一個糖果,請問,用15塊能夠得到幾個糖果呢? 先想想,答案就在下面了~ Ans:22個 15+5+1+1=22,為甚麼呢?首先用15塊買到15個糖果,15個糖果紙可以換到5個糖果,換來的5個糖果其中3個糖果紙可以再換到1個糖果,重點來了,換來的這1個糖果紙跟之前剩下的兩個糖果紙又可以換到一個糖果~~ 真是太神奇了~傑克~,我之前是算20個,沒想到看似簡單的題目暗藏這麼多的玄機啊~

WPF Sample

在 MSDN 上有提供相當多的WPF相關範例可以參考,對這部分有興趣的朋友可千萬別錯過了;原文位置如下 Windows Presentation Foundation 範例 節錄部分相關主題連結如下 WPF 入門範例 應用程式開發範例 WPF 基本概念範例 協助工具範例 控制項範例 資料範例 (WPF) 文件範例 (WPF) 圖形和多媒體範例 全球化和當地語系化範例 移轉和互通性範例

WPF學習日誌 ~ Canvas ~

之前我們有介紹WPF裡面的容器,這個是最後一個容器了,Canvas,它的主要特性其實就是利用絕對位置來排列控制項,下面我們用簡單的測試程式碼來看一下 Class Window1 Dim cv As Canvas Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded cv = New Canvas cv.Width = 300 cv.Height = 300 cv.Background = Brushes.AliceBlue For i As Integer = 0 To 4 Dim B As New Button B.Content = "_" & i.ToString Canvas.SetLeft(B, i * 20) Canvas.SetTop(B, i * 20) cv.Children.Add(B) Next Me.Content = cv End Sub End Class

WPF學習日誌 ~ CaptureMouse ~

圖片
CaptureMouse顧名思義是捕捉滑鼠,那捕捉滑鼠要做什麼呢? 當我們捕捉住滑鼠的訊號之後,當滑鼠離開了Winddow的範圍之外,我們仍然可以收到MouseMove以及MouseUp的事件,這可以利用在縮/放部分,如果你有用過Blend(或是跑過DirectX的sample)的話,在調整(縮/放)工作區大小時,是類似的感覺;下面測試捕捉滑鼠,利用移動的距離來改變TextBlock的字體大小,執行結果像是下圖這樣 下面我們來看看測試的程式碼 Class Window1 Dim sp As StackPanel Dim tb As TextBlock Dim p As New Point Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded sp = New StackPanel tb = New TextBlock tb.Text = "Some String here" tb.Background = Brushes.AliceBlue tb.HorizontalAlignment = Windows.HorizontalAlignment.Center tb.VerticalAlignment = Windows.VerticalAlignment.Center sp.Children.Add(tb) Me.Content = sp End Sub Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Input.MouseEventArgs) MyBase.OnMouseMove(e) If e.LeftButton = MouseButtonState.Pressed Then Me.Title = e.GetPosition(sp).X &

Windows Vista SP1

等候了許久,Windows Vista SP1出爐了,快去看看吧 :) Hotfixes and Security Updates included in Windows Vista Service Pack 1 Windows Vista Service Pack 1 All Language Standalone 版

Fix-Major Error 0x80004005, Minor Error 0. Attempted to divide by zero

這篇是給自己備忘了,有用SQL Compact的朋友也可以參考看看; 原文位置: FIX: Error message when you try to delete the rows from the table in SQL Server 2005 Compact Edition or in SQL Server Compact 3.5: "Major Error 0x80004005, Minor Error 0. Attempted to divide by zero" 底下是部分原文 Hotfix information A supported hotfix is now available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next SQL Server 2005 Compact Edition service pack that contains this hotfix. To resolve this problem, submit a request to Microsoft Online Customer Services to obtain the hotfix. To submit an online request to obtain the hotfix, visit the following Microsoft Web site: http://go.microsoft.com/?linkid=6294451 (http://go.microsoft.com/?linkid=6294451)

WPF學習日誌 ~ ApplicationCommand ~

在WPF裡面有ApplicationCommand的功能可以讓我們來利用;比如說在做文字編輯的時候,會用到的剪下、貼上,等等的功能,在以往我們要撰寫一些對應的程式碼,除了功能的部分,在Enable/Disable相關的動作,我們也必須要去撰寫相關的程式碼,在WPF裡面我們可以很輕鬆的做到這些動作,你可以在執行過程中,觀看Enable/Disable的變化,對於相關的動作,我們可是沒有撰寫相關的程式碼喔,下面我們來看看測試的程式碼吧 Class Window1 Dim dp As DockPanel Dim tb As ToolBar Dim tbTray As ToolBarTray Dim txtBody As TextBox Dim btnCopy As Button Dim btnPaste As Button Dim btnCut As Button Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded dp = New DockPanel Me.Content = dp tbTray = New ToolBarTray dp.Children.Add(tbTray) DockPanel.SetDock(tbTray, Dock.Top) txtBody = New TextBox txtBody.AcceptsReturn = True txtBody.Background = Brushes.AliceBlue txtBody.VerticalScrollBarVisibility = ScrollBarVisibility.Auto dp.Children.Add(txtBody) ''設定最後加入的項目填滿剩餘的空間 dp.LastChildFill = True '&#

WPF學習日誌 ~ ToolBar ~

圖片
這篇利用簡單的程式碼來熟悉一下ToolBar的使用方式,同樣的,也利用對照的方式,做了簡單的XAML Code來讓大家對照,下面就來看看程式碼吧 Class Window1 Dim dp As DockPanel Dim tb(3) As ToolBar Dim tbTray As ToolBarTray Dim txtBody As TextBox Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded dp = New DockPanel Me.Content = dp tbTray = New ToolBarTray dp.Children.Add(tbTray) DockPanel.SetDock(tbTray, Dock.Top) txtBody = New TextBox txtBody.AcceptsReturn = True txtBody.Background = Brushes.AliceBlue txtBody.VerticalScrollBarVisibility = ScrollBarVisibility.Auto dp.Children.Add(txtBody) ''設定最後加入的項目填滿剩餘的空間 dp.LastChildFill = True For i As Integer = 0 To tb.Length - 1 tb(i) = New ToolBar ''設定ToolBar的文字,通常不使用 tb(i).Header = "TB" & i.ToString For j As Integer = 0 To 3 Dim

利用Combobox來選擇字型

圖片
Note:.net framework 2.0 , Windows Form 一般在使用Word之類的文書編輯軟體時在選擇字體的時候,可以在Combobox裡面看到字體的樣式,那在程式裡面怎麼做呢?下面我們來看看完成圖以及程式碼 不過這程式還有些問題,有些字型沒有辦法描繪,還沒有去找問題,先用try..catch去避開,參考看看嚕 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.DrawMode = DrawMode.OwnerDrawVariable Dim oneFontFamily As FontFamily For Each oneFontFamily In FontFamily.Families ComboBox1.Items.Add(oneFontFamily.Name) Next End Sub Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem Dim g As Graphics = e.Graphics Try g.DrawString(ComboBox1.Items.Item(e.Index), _ New Font(ComboBox1.Items.Item(e.Index).ToString, 10), _ Brushes.Black, e.Bounds.X, e.Bounds.Y) Catch ex As Exception End Try End Sub 相關參考 HOW TO:在 ComboBox 控制項中建立各種大小的文字 FontFamily 類別

WPF學習日誌 ~ ContextMenu ~

圖片
在 上一篇 有簡單說明一下Run的用法,這篇利用Run的範例,稍微加一點東西配合快顯功能表的介面來設定字體的樣式,執行畫面如下圖 下面是測試的程式碼 Class Window1 Dim sp As StackPanel Dim txtBlock As TextBlock Dim tmpR As Run Dim cMenu As ContextMenu Dim itemB As New MenuItem Dim itemI As New MenuItem Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded ''快顯功能表初始化 cMenu = New ContextMenu itemB = New MenuItem itemB.Header = "Bold" cMenu.Items.Add(itemB) itemI = New MenuItem itemI.Header = "Italic" cMenu.Items.Add(itemI) ''功能表事件掛載 cMenu.AddHandler(MenuItem.ClickEvent, New RoutedEventHandler(AddressOf MenuItem_Click)) sp = New StackPanel Me.Content = sp txtBlock = New TextBlock txtBlock.Height = 300 txtBlock.Width = 300 txtBlock.HorizontalAlignment = Windows.HorizontalAlignment.Center txtBlock.Ba

Run ? 這是什麼東東

圖片
在看書的過程中,好幾次看到"run"這個東西,還滿有趣的,可以將文字切割開來,而且各自擁有其對應的"事件",簡單測試一下當滑鼠移動到字的上方改變字的顏色以及大小,執行結果像是這樣 下面就來看看測試的程式碼吧 Class Window1 Dim sp As StackPanel Dim txtBlock As TextBlock Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded sp = New StackPanel Me.Content = sp txtBlock = New TextBlock txtBlock.Height = 300 txtBlock.Width = 300 txtBlock.HorizontalAlignment = Windows.HorizontalAlignment.Center txtBlock.Background = Brushes.AliceBlue txtBlock.FontSize = 32 sp.Children.Add(txtBlock) Dim strArr() As String = {"T", "H", "I", "S", " ", "A", " ", "B", "O", "O", "K"} For Each s As String In strArr Dim runTmp As New Run(s) runTmp.TextDecorations = New TextDecorationCollection

GetType().InvokeMember

在 程式執行階段,要如何判斷表單中是否存在 tooltip 這篇文章中,提問者問到要如何判斷Form裡面是不是有ToolTip,而ToolTip不包含在Controls集合中,測試了一下,不太確定這樣的做法是不是繞了遠路,大家研究看看吧 Imports System.ComponentModel Public Class Form1 Private Function HasToolTip() As Boolean If Me.components.Components Is Nothing Then Return False Else For Each c As Component In Me.components.Components If TypeName(c) = "ToolTip" Then Return True End If Next Return False End If End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show(Me.HasToolTip()) Test.CheckToolTip(Me) End Sub End Class Public Class Test Public Shared Sub CheckToolTip(ByRef frm As Object) Dim o As Object = _ frm.GetType().InvokeMember("HasToolTip", _ Reflection.BindingFlags.Instance

用"有意義"的名稱來代表常數

圖片
Note:.net framework 2.0 今天在 請問自訂引數名稱該怎麼做? 這篇文章中看到這個問題,在程式寫作過程中也會常遇到這個需求,所以給他小小的整理一下,比如說像下面這張圖 這樣會自動帶出常數名稱相當方便而且直覺,很簡單的就能知道對應代表的意義,那建立我們自己專屬的變數怎麼做呢?請參考下面這張圖

WPF學習日誌 ~ Menu ~

下面這篇我們用簡單的程式碼來測試一下Menu的功能,先來看看測試的程式碼 Imports System.Windows Imports System.IO Imports System.Reflection Class Window1 Dim dp As DockPanel Dim MotherMenu As Menu Dim LV1_Menu(4) As MenuItem Dim LV2_Menu(4) As MenuItem Dim txtBody As TextBox Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded ''初始化Content的容器 dp = New DockPanel Me.Content = dp ''實體化Menu MotherMenu = New Menu For i As Integer = 0 To 4 ''加入第一層目錄 LV1_Menu(i) = New MenuItem ''設定Menu文字 LV1_Menu(i).Header = "Menu._" & i MotherMenu.Items.Add(LV1_Menu(i)) For j As Integer = 0 To 4 ''加入第二層目錄 LV2_Menu(j) = New MenuItem LV2_Menu(j).Header = "Menu." & i & "-" & j LV1_Menu(i).Items.Add(L

GPS

這篇是之前做在Yahoo上面的一篇文章,把它移過來,免的忘記了,有需要的朋友可以參考看看 一般常用的衛星導航都會用到GPS,這裡說明一下GPS的通訊與資料的格式GPS也是利用Serial port的方式來傳遞資料,速率上一般是使用 4800,N,8,1傳輸上是單向的,也就是說我能夠收到衛星傳過來的訊息,但不能發送訊息給衛星..下面簡單說明一下協定的部份,如果須要更詳細的資料可以到以下網址參考 http://www.gpsinformation.org/dale/nmea.htm#intro - GPS NMEA Protocol -NMEA 是GPS用的標準通訊協定,傳回值是一串ASCII的字串,舉例來說可能會收到如下一串字$GPRMC,053322.682,A,2502.6538,N,12121.4838,E,0.00,315.00,080905,,,A*6F 053322.682:UTC Time , 格式是hhmmss.sss所以是5:33:22.682 A:代表資料是有效的,如果找不到衛星的話會是V 2502.6538:代表的是緯度,格式是degree * 100 + minutes。但是minutes是100進位,所以 要/100 * 60轉為degree,轉換後就是25'02'39.228''. 2502.6538 / 100 = 25.02 0.6538 * 60 = 39.228 N:代表緯度的資料是北緯 12121.4838:代表是經度,格式同緯度的部份一樣要經過轉換。 E:代表經度的資料是東經 0.00:代表的是速度,這裡因為天線沒有移動,所以是0 315.00:代表的是方向 080905:代表的是現在的日期,格式是ddmmyy再過來有兩個欄位沒有用到所以空著 A:不確定 *6F:代表的是CheckSum CheckSum(檢查碼)是以*號開頭,後面兩個Ascii字元算法如下 不包含開頭的'$',一直計算到'*'之前。一個byte一個byte的作XOR.

WPF學習日誌 ~ 選擇顏色的 ListBox ~

圖片
在以往Windows Form的應用程式中,ListBox裡面能夠放什麼呢?第一個直覺就是"字",如果要每個Item都各自擁有各自的顏色,那還要自行去處理繪製的動作,而處理繪製的動作時可能又會讓選取項目的時候失去選取項目時的"醒目提示"(背景變成藍色,表示被選取的狀態),到了WPF這樣的情形獲得很大的改善 下面這個範例所做出來的是一個選擇顏色用的ListBox,像是下面這張圖 從這個範例我們也可以看出WPF的"控制項"可塑性相當的高,下面我們就來看看程式碼吧 Imports System.Windows Imports System.IO Imports System.Reflection Class Window1 Dim sp As StackPanel Dim lstColor As ListBox Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded ''初始化用來放置Listbox的容器 sp = New StackPanel Me.Content = sp lstColor = New ListBox lstColor.Margin = New Thickness(5) lstColor.MaxHeight = 300 lstColor.MaxWidth = 300 ''Form調整大小的模式設定為內含物件的高度 Me.SizeToContent = Windows.SizeToContent.Height ''使用Reflection取得顏色相關的資料 Dim propInfo() As PropertyInfo propInfo = GetType(Colors).GetProperties For Each prop As PropertyInfo

SearchIndexer 耗損CPU資源

我的電腦是用Vista的作業系統,最近在一開機的時候CPU的使用率常態的被吃掉4x多,整個系統變的很慢,打開工作管理員一看,都是SearchIndexer.exe這隻程式..搜尋了一下,參考 SearchIndexer.exe at 99% util for over 48 hours now, system unresponsive 這篇文章,將機碼修改 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\SetupCompletedSuccessfully = 0 呼,目前看起來是OK了,繼續觀察看看..有一樣症狀的朋友可以參考看看。

Directx 相關資源

這篇是給自己備忘了,最近在找一些解決方案,有可能會用到DirectShow,找了一下相關資料,先列出來以免忘了;DircetX還是以C/C++的方式開發的屬多數,另外之前有Maneged DirectX 1.0,後來就變成XNA了,這部分之前都沒碰過,想用Managed Code來作,看來還有一些路要走啊.. http://sourceforge.net/projects/directshownet/ DirectShow http://www.shrinkwrapvb.com/ Experimental code using DirectShow with the .NET Framework 1.0

如何在Systray(系統工具列)裡面增加應用程式的圖案

這也是一個相當常見的問題,在右下角我們會看到一些常駐程式的圖形顯示在上面,那我們也辦的到嗎?可以的,而且在.net framework 2.0是很容易的 Question: 原文位置: 工作列 (Task bar)> 我開啟一個表單,然後當我按下縮小的時候 他會以我設定好的圖示出現在工作列 (Task bar)中 當我雙按滑鼠 左鍵點兩下可再度開啟 右鍵會出現一個選單可以讓我選擇關閉 這樣的功能ShowInTaskbar,NotifyIcon 我該如何做呢? 下面是參考的程式碼 Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize Application.DoEvents() If Me.WindowState = FormWindowState.Minimized Then Me.Hide() NotifyIcon1.Visible = True NotifyIcon1.ShowBalloonTip(1000) NotifyIcon1.Text = "12345" End If End Sub 相關參考 NotifyIcon 範例 NotifyIcon 元件 (Windows Form)

Graphics.SetClip 方法

Note:.net framework v2.0 今天看討論區的這篇文章 請問如何把DrawImageUnscaled畫出來的東西放到剪貼簿呢? ,看到提問者用了SetClip的方法,之前沒用過,於是乎到MSDN查詢了一下,將用法整理如下,大家可以參考看看,程式碼部分是直接用MSDN上面的範例 SetClip的作用是限定繪圖的區域,可以參考一下下面網頁 http://msdn2.microsoft.com/zh-tw/library/ms142116(VS.80).aspx 依照範例程式碼建立新的Windows Form應用程式之後,貼上下面程式碼來測試 Public Class Form1 Public Sub SetClipGraphicsCombine(ByVal e As PaintEventArgs) ' Create temporary graphics object and set its clipping region. Dim newGraphics As Graphics = Me.CreateGraphics() newGraphics.SetClip(New Rectangle(0, 0, 100, 100)) ' Update clipping region of graphics to clipping region of new graphics. e.Graphics.SetClip(newGraphics, Drawing2D.CombineMode.Replace) ' Fill rectangle to demonstrate clip region. e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, 500, 300) ' Release new graphics. newGraphics.Dispose() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Win

Managed Direct3D Mobile Samples

今天在找一些資料的時候看到了一些sample以及參考資料,把相關的連結貼出來,免的忘了,有興趣的朋友可以一起參考看看 Managed Direct3D Mobile Samples 原文內提到的相關連結列在下面 Direct3D Mobile Billboard Sample Shows how to perform billboarding to draw trees. Direct3D Mobile Fixed Point Billboard Sample Shows how to perform billboarding to draw trees using fixed point math. Direct3D Mobile Create Device Sample Provides a tutorial for creating a Direct3D device and using it to clear the window. Direct3D Mobile Fractal Sample Shows how to use fractals to generate and display height map. Direct3D Mobile Fixed Point Fractal Sample Shows the fractal sample converted to use fixed point math. Direct3D Mobile Lighting Sample Provides a tutorial on how to use lighting. Direct3D Mobile Fixed Point Lighting Sample Shows how to, using fixed point math, make moving directional and point lights. Direct3D Mobile Lights Sample Shows how to make moving directional and point lights. Direct3D Mobile Matrices Sample This sample provides a tutorial on how to use matrix transfo

文章推薦 [黑暗執行緒 Windows Form UI優化入門課–非同步作業]

今天在看 黑暗執行緒 ,看到了這邊文章 Windows Form UI優化入門課 – 非同步作業 ,其中文章下載的部分可以下載一個PDF檔來看,看過之後真的很不錯,對於BackgroundWorker或是非同步作業還不是很熟悉的朋友一定要去看看~強力推薦~

WPF學習日誌 ~ Grid ~

Grid這個"容器"相較之前的容器來看,顯的比較複雜一些,需要設定的東西比較多,下面用簡單的程式碼展示一下基本的功能,希望大家對於Grid能有一些基本的了解 Dim gd As Grid Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded gd = New Grid Me.Title = "Grid Test" ''設定Form的大小跟Content的長、寬是一樣的 Me.SizeToContent = Windows.SizeToContent.WidthAndHeight Me.Content = gd ''為了方面觀看變化,我們把隔線設定為顯示 gd.ShowGridLines = True ''為了範例需要我們把新增欄、列的新增跟按鈕的新增分開處理 For iRow As Integer = 0 To 4 ''新增Grid的列 Dim rd = New RowDefinition If iRow = 4 Then ''最後一列為了展示跨越欄位的button,這邊做特殊設定 ''可以自行修改看看GridUnitType的部分看看有什麼不同 rd.Height = New GridLength(100, GridUnitType.Star) Else rd.Height = GridLength.Auto End If gd.RowDefinitions.Add(rd) Next For iCol As Inte

WPF學習日誌 ~ DockPanel ~

打鐵要趁熱,下面這篇我們繼續看看DockPanel的部分,從名稱上可以看出這跟之前VS2005我們設定控制項的Dock屬性的感覺滿像的,沒錯,大致上是這樣的,下面我們看看測試的程式碼吧 Dim dp As DockPanel Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded dp = New DockPanel Me.Title = "DockPanel Test" Me.Content = dp For z As Integer = 0 To 3 Dim btn As New Button btn.Name = "Button" & z btn.Content = "Button_" & z DockPanel.SetDock(btn, z) dp.Children.Add(btn) ''設定最後加入的元素是否要填滿剩下的空間 dp.LastChildFill = False Next End Sub 比較特別的地方是設定Dock的位置的時候我們是呼叫DockPanel的靜態方法SetDock,不是用"執行個體dp"去設定Dock喔。

變更目前的工作目錄

這邊是在討論區看到的,相關問題的詢問次數也不少,大家可以參考看看 Question - 原文 OpenFileDialog 的問題 有兩個按鈕,A與B,按A可以執行主程式旁邊的一個副程式,裡頭的CODE大概像這樣: Dim MyProcess As New System.Diagnostics.Process MyProcess.StartInfo.FileName = "副程式.exe" MyProcess.Start() 按B會跳出OpenFileDialog,讓使用者選擇檔案如果說,先按A再按B,沒問題。 但是,如果先按B再按A,就會出現錯誤(找不到副程式.exe),因為使用OpenFileDialog好像會更改的預設執行目錄。想請問大大,這個預設執行目錄的設定放在哪丫? 這問題主要是因為當你用"相對路徑"的時候要特別注意,由上面題目看起來,主、副程式應該都是在同一個資料夾內,而如果先有了OpenFileDialog的動作的話,由於工作目錄被變更了,所以產生了找不到檔案的問題。 那應該如何處理呢?下面這個是用Process類別時我比較建議的方式,程式碼如下 Dim p As New Process p.StartInfo.UseShellExecute = True p.StartInfo.WorkingDirectory = Application.StartupPath p.StartInfo.FileName = "副程式.exe" p.Start() 相關參考 ProcessStartInfo.WorkingDirectory 屬性

WPF學習日誌 ~ WrapPanel ~

這篇我們來測試一下第二個"容器",WrapPanel,它是怎麼來幫我們做排版的動作呢? 千言萬語勝不過按一下"F5",讓我們直接瞧瞧程式碼吧 Dim wp As WrapPanel Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded Dim wp As New WrapPanel wp.Background = Brushes.AliceBlue Me.Title = "Test WrapPanel" Me.Content = wp For z As Integer = 0 To 25 Dim btn As New Button btn.Name = "Button" & z btn.Content = "Button _" & Chr(&H41 + z) btn.VerticalAlignment = Windows.VerticalAlignment.Center btn.HorizontalAlignment = Windows.HorizontalAlignment.Center AddHandler btn.Click, AddressOf Button_Click wp.Children.Add(btn) Next End Sub Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) MessageBox.Show(CType(e.Source, Button).Content.ToString) End Sub 執行程式之後去改變視窗的大小,之後就可以看到W

Microsoft DreamSpark

在 Welcome to Microsoft DreamSpark 提到,如果你是學生的話,可以申請免費使用VS2008 pro,Windows Server 2003 std,等其他產品,免費的喔,不過目前還沒有台灣....目前只有下面這些 We are kicking this off in 11 countries/regions, giving DreamSpark to millions of students in the United States, the United Kingdom, Canada, China, Germany, France, Finland, Spain, Sweden, Switzerland and Belgium. If you are not residing in one of the countries listed keep checking back, we will be adding more countries throughout the year. 持續關注吧,相信將來應該會有的,來個全民公投好了, "您是否支持MicroSoft將台灣加入DreamSpark計畫中呢?" 選項一:支持 選項二:一定要的 算了,很冷...還是打程式去~ PS:這篇沒有任何政治立場,請勿做過多的聯想..( 最近很敏感啊~ =.=" )

Hotfix available for VB performance issue in VS2008

在Visual Basic Team的Blog上面發布了這篇文章, Hotfix available for VB performance issue in VS2008 ,節錄部分原文如下 Details The hotfix is a 3.98MB download and can be found at: http://support.microsoft.com/kb/946344 It addresses performance issues in the following scenarios: • The IDE takes a long time to build/rebuild the solution. • You experience a slow response time when you press F5 to start debugging. • You experience a slow response time in the Code Editor. • You experience a slow response time in IntelliSense. 如果你用遇到上述問題的話可以下載Hotfix來作修正,要注意的是沒有上述問題的話可別亂裝,要注意看說明,有些Hotfix因為沒有跟其他東西做很完整的相容性測試,不保證不會出現其他的"靈異現象"喔,這部分說明上會特別提及,要注意看。

WPF學習日誌 ~ 3DTools ~

Note:本篇開發工具使用VS2008,.net framework版本3.5 雖然XAML Code還不會但是還是很想嘗試看看WPF 3D的功能,在WIndowsClient看了 Building an Interactive 3D Video Player 的範例,實在是手很癢..於是乎就照著範例測試了一下,不過其中播放影片的那個UserControl的XAML Code我沒有阿..殘念,沒關係,我用老朋友Button來測試,嘿嘿.. 首先要到 CodePlex 下載3DTools的Dll檔,上面有bin(編譯好的),或是scr(未編譯的),看你是想要用哪一種,檔案準備好了之後,把它加到我們專案的參考進來,下面我們就看看XAML Code吧 很奇怪,我把xmal code貼上之後,畫面出不來,會跑出一個button..真是太神奇了 之接到這邊 下載VS2008的專案檔 來看吧 執行程式之後,你可以按著滑鼠左鍵,然後移動滑鼠(嘿嘿..我的button會旋轉耶..),或是右鍵,可以拉近拉遠,很炫吧。 其中我們看看下面這幾行 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Inter3D="clr-namespace:_3DTools;assembly=3DTools" 上面兩行是預設引入的,Inter3D是加上去的,這感覺像是引入(Imports)命名空間的感覺,有加進來的話才會有相關功能可以用,好啦,不多說了,馬上動手去測試看看吧。 另外Button的部分我們也可以改成下面這樣,也可以放影片喔

WPF學習日誌 ~ StackPanel ~

前面我們測試過幾篇有關WPF的應用程式,不知道有沒有發現,我們沒有辦法指定兩個以上的東西(物件)給Content屬性,WIndow的COntent、Button的Content等等,那怎麼辦呢?總不能用來用去都是使用一個東東而已吧..所以接下來我們要測試一些有關"容器"的部分,在WPF中有下面幾種容器 StackPanel WrapPanel DockPanel Grid Cancas ,這篇只會提到StackPanel的部分,有興趣的朋友可以先自行測試看看,或是到MSDN去看看相關細節;好,下面來看看測試的程式碼吧 Dim sp As StackPanel Dim rnd As Random Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded rnd = New Random() sp = New StackPanel sp.Background = Brushes.AliceBlue Me.Content = sp For i As Integer = 1 To 9 Dim btn = New Button btn.Name = "Button" & i btn.FontFamily = New FontFamily("Consola") Randomize() btn.FontSize = rnd.Next(10, 25) ''用 "_" 設定當按下"alt"按鍵時出現的"快速鍵提示字" btn.Content = "Button No._" & i ''設定按鈕間的間隔 btn.Margin

WindowsClient.net

下面這邊有個學習WPF,windows Form的相關學習資源,有一些Vedio可以看,對於這方面有興趣的朋友,千萬別錯過了,戴好耳機,抓緊滑鼠,咱們出發啦~ WindowsClient.net

WPF學習日誌 ~ 變換Form的背景圖 ~

Note:本篇工具使用VS2008,.Net framework版本3.5 這篇功能測試是每秒會變換Form的背景圖片,話先說在前頭,這篇單純的只是熟悉一下WPF相關物件的使用方式,不會看到WPF的"特異功能",單就功能上來看VS2005也是很輕易的可以完成的。 首先,有些東西要了解一下,像是WPF中並沒有直接提供Timer的控制項,那怎麼做呢?請參考下面這篇 請教WPF form沒有Timer元件了嗎?? 好,下面我們來看看程式碼吧 ''宣告Timer物件 Dim myT As Threading.DispatcherTimer ''宣告Image物件 Dim img As Image Dim B As BitmapImage Dim ImagePath() As String Dim Count As Integer = 0 Dim u As Uri Dim R As New Random Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded ''設定標題列文字 Me.Title = "WPF Text" ''取得圖片檔案路徑 ImagePath = IO.Directory.GetFiles("D:\圖檔\JPG\App") u = New Uri(ImagePath(0)) B = New BitmapImage B.BeginInit() B.UriSource = u B.EndInit() img = New Image img.Source = B img.Stretch = Stretch.UniformToFill Me.Content = img ''

利用"連結的伺服器"在兩個SQL Server中交換資料

圖片
在使用資料庫的時候當資料庫有多個的時候,要彼此交換資料是一個滿麻煩的事情,用複製、貼上的話在Management studio中又要跑滿久的,下面這個方式提供給大家參考看看 首先一樣開啟Management Studio,登入其中一台SQL Server,之後展開"伺服器物件",這時候可以看到"連結的伺服器",在上面點選右鍵,選擇新增之後會看到如下畫面 在"連結的伺服器"這個地方要打的就是我們另一個SQL Server的主機位置了,要注意的是這裡打的是IP位置或是打電腦名稱的話會影響我們待會要下的SQL指令,這個要注意一下;設定好"一般"頁面的參數之後要再設定"安全性"的參數,如下圖 這邊我是設定用sa的帳號去做登入,設定好之後按下確定。 這樣新增完連結的伺服器之後,想要把B-Server的某一個Table的資料完全的複製到A-Server的話,可以在A-Server用"新增查詢"的功能執行下面的SQL指令 Select * into [A-Server].DataBaseName.dbo.tmpTable from [B-Server].DataBaseName.dbo.TableName 其他的部分就自行嘗試看看嚕~

Making PInvoke Easy

圖片
今天在瀏覽 The Visual Basic Team 的Blog時,看到了下面這篇 Making PInvoke Easy ,其中提到一個工具(CLRInsideOut2008_01.exe)能夠幫助我們取得API的宣告方式,比如說要看CreateFile是怎麼宣告的,我抓了下面這張圖 是不是很方便呢?到 原文位置 了解更多吧 ~ 下載CLRInsideOut2008_01.exe解壓縮後裡面也會有使用說明文件喔 ~