|
-
Jul 28th, 2004, 01:24 AM
#1
Thread Starter
Addicted Member
Show and Hide Forms ( New to .net)
Hi
I have two forms ( Form1, Form2).
On Form1 i have a button, when i click that button form1 must close and Form2 must Show.
How do I do that????
Thanx
-
Jul 28th, 2004, 01:57 AM
#2
VB Code:
'in the form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2(Me)
f.Show()
End Sub
'in the form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.f.Close()
End Sub
'to the constructor of the form2
Dim f As Form
Public Sub New(ByVal f As Form1)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
Me.f = f
'Add any initialization after the InitializeComponent() call
End Sub
'to the module...make it as a startup object
Sub main()
Dim f As New Form1()
f.Show()
Application.Run()
End Sub
or this one
VB Code:
' form2
'in the main form
public logged as boolean=false
'in the form load
dim x as new form1()
me.addownedform(x)
x.showdialog()
if logged = false then
application.doevents()
end if
'in the form1
dim m as form2
'in the formload
m= me.owner
'in button click
m.logged = true
close()
make the form2 as startup object...
courtesy of dynamic sysop
Last edited by mar_zim; Jul 28th, 2004 at 02:04 AM.
-
Jul 28th, 2004, 02:01 AM
#3
Frenzied Member
this is very simple,
VB Code:
dim x as new form2
x.show
me.close
-
Jul 28th, 2004, 02:05 AM
#4
Originally posted by maged
this is very simple,
VB Code:
dim x as new form2
x.show
me.close
Does that work?
-
Jul 28th, 2004, 02:13 AM
#5
Thread Starter
Addicted Member
Thanx
Next step is to load a Datagrid from a SQL Database
-
Jul 28th, 2004, 02:16 AM
#6
maged i dont think your code will work...
about loading the datagrid from sql
VB Code:
'cn is an sqlconnection
dim dt as new datatable("sampletable")
dim da as new sqldataadapter("select * from categories",cn)
da.fill(dt)
datagrid1.datasource = dt
-
Jul 28th, 2004, 02:33 AM
#7
Hyperactive Member
Good morning to everyone, dear friends.
Dear Maged, I think your is the simplest way, but if the form in which this code is placed is the default start up object, as probably is, closing Form1, will cause your app. end.
I suggest to change:
dim x as new form2
x.show
me.close
in
Dim f2 As New Form2
Me.Hide()
f2.ShowDialog()
Me.Close()
Form1 is not really closed, until Form2 closes, but it seems so anyway.
Obviously you could really close Form1,starting from a module, running Form1, then when it will be closed, running Form2, but probably it's a good idea, at this moment, to stay on simple solutions. There will be time to worry on these subjects, for our friend chatty!
Anyway, it should be something like (By memory...check syntax before use. Only idea is important!!!):
Public Sub Main 'In a module and declared as starting object in project's properties
Dim F1 as new Form1
F1.ShowDialog() 'The button in F1 will close F1 itself
Dim F2 As New Form2
F2.Showdialog()
End
End Sub
Good job!
Live long and prosper (Mr. Spock)
-
Jul 28th, 2004, 03:08 AM
#8
Thread Starter
Addicted Member
How do i Update, Insert or Delete a record without using a dataset.
Do i use ExecuteNonQuery?
Last edited by chatty; Jul 28th, 2004 at 03:16 AM.
-
Jul 28th, 2004, 03:22 AM
#9
Fanatic Member
a slight modification of mzims solution
VB Code:
' on form1
Shared Sub Main()
Dim f As New Form1()
f.Show()
Application.Run()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2(Me)
f.Show()
End Sub
' on form2
Dim f As Form
Public Sub New(ByVal f As Form)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
Me.f = f
'Add any initialization after the InitializeComponent() call
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.f.Close()
End Sub
Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Application.Exit()
End Sub
though module can have this run but i don't recommend modules because the main purpose of module are structures and enums. the thing that needs no encapsulation. cheers mate.
remember: application.run() has nothing on it so we should .exit() this thing. hope this helps mate. if not, sorry.
-
Jul 28th, 2004, 03:27 AM
#10
Fanatic Member
mendhak is good at this ado.net thing. i'm sure he can give exact details. but executeNonQuery() is used for non queries. sample: update, delete, entry or even create a table/database through code. one sample, a basic one cause i'm a noob too. hehehe.
VB Code:
dim cn as new sqlconnection()
cn.connectionstring=[i]conn_string[/i]
cn.open()
dim cm as new sqlcommand("insert into table_name values('field1','field2')",cn)
cm.executenonquery()
where table_1 has 2 fields with data type string. cheers mate.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|