最前面的話:Smobiler是一個在VS環境中使用.Net語言來開發APP的開發平台,也許比Xamarin更方便
一、目標樣式
我們要實現上圖中的效果,需要如下的操作:
1.從工具欄上的”Smobiler Components”拖動一個MicroBlog控件到窗體界面上
2.用代碼添加手機界面上顯示的內容
Load事件代碼:
VB:
Private Sub TestMicroBlog_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try Me.MicroBlog1.DefaultUserName = "偉斌" Me.MicroBlog1.DefaultUserID = "偉斌" contentArray(0) = "把青春獻給身後那座"+ vbCrLf + "輝煌的城市" + vbCrLf + "為了這個美夢" + vbCrLf + "我們付出著代價" userarray(0) = "偉斌" picturearray(0) = 0 InitialMicroBlogData() Catch ex As Exception MessageBox.Show(ex.Message, Sub() Me.Close()) End Try End Sub C#: private void TestMicroBlog_Load(object sender, EventArgs e) { try { this.MicroBlog1.DefaultUserName = "偉斌"; this.MicroBlog1.DefaultUserID = "偉斌"; contentArray[0] = "把青春獻給身後那座" + System.Environment.NewLine + "輝煌的城市" + System.Environment.NewLine + "為了這個美夢"+ System.Environment.NewLine + "我們付出著代價"; userarray[0] = "偉斌"; picturearray[0] = "0"; InitialMicroBlogData(); } catch (Exception ex) { MessageBox.Show(ex.Message, (Object s, MessageBoxHandlerArgs args) => this.Close()); } }
其他代碼:
VB:
Dim contentArray(4) As String Dim userarray(4) As String Dim picturearray(8) As String Dim voice(5) As String Private Sub InitialMicroBlogData(Optional count As Integer = 10, Optional ByVal insert As Boolean = False) Dim user As String = userarray(0) Dim picturerandomnum As Integer = 6 Dim imageList As New List(Of String) imageList.Add(6) Dim item As New MicroBlogItem(user, user, contentArray(0), DateTime.Now.ToString) item.Pictures = imageList item.ILikes.Add(userarray(0), userarray(0)) If insert = False Then Me.MicroBlog1.BlogItems.Add(item) Else Me.MicroBlog1.BlogItems.AddTop(item) End If Next End Sub C#: string[] contentArray = new string[5]; string[] userarray = new string[5]; string[] picturearray new string[9]; string[] voice = new string[6]; private void InitialMicroBlogData(int count = 10, bool insert = false) { string user = userarray[0]; List<string> imageList = new List<string>(); imageList.Add("6"); MicroBlogItem item = new MicroBlogItem(user, user, contentArray[0], DateTime.Now.ToString()); item.Pictures = imageList; item.ILikes.Add(userarray[0], userarray[0]); if (insert == false) { this.MicroBlog1.BlogItems.Add(item); } else this.MicroBlog1.BlogItems.AddTop(item); } }
二、手機效果顯示
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持幫客之家。