Question How can i add a event.

matt1234hi5

Member
Joined
May 13, 2008
Messages
12
Programming Experience
1-3
hello everyone.

VB.NET:
Dim id As String = timeline(poo).Status.Id.ToString
        Dim tweet_pic = New System.Windows.Forms.PictureBox
        Dim tweet_text_panel = New System.Windows.Forms.Panel
        Dim tweet_text = New System.Windows.Forms.RichTextBox
        Dim tweet_holder = New System.Windows.Forms.Panel
        Dim Button3 = New System.Windows.Forms.Button
        '
        'twit_1_pic
        '
        tweet_pic.ImageLocation = timeline(poo).ProfileImageUrl.ToString
        tweet_pic.Location = New System.Drawing.Point(0, 0)
        tweet_pic.Name = "twit_" & timeline(poo).Status.Id & "_pic"
        tweet_pic.Size = New System.Drawing.Size(48, 48)
        tweet_pic.TabIndex = 1
        tweet_pic.TabStop = False
        '
        'twit_1_text_panel
        '
        tweet_text.BorderStyle = BorderStyle.None
        tweet_text_panel.BackColor = System.Drawing.Color.Transparent
        tweet_text_panel.BackgroundImage = Global.twitterer3.My.Resources.Resources.speech
        tweet_text_panel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None
        tweet_text_panel.Controls.Add(tweet_text)
        tweet_text_panel.Location = New System.Drawing.Point(48, 0)
        tweet_text_panel.Name = "twit_" & timeline(poo).Status.Id & "_text_panel"
        tweet_text_panel.Size = New System.Drawing.Size(274, 48)
        tweet_text_panel.TabIndex = 0
        '
        'twit_1_text
        '
        tweet_text.ReadOnly = True
        tweet_text.BackColor = Color.Black
        tweet_text.ForeColor = System.Drawing.Color.White
        tweet_text.Location = New System.Drawing.Point(12, 2)
        tweet_text.Name = "twit_" & timeline(poo).Status.Id & "_text"
        tweet_text.Size = New System.Drawing.Size(260, 40)
        tweet_text.TabIndex = 0
        tweet_text.Text = timeline(poo).ScreenName.ToString & ": " & phrasehtml(timeline(poo).Status.Text)
        '
        'Button 3
        '
        Button3.BackgroundImage = Global.twitterer3.My.Resources.Resources.__copy
        Button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center
        Button3.FlatAppearance.BorderSize = 0
        Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Button3.Location = New System.Drawing.Point(322, 24)
        Button3.Name = "reply_button_" & timeline(poo).Status.Id
        Button3.Size = New System.Drawing.Size(24, 24)
        Button3.TabIndex = 4
        Button3.UseVisualStyleBackColor = True

        '
        'twit_1_holder
        '
        tweet_holder.Controls.Add(tweet_text_panel)
        tweet_holder.Controls.Add(tweet_pic)
        tweet_holder.Controls.Add(Button3)
        tweet_holder.Location = New System.Drawing.Point(0, ((((tweets_holder.VerticalScroll.Value) - tweets_holder.VerticalScroll.Value) - tweets_holder.VerticalScroll.Value) - 48))
        tweet_holder.Name = "twit_" & timeline(poo).Status.Id & "_holder"
        tweet_holder.Size = New System.Drawing.Size(346, 48)
        tweet_holder.TabIndex = 2
        tweet_holder.Parent = Me.tweets_holder
        tweet_text_panel.SuspendLayout()
        tweet_holder.SuspendLayout()
        tweet_pic.SuspendLayout()
        tweet_text.SuspendLayout()
        Button3.SuspendLayout()
        tweets.Add(timeline(poo).Status.Id)

There is my code, in that I am make a Button 3. Lets say I want to attach an event to that, but also pass a user name variable to the event. How would I do that?
 
The quickest way to add an event would be to use the design view - select the button on the form and then in properties panel click on the "lightening" button on the top of the properties panel to reveal the events, then double click on the event required and the event will be automatically created for you. You also need to declare the variable somewhere in the class
public class eurojenform
Dim username
'EVENT CODE'
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3_btn.Click

username = "eurojen"


End Sub


Hope that helps


Jen
 
You could inherit eventargs, make your own, and pass that... but you may have to make your own button control. Could you store the variable in the "Tag" member?
 
use AddHandler when you create the control:

VB.NET:
AddHandler control_name.event_name, addressOf method_name

so for your button:

VB.NET:
Private sub Create Buttons

	dim b as new button
	
	b.name = "buttonTest"
	b.location = new point(50,50)
	addHandler b.Click, addressof ClickHandler

End Sub

private sub ClickHandler(sender as object, e as eventargs)

	dim b as button = directcast(sender, button)
	messagebox.show(b.name)

end sub
^ from memory, so might need some tweaking.
 
Did you declare it as "Friend Withevents Button3 as new button"? That would allow you to have access to it from anywhere in that project and put it in the code window so that finding events would be easy.
 
I guess I meant "could you". I do it alot. I may do something like:

VB.NET:
Public Class Form1
    Inherits System.Windows.Forms.Form
    
    'Mod level Variables
    Friend WithEvents Button3 As Button

    Private Sub LoadControls()
        Button3 = New Button
        With Button3
            .Name = "Button3"
            .Size = New Size(30, 20)
            .Location = New Point(0, 0)
        End With

        Me.Controls.Add(Button3)

    End Sub

End Class

But maybe I am misunderstanding the way you are coding your project. I tend to not like to use addhandler unless I really have to declare items on the fly, or I am making an array of items that fire events.
 
Back
Top