Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone

Is it possible to Load a Form using the Tag of a Button

ex. I have a Form "FrmCountrys" that had 3 button, I put a Corresponding Form each tag of the button

VB
BtnPhil.text = Philippines
BtnPhil.Tag = FrmPhil

BtnJapan.text = Japan
BtnPhil.Tag = FrmJapan

BtnAfghanistan.text = Afghanistan
BtnAfghanistan.Tag = FrmAfghanistan


On FrmCountrys
VB
Private Sub BtnCountrys(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnPhil.Click,BtnJapan.Click,BtnAfghanistan.Clik
Dim Btn as Button = Ctype(sender,Button)
//Need some Idea panu ma call yung mga form sa pamamagitan ng Tag
End Sub
Posted
Updated 8-Jul-13 17:32pm
v2

YOu need to do something like this, in the OnClick event for your buttons

VB
Private Sub ClickHandler(sender As Object, e As EventArgs)
Dim f as Form
f = Sender.tag
f.ShowDialog()
End Sub



Sorry I can't be more precise - don't have VB.Net in front of me and its been a while ...
 
Share this answer
 
Comments
iMaker.ph 9-Jul-13 1:00am    
I get some error "Unable to cast object of type 'System.String' to type 'System.Windows.Forms.Form'."
Dim Btn as Button = Ctype(sender,Button)
f = Btn.Tag
If that's the error then it looks like your tag is a string (assuming the error is on the f=Btn.Tag line)

Is your FrmJapan etc. a Form?
 
Share this answer
 
Comments
iMaker.ph 9-Jul-13 7:33am    
Yes my BtnTag is just the name of the Form
And Yes FrmJapan is a Form..
sorry for Late Reply :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900