Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How To Create Objects By Code


  • Please log in to reply
3 replies to this topic

#1 MFatih

MFatih

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 03 January 2011 - 12:38 PM

Hello Everyone!
This is Fatih From Fatihbakir.net

Well I Have Created A Tutorial That Would Be Helpful For Those Who Don't Know How To Create Objects By Code And Set Their Actions For Their Events.

Object Creating By Code
Estimated Time = 1 Hour To Understand Everything. 10 Minutes To Copy + Paste.

Well, Sometimes You Cant Know How Many Objects Are Going To Be Used On Your Form, So You Cant Design Your Forms Statically.

In This Tutorial, I Will Try To Explain Everything About This Subject.

First, We Will Need A Form To Start Coding. For A Good Design You Can Use My Properties To Have A Good Design And Your Form Will Be Compatible With My Codes.

Name -> main_form
BackColor -> CornflowerBlue
Size -> 350;500
Text -> Main Form

Your Form Should Be Like This;
Posted Image

Then, Create A Button That Works To Create A Panel On Each Click.

Name -> Button1
BackColor -> Cornsilk
FlatStyle -> Flat
Font -> Trebuchet MS; 9,75pt; style=Bold
Location -> 12; 437
Size -> 320; 32
Text -> Create A Panel!

Ok It Is Now Probably Like This;
Posted Image

Okay. Our Static Designs Are Over. Now It Is Time To Code Some.

Double Click On Button1 Object.

First Type
Dim which As Integer = 0
To After The
Public Class main_form
Row.

And Type Those Into Your Button1.Click Event;

Dim b As New Panel
b.Location = New System.Drawing.Point(12, (which * 62) + 12)
which += 1
b.Name = "Panel" & which
b.BorderStyle = BorderStyle.FixedSingle
b.Size = New System.Drawing.Size(317, 50)
b.TabIndex = which + 2
b.BackColor = Color.LightSteelBlue
Me.Controls.Add(b)
AddHandler b.Click, AddressOf deneme
This Will Create A Panel On Your Form For Each Click With A 12 Pixels Of Space.
But This Is Not Enough Right? There Must Be Your Friend's Name And Status.

So Type Them After The Code We Wrote A Moment Ago;

Dim c As New Label
c.Location = New System.Drawing.Point(40, 4)
c.AutoSize = True
Dim font As New Font("Trebuchet MS", 10, FontStyle.Regular)
c.Font = font
c.ForeColor = Color.DarkRed
c.Text = "Text Of Panel" & which
AddHandler c.MouseMove, AddressOf altciz
AddHandler c.MouseLeave, AddressOf altciz_kaldir

Dim d As New Label
d.Location = New System.Drawing.Point(45, 22)
d.AutoSize = True
d.Text = "Subtext Of Panel" & which

b.Controls.Add(c)
b.Controls.Add(d)
c.Visible = True
b.Visible = True
So For Each Click, Your Code Creates A Panel On Your Form And Creates 2 Labels On Your Panel.
Well You Debugged It And Saw These

AddHandler b.Click, AddressOf deneme
AddHandler c.MouseMove, AddressOf altciz
AddHandler c.MouseLeave, AddressOf altciz_kaldir
Rows Are Errored. These Codes Define Events For Your Objects.

So You Must Define Those Functions Too;

Private Function deneme(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(sender.Name)
Return vbNull
End Function

Private Function altciz(ByVal sender As System.Object, ByVal e As System.EventArgs)
sender.font = New Font("Trebuchet MS", 10, FontStyle.Bold)
Cursor = Cursors.Hand
Return vbNull
End Function

Private Function altciz_kaldir(ByVal sender As System.Object, ByVal e As System.EventArgs)
sender.font = New Font("Trebuchet MS", 10, FontStyle.Regular)
Cursor = Cursors.Default
Return vbNull
End Function
Okay This Is It!

You Can Now Debug It And See The Results. For Each Clicking You Will Create Another Panel With Diffrent Labels Which Have Hover Functions.

Like This;
Posted Image

Well This Is The First Part Of My Chat Program Tutorial.
You Can Follow Rest On My Personal Site Here

Thank You For Reading.
If There Is Any Question Please Let Me Know. :c-smile:

Edited by MFatih, 04 January 2011 - 05:39 AM.

  • 0

#2 MFatih

MFatih

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 04 January 2011 - 06:23 AM

Second Part Is Here and Sent To This Forum Too. It Will Be Active After A Moderator Reads It I Think.
  • 0

#3 EmersonBeginner

EmersonBeginner

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:Others
  • Learning:Others

Posted 16 October 2012 - 08:14 PM

Hi MFatih

my name is emerson, i am new here and i want to learn more about vb6... thanks to your tutorial (reading by now) and have a great day :thumbup:
  • 0

#4 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 16 October 2012 - 10:47 PM

hmm... interesting ... keep on the good work
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download