473,327 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

using two forms

Hi, Im using two forms in the same application. Main form opens, click
menu for secend form. This is a log on form, used to get three bits of
info. Up to this point Im ok. I then want to send this info back to
form one for it to process. My question is how do I call the relevent
code on form1. If I do all the coding in one form only, ie logging on
etc, all works ok.
regards robert

Jul 11 '07 #1
6 2226
On Jul 11, 1:25 pm, "RobcPet...@yahoo.co.uk" <RobcPet...@yahoo.co.uk>
wrote:
Hi, Im using two forms in the same application. Main form opens, click
menu for secend form. This is a log on form, used to get three bits of
info. Up to this point Im ok. I then want to send this info back to
form one for it to process. My question is how do I call the relevent
code on form1. If I do all the coding in one form only, ie logging on
etc, all works ok.
regards robert
You contradict yourself. You say that form2 needs to send data back to
form1. And then you ask how to call the relevant code in form1. So,
what do you want to do? Pass the data back from form2 to form1 or tell
form1 from form2 to do something?

Passing the data from form2 to form1 is simple. Just declare
properties for these values in form2 and when form2 closes, form1 will
have acces to the values in form2's properties.

Invoking a method in form1 from form2 is also pretty simple, but I
suspect you really need to just pass the data back to form1.
Jul 11 '07 #2
Thanks for your reply. After re reading my post, your right I have
contradicted myself. All I need to do is pass data from forw 2 to form
1. Do I declare the values in the normal way, ie public int xxxx; etc.
Regards Robert

Jul 11 '07 #3
On Jul 11, 2:19 pm, "RobcPet...@yahoo.co.uk" <RobcPet...@yahoo.co.uk>
wrote:
Thanks for your reply. After re reading my post, your right I have
contradicted myself. All I need to do is pass data from forw 2 to form
1. Do I declare the values in the normal way, ie public int xxxx; etc.
Regards Robert
I would define them in the "standard" way to define class properties.
Declare a private variable to hold the local value. Then declare a
public (or friend) property that links to the private variable. As is:

Private _myvalue as Boolean

Public Property myvalue as Boolean
Get
Return _myvalue
End Get
Set(ByVal value as Boolean)
_myvalue = value
End Set
End Property

Jul 11 '07 #4
On Jul 11, 3:06 pm, z...@construction-imaging.com wrote:
On Jul 11, 2:19 pm, "RobcPet...@yahoo.co.uk" <RobcPet...@yahoo.co.uk>
wrote:
Thanks for your reply. After re reading my post, your right I have
contradicted myself. All I need to do is pass data from forw 2 to form
1. Do I declare the values in the normal way, ie public int xxxx; etc.
Regards Robert

I would define them in the "standard" way to define class properties.
Declare a private variable to hold the local value. Then declare a
public (or friend) property that links to the private variable. As is:

Private _myvalue as Boolean

Public Property myvalue as Boolean
Get
Return _myvalue
End Get
Set(ByVal value as Boolean)
_myvalue = value
End Set
End Property
I just realized I posted VB code in a C# group. Sorry. Do you need me
to translate?

Jul 11 '07 #5
Thankyou all for your replys. Plenty to read up on. Id got as far as
ian suggestion, which works. Now Im reading up to make sure I
understand whats happening for future ref. One issue Ive got at the
momment is when I open and use the form2, then close it, details go
back to form one. When I open it again to get details, it crashes. Im
using a treeview in form2 and secong time around it doesnt like the
final nodes. Any way thankyou all again.
Regards Robert

Jul 12 '07 #6
Or (a bit nicer):

using (Form2 form2 = new Form2())
{
if (form2.ShowDialog() == DialogResult.OK)
{
myObject = form2.MyResult;
}
}

BTW there's no need to call Close... ShowDialog hides the form
automatically.

On Jul 14, 2:40 pm, "Ian Semmel" <any...@rocketcomp.com.auwrote:
When you use ShowDialog, Close() doesn't destroy the form.

eg you can do

form2 = new Form2();
rc = form2.ShowDialog();
form2.Close();

myObject = form2.GetMyResult();

form2.Dispose();
-----Original Message-----
From: RobcPet...@yahoo.co.uk [mailto:RobcPet...@yahoo.co.uk]
Posted At: Friday, 13 July 2007 5:39 AM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: using two forms
Subject: Re: using two forms
Thankyou all for your replys. Plenty to read up on. Id got as far as
ian suggestion, which works. Now Im reading up to make sure I
understand whats happening for future ref. One issue Ive got at the
momment is when I open and use the form2, then close it, details go
back to form one. When I open it again to get details, it crashes. Im
using a treeview in form2 and secong time around it doesnt like the
final nodes. Any way thankyou all again.
Jul 15 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
0
by: grutta | last post by:
I am writing a windows service that will recieve notification when a USB Device is insterted into the machine. I have used the RegisterDeviceNotification and the RegisterServiceCtrlHandlerEx with...
5
by: Dave | last post by:
I tried posting this in the WinForm forum and got no hits so I am trying it here. After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
0
by: Marco Segurini | last post by:
Hi, I am trying to dynamically install/deinstall a message handler to a System.Windows.Forms.Form using NativeWindow. I do not use IMessageFilter derived class because it intercept only the...
2
by: Hrcko | last post by:
How to use this control? I have to grids on my form, one on the top and one on bottom. When I start application I want to be able to move bottom grip up, and top grid down, but it doesn't...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
3
by: Siv | last post by:
Hi, A little while ago I wrote a small program that allowed the user to view products from a database. The database holds the details of the products which can be viewed via a form and...
0
by: Sister Ray | last post by:
I'm trying to create a simple form that sends an email using my company's exchange server. I'm using the System.Net.Mail Namespace of the .net framework 2.0. I've googled everywhere and i think my...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.