How to make Twitter Ultimate v1.0 Beta for CnS Destop
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
1 post
Page 1 of 1
How to make Twitter Ultimate v1.0 Beta
Add-in for Cns Desktop
--------------------------------------------------------
Visual Basic 2008 Express Edition
First you need to download the TwitterVB Library. You can do this from the url below.
Download TwitterVB
http://twittervb.codeplex.com/
Then if you dont know how to create a Class Library for the CnS Desktop Add-Ins,
The link below will help you with that.
How To make Add-Ins
viewtopic.php?f=106&t=1118
This is the original artical for the Twitter Ultimate v1.0 BETA along with ScreenShots.
viewtopic.php?f=106&t=1199
--------------------------------------------------------
Lets get started.
Fire up VB 2008 EE,
Create a New Class Library add a UserControl.
Add 2 Settings
Username - string - user
Password - string - user
UserControl1 Properties
Size: 970,454
Add 1 Timer to the UserControl1
Add 2 Panels
Panel1
Name: PanelNewUser
BackColor: AliceBlue
BorderStyle: None
Dock: Fill
--------------------------------------------------------
Add to PanelNewUser
-PictureBox1
Name: PictureBox1
Anchor: Top
BackColor: Transparent
BackGroundImage: None
Image: (My.Resources)
Location: 178,12
Size: 141,138
-Panel1
Name: Panel1
Anchor: Top
Backcolor: SkyBlue
BorderStyle: Fixed3D
Location: 302,143
Size: 360,160
Add to Panel1
4 Labels
Label1: "Please enter your Twitter account information"
Label2: "Username"
Label3: "Password"
Label4:
Name: lblNoUser
Text: "User Does Not Exist! + vbNewLine + Please try again!"
2 TextBox
TextBox1
Name: txtUsername
ApplicationSetting: Text - Username
TextBox2
Name: txtPassword
ApplicationSetting: Text - Password
1 Button
Name:BUtton1
Text: Sign In
--------------------------------------------------------
Panel2
Name: PanelIsUser
BackColor: AliceBlue
BorderStyle: None
Dock: Fill
Add to Panel2
2 ListBox2
ListBox1
Name: lstFollowers
Anchor: Top
Border: Fixed3D
Location: 17,17
Size: 150,420
ListBox2
Name: lstTimeLine
Anchor: Top
Border: Fixed3D
Location: 173,17
Size: 785,308
2 PictureBox
PictureBox1
Name: PBUserImage
Anchor: Top
Location: 181,350
Size: 75,75
PictureBox2
Nmae: PBLargeText
Anchor: Top
Location: 703,331
Size: 29,33
1 GroupBox
Name: GroupBox1
Anchor: Top
Location: 273,337
Size: 424,100
Text: "Information Center"
4 LinkLabels
LinkLabel1
Name: LinkLabel1
Anchor: Top
Location: 801,337
TExt: Read My Latest Status
LinkLabel2
Name: LinkLabel2
Anchor: Top
Location: 801,353
TExt: Update My Status
LinkLabel3
Name: LinkLabel3
Anchor: Top
Location: 36,437
TExt: Reset for New User
LinkLabel4
Name: LLUpdate
Anchor: Top
Location: 362,81
Text: Update
1 CheckBox
Name: CBCnSBrowser
Anchor: Top
CheckState: Checked
Location: 18,76
Text: Use CnS Browser for Status Links
1 RichTextBox
Name: RTBStatus
Anchor: Top
Location: 252,70
Size: 30,27
1TextBox
Name: txtStatus
Anchor: Top
Location: 288,78
MultiLine: True
Size: 23,19
--------------------------------------------------------
OK. The above setup up the starting values for Panel1 and Panel2
Now for the code behind
Imports
UserControl_Load Event
Button1_Click
Now create a Public Sub GetMyFreinds
SO far this is what is going on. When you first run the Add-In. You come to the Sign In
Panel. If this is the first time. Your Username and Password will be saved.
If you have an account Panel1 will be hiden and Panel2 will show. If you DO NOT have
a account. lblNoUser will be shown.
OK. Your LogIn was good.
Panel2 - PanelIsUser
lstFollowers:
Add-in for Cns Desktop
--------------------------------------------------------
Visual Basic 2008 Express Edition
First you need to download the TwitterVB Library. You can do this from the url below.
Download TwitterVB
http://twittervb.codeplex.com/
Then if you dont know how to create a Class Library for the CnS Desktop Add-Ins,
The link below will help you with that.
How To make Add-Ins
viewtopic.php?f=106&t=1118
This is the original artical for the Twitter Ultimate v1.0 BETA along with ScreenShots.
viewtopic.php?f=106&t=1199
--------------------------------------------------------
Lets get started.
Fire up VB 2008 EE,
Create a New Class Library add a UserControl.
Add 2 Settings
Username - string - user
Password - string - user
UserControl1 Properties
Size: 970,454
Add 1 Timer to the UserControl1
Add 2 Panels
Panel1
Name: PanelNewUser
BackColor: AliceBlue
BorderStyle: None
Dock: Fill
--------------------------------------------------------
Add to PanelNewUser
-PictureBox1
Name: PictureBox1
Anchor: Top
BackColor: Transparent
BackGroundImage: None
Image: (My.Resources)
Location: 178,12
Size: 141,138
-Panel1
Name: Panel1
Anchor: Top
Backcolor: SkyBlue
BorderStyle: Fixed3D
Location: 302,143
Size: 360,160
Add to Panel1
4 Labels
Label1: "Please enter your Twitter account information"
Label2: "Username"
Label3: "Password"
Label4:
Name: lblNoUser
Text: "User Does Not Exist! + vbNewLine + Please try again!"
2 TextBox
TextBox1
Name: txtUsername
ApplicationSetting: Text - Username
TextBox2
Name: txtPassword
ApplicationSetting: Text - Password
1 Button
Name:BUtton1
Text: Sign In
--------------------------------------------------------
Panel2
Name: PanelIsUser
BackColor: AliceBlue
BorderStyle: None
Dock: Fill
Add to Panel2
2 ListBox2
ListBox1
Name: lstFollowers
Anchor: Top
Border: Fixed3D
Location: 17,17
Size: 150,420
ListBox2
Name: lstTimeLine
Anchor: Top
Border: Fixed3D
Location: 173,17
Size: 785,308
2 PictureBox
PictureBox1
Name: PBUserImage
Anchor: Top
Location: 181,350
Size: 75,75
PictureBox2
Nmae: PBLargeText
Anchor: Top
Location: 703,331
Size: 29,33
1 GroupBox
Name: GroupBox1
Anchor: Top
Location: 273,337
Size: 424,100
Text: "Information Center"
4 LinkLabels
LinkLabel1
Name: LinkLabel1
Anchor: Top
Location: 801,337
TExt: Read My Latest Status
LinkLabel2
Name: LinkLabel2
Anchor: Top
Location: 801,353
TExt: Update My Status
LinkLabel3
Name: LinkLabel3
Anchor: Top
Location: 36,437
TExt: Reset for New User
LinkLabel4
Name: LLUpdate
Anchor: Top
Location: 362,81
Text: Update
1 CheckBox
Name: CBCnSBrowser
Anchor: Top
CheckState: Checked
Location: 18,76
Text: Use CnS Browser for Status Links
1 RichTextBox
Name: RTBStatus
Anchor: Top
Location: 252,70
Size: 30,27
1TextBox
Name: txtStatus
Anchor: Top
Location: 288,78
MultiLine: True
Size: 23,19
--------------------------------------------------------
OK. The above setup up the starting values for Panel1 and Panel2
Now for the code behind
Imports
Code: Select all
Imports System.Text
Imports System.Windows.Forms.VisualStyles.VisualStyleElement
Imports TwitterVB2
Imports System.Net
Imports System.IO
Imports System.Drawing
Code: Select all
'* Panel1 - PanelNewUserPublic Class UserControl1
Dim TUser As String = My.Settings.Username
Dim TPass As String = My.Settings.Password
Public Update2 As String = "http://@twitter.com/statuses/update.xml"
UserControl_Load Event
Code: Select all
----------- Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtStatus.Visible = False
RTBStatus.Visible = False
CBCnSBrowser.Visible = False
LLUpdate.Visible = False
lblNoUser.Visible = False
lblNoUser.Location = New System.Drawing.Point(23, 123)
If txtUsername.Text = "" Or txtPassword.Text = "" Then
Button1.Enabled = False
Else
Button1.Enabled = True
End If
PanelNewUser.BackgroundImage = My.Resources.bgclouds
PanelNewUser.BackgroundImageLayout = Windows.Forms.ImageLayout.None
PanelIsUser.BackgroundImage = My.Resources.bgclouds
PanelIsUser.BackgroundImageLayout = Windows.Forms.ImageLayout.None
ToolTip1.ShowAlways = True
ToolTip1.ReshowDelay = 10
ToolTip1.AutomaticDelay = 150
ToolTip1.IsBalloon = True
ToolTip1.UseAnimation = True
ToolTip1.UseFading = True
ToolTip1.SetToolTip(PBLargeText, "Increase Text Size")
End Sub
Button1_Click
Code: Select all
---------- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txtUsername.Text = "" Or txtPassword.Text = "" Then
MsgBox("Please Fillout your Twitter Information")
Else
Try
GetMyFreinds()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
End Sub
Now create a Public Sub GetMyFreinds
Code: Select all
Create a new Public Sub GetTLPanel
Public Sub GetMyFreinds()
Try
' Get an instance of the Twitter class and authenticate
Dim tw As New TwitterVB.Twitter
tw.AuthenticateAs(txtUsername.Text, txtPassword.Text)
' Create a List of TwitterUser objects
Dim MyFriends As List(Of TwitterVB.TwitterUser) = tw.UserMethods.Friends
' Iterate through the list and add the names to the listbox
For Each User As TwitterVB.TwitterUser In MyFriends
Me.lstFollowers.Sorted = True
Me.lstFollowers.Items.Add(User.ScreenName)
Next
GetTLPanel()
My.Settings.TUser = txtUsername.Text
My.Settings.TPass = txtPassword.Text
My.Settings.Save()
Catch ex As Exception
txtUsername.Text = ""
txtPassword.Text = ""
lblNoUser.Visible = True
End Try
End Sub
Code: Select all
-------------------------------------------------------- Public Sub GetTLPanel()
PanelNewUser.Visible = False
PanelNewUser.SendToBack()
PanelIsUser.Visible = True
PanelIsUser.BringToFront()
PanelIsUser.Dock = Windows.Forms.DockStyle.Fill
lstFollowers.Location = New System.Drawing.Point(17, 17)
lstFollowers.Size = New System.Drawing.Size(150, 420)
End Sub
SO far this is what is going on. When you first run the Add-In. You come to the Sign In
Panel. If this is the first time. Your Username and Password will be saved.
If you have an account Panel1 will be hiden and Panel2 will show. If you DO NOT have
a account. lblNoUser will be shown.
OK. Your LogIn was good.
Panel2 - PanelIsUser
lstFollowers:
Code: Select all
SO here when the Add-In loads. It will show a list of everyone that is following you. From here you can click on a name to see there Statuses. Private Sub lstFollowers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFollowers.SelectedIndexChanged
lstTimeLine.Items.Clear()
GetUserTimelineWithParameters()
End Sub
Code: Select all
Public Sub GetUserTimelineWithParameters()
Dim tw As New TwitterAPI
tw.AuthenticateAs(Username, Password) 'OR tw.AuthenticateAs(txtUsername.Text, txtPassword.Text)
' Specify that we want 50 statuses instead of the default 20
Dim tp As New TwitterParameters
tp.Add(TwitterParameterNames.Count, lstFollowers.SelectedItem)
tp.Add(TwitterParameterNames.ScreenName, lstFollowers.SelectedItem)
For Each status As TwitterStatus In tw.UserTimeline(tp)
lstTimeLine.Items.Add(status.CreatedAt & ": " & status.Text)
PBUserImage.Load(status.User.ProfileImageUrl.ToString)
PBUserImage.SizeMode = Windows.Forms.PictureBoxSizeMode.StretchImage
GroupBox1.Text = status.User.Name & " Twitter Information"
lblDescription.Text = status.User.Description
RTBStatus.Tag = status.User.Url
If RTBStatus.Visible = True Then
RTBStatus.Visible = False
CBCnSBrowser.Visible = False
lblDescription.Visible = True
End If
Next
End Sub
Code: Select all
Public Sub GetMyTimeline()
Dim tw As New TwitterAPI
tw.AuthenticateAs(Username, Password) 'OR tw.AuthenticateAs(txtUsername.Text, txtPassword.Text)
' Specify that we want 50 statuses instead of the default 20
Dim tp As New TwitterParameters
tp.Add(TwitterParameterNames.Count, TUser)
tp.Add(TwitterParameterNames.ScreenName, TUser)
For Each status As TwitterStatus In tw.UserTimeline(tp)
lstTimeLine.Items.Add(status.Text)
PBUserImage.Load(status.User.ProfileImageUrl.ToString)
PBUserImage.SizeMode = Windows.Forms.PictureBoxSizeMode.StretchImage
GroupBox1.Text = status.User.Name & " Twitter Information"
lblDescription.Text = status.User.Description
Next
End Sub
Code: Select all
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
lstTimeLine.Items.Clear()
If txtStatus.Visible = True Then
LLUpdate.Visible = False
txtStatus.Visible = False
End If
Try
GetMyTimeline()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Code: Select all
Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
GroupBox1.Text = "Update Status"
lblDescription.Text = ""
LLUpdate.Visible = True
txtStatus.Visible = True
txtStatus.Location = New System.Drawing.Point(18, 19)
txtStatus.Size = New System.Drawing.Size(386, 49)
RTBStatus.Visible = False
CBCnSBrowser.Visible = False
End Sub
Code: Select all
Public Function PostStatus(ByVal status As String) As String
Dim ret As String
Dim req As WebRequest = HttpWebRequest.Create(Update2)
System.Net.ServicePointManager.Expect100Continue = False
req.Credentials = New NetworkCredential(TUser, TPass)
req.ContentType = "application/x-www-form-urlencoded"
req.Method = "POST"
Dim encoding As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding()
Dim bt() As Byte = encoding.GetBytes(String.Format("status={0}", status))
Dim s As Stream
Try
req.ContentLength = bt.Length
s = req.GetRequestStream()
s.Write(bt, 0, bt.Length)
Catch ex As Exception
Throw ex
End Try
Try
'returns raw xml
Dim res As WebResponse = req.GetResponse()
If res Is Nothing Then
Return Nothing
End If
Dim sr As StreamReader = New StreamReader(res.GetResponseStream())
ret = sr.ReadToEnd().Trim()
sr.Close()
Catch ex As Exception
Throw ex
End Try
Return ret
End Function
Code: Select all
Private Sub LLUpdate_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LLUpdate.LinkClicked
PostStatus(txtStatus.Text)
GroupBox1.Text = ""
lblDescription.Text = "Status has been Updated!"
LLUpdate.Visible = False
txtStatus.Visible = False
Timer1.Enabled = True
Timer1.Interval = 1500
Timer1.Start()
End Sub
Code: Select all
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
GroupBox1.Text = "Information Center"
lblDescription.Text = "Description"
Timer1.Stop()
End Sub
Code: Select all
Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
My.Settings.TUser = ""
My.Settings.TPass = ""
My.Settings.Save()
MsgBox("You must restart the CnS Browser for the changes to take effect!")
End Sub
Code: Select all
Private Sub txtPassword_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyUp
If txtUsername.Text = "" Or txtPassword.Text = "" Then
Button1.Enabled = False
Else
Button1.Enabled = True
End If
End Sub
Code: Select all
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PBLargeText.Click
Dim fnt As Drawing.Font
fnt = lstTimeLine.Font
lstTimeLine.Font = New Drawing.Font(fnt.Name, 12, FontStyle.Regular)
End Sub
Code: Select all
Private Sub lstTimeLine_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTimeLine.SelectedIndexChanged
RTBStatus.Visible = True
RTBStatus.Location = New System.Drawing.Point(18, 19)
RTBStatus.Size = New System.Drawing.Size(386, 52)
RTBStatus.Text = lstTimeLine.SelectedItem.ToString()
CBCnSBrowser.Visible = True
End Sub
Code: Select all
Private Sub RTBStatus_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkClickedEventArgs) Handles RTBStatus.LinkClicked
If CBCnSBrowser.Checked = True Then
SlotAddIn.Interaction.GoURL(RTBStatus.Tag.ToString)
Else
System.Diagnostics.Process.Start(e.LinkText)
End If
End Sub
Code: Select all
End Class
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023