473,657 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Showing Windows Forms - question

Hi!

If Windows Form -application has for example a button on Form1 which
Click-event opens other Form2-form like...

Dim f as New Form2
f.ShowDialog()
If (f.DialogResult = DialogResult.OK ) Then
SaveText(f.txtI nput.Text)
End If
f.Dispose()

....and when OK-button was pressed on Form2, it saves content of the TextBox
on the Form2 before closing Form2.

This is working fine like this way for now. But I want to keep Form1 as an
editable form when Form2 is open, how to this?

I tried simply changing line f.ShowDialog() to f.Show(), but then code
execution is going to the end of the Sub, and I can't catch when OK was
pressed on the Form2. I thing this is simple question. Hopefully you
understand what I'm trying to explain :)

--
Thanks in advance!

Mika
Nov 21 '05 #1
4 1574
Since you are using ShowDialog(), the form will show up modally and you wont
be able to edit the calling form (Form1). You will have to use Show() only.
As for saving the text of a textbox on form2, you can do that in the Click
event of the OK button in form2. Since your SaveText method is in Form1, you
can pass a reference to Form1 into Form2 and make SaveText as a friend
method. Here's how you could do it (there are other ways too):

' All this in Form2

Private frmForm1 As Form1

' Constructor of Form2
Public Sub New(ByVal frmCalling As Form1)
frmForm1 = frmCalling
End Sub

' OK Button Click in Form2
Private Sub btnOK_Click(ByV al sender as Object, _
ByVal e As EventArgs) Handles btnOK.Click
frmForm1.SaveTe xt(Me.txtInput. Text)
End Sub

' In Form1
Dim f As New Form2(Me)
f.Show()

That should pretty much do what you are looking for.

hope that helps..
Imran.

"Mika M" <mika.mahonen@n ospam_kolumbus. fi> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi!

If Windows Form -application has for example a button on Form1 which
Click-event opens other Form2-form like...

Dim f as New Form2
f.ShowDialog()
If (f.DialogResult = DialogResult.OK ) Then
SaveText(f.txtI nput.Text)
End If
f.Dispose()

...and when OK-button was pressed on Form2, it saves content of the TextBox on the Form2 before closing Form2.

This is working fine like this way for now. But I want to keep Form1 as an
editable form when Form2 is open, how to this?

I tried simply changing line f.ShowDialog() to f.Show(), but then code
execution is going to the end of the Sub, and I can't catch when OK was
pressed on the Form2. I thing this is simple question. Hopefully you
understand what I'm trying to explain :)

--
Thanks in advance!

Mika

Nov 21 '05 #2
Mika,

It is a simple question yes, however the showdialog is very easy for this.
When there is few processing it will as well not be bad, however when there
is time involving processing in one of your forms you will need
multithreading.

Here a sample I made some weeks ago.
It shows 3 forms the main, and one normal and one with threading.

http://groups.google.com/groups?selm...TNGP10.phx.gbl
I hope this helps?

Cor

"Mika M" <mika.mahonen@n ospam_kolumbus. fi>

If Windows Form -application has for example a button on Form1 which
Click-event opens other Form2-form like...

Dim f as New Form2
f.ShowDialog()
If (f.DialogResult = DialogResult.OK ) Then
SaveText(f.txtI nput.Text)
End If
f.Dispose()

...and when OK-button was pressed on Form2, it saves content of the
TextBox on the Form2 before closing Form2.

This is working fine like this way for now. But I want to keep Form1 as an
editable form when Form2 is open, how to this?

I tried simply changing line f.ShowDialog() to f.Show(), but then code
execution is going to the end of the Sub, and I can't catch when OK was
pressed on the Form2. I thing this is simple question. Hopefully you
understand what I'm trying to explain :)

--
Thanks in advance!

Mika

Nov 21 '05 #3
Hi Cor and thanks for your reply!

I looked and tried that sample in Google and after ...

Private Sub Button1_Click(. ..

.... following lines ...

AddHandler frm1.ready, AddressOf Frm1Ready
AddHandler frm1.ready, AddressOf frm2ready

.... causes following errors ...

'ready' is not an event of 'FormTest.Form2 '.
'ready' is not an event of 'FormTest.Form2 '.

Maybe I'm missing something?

--
Mika

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:eR******** ******@TK2MSFTN GP15.phx.gbl...
Mika,

It is a simple question yes, however the showdialog is very easy for this.
When there is few processing it will as well not be bad, however when
there is time involving processing in one of your forms you will need
multithreading.

Here a sample I made some weeks ago.
It shows 3 forms the main, and one normal and one with threading.

http://groups.google.com/groups?selm...TNGP10.phx.gbl
I hope this helps?

Cor

Nov 21 '05 #4
Mika,

Thank you for making me attent on this, it is because the event in form2 is
named frm2Ready while i changed it later to "ready" however not in the
sample in form 2.

Here the complete sample again (Than I can use this on Google again)

\\\needs on form 1 one button and three textboxes
Private WithEvents frm1 As Form2
Private Delegate Sub Frm1Handler(ByV al message As String)
Private WithEvents frm2 As Form2
Private MyThread As System.Threadin g.Thread
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim timer1 As New System.Windows. Forms.Timer
AddHandler timer1.Tick, AddressOf mytimer1
TextBox1.Text = "0"
timer1.Enabled = True
timer1.Interval = 400
Dim timer2 As New System.Windows. Forms.Timer
End Sub
Private Sub mytimer1(ByVal sender As Object, _
ByVal e As System.EventArg s)
TextBox1.Text = (CInt(TextBox1. Text) + 1).ToString
DirectCast(send er, System.Windows. Forms.Timer).En abled = True
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
frm1 = New Form2
frm1.itstop = Me.Top
frm1.itsleft = Me.Left + 200
AddHandler frm1.ready, AddressOf Frm1Ready
frm1.Text = "Extra thread"
MyThread = New System.Threadin g.Thread(Addres sOf frm1.Show)
MyThread.Start( )
frm2 = New Form2
frm2.itstop = Me.Top
frm2.itsleft = Me.Left + 400
frm2.Text = "In own thread"
AddHandler frm1.ready, AddressOf Frm2Ready
frm2.Show()
End Sub
Private Sub Frm1Ready(ByVal message As String)
Me.BeginInvoke( New Frm1Handler(Add ressOf Frm1HandlerSub) , New
Object() {message})
End Sub
Private Sub Frm1HandlerSub( ByVal message As String)
TextBox2.Text = message
frm1.Close()
MyThread.Abort( )
End Sub
Private Sub frm2ready(ByVal message As String)
TextBox3.Text = message
frm2.Dispose()
End Sub
Private Sub Form1_Closing(B yVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
MyThread.Abort( )
End Sub
///
\\\Needs a form2 with one textbox
Friend Event ready(ByVal message As String)
Friend itstop As Integer
Friend itsleft As Integer
Private Sub Form2_Activated (ByVal sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Activate d
Me.Left = itsleft
Me.Top = itstop
Me.BringToFront ()
Dim timenext As DateTime = Now.Add(TimeSpa n.FromSeconds(1 0))
Do While timenext > Now
TextBox1.Text = Now.TimeOfDay.T oString
Application.DoE vents() 'to show the time
Threading.Threa d.Sleep(50)
Me.Opacity -= 0.004
Loop
RaiseEvent ready(Now.TimeO fDay.ToString)
End Sub
Private Sub Form2_Closing(B yVal sender As Object, ByVal _
e As System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
e.Cancel = True
End Sub
///
Nov 21 '05 #5

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

Similar topics

1
3721
by: Daniel Hill | last post by:
OK, I have very, VERY basic background knowledge of VB6 and have now upgraded to VB.NET and now I'm struggling to bring up the forms I want. What I am looking to do is to have a click a command button bring up a form, and to have which form is brought up determined by which item is selected in the accompanying combo box. I've gathered that you have to declare the item as a
4
1595
by: Gerry Viator | last post by:
Hi all, Whats going on. Testing messagebox, text isn't showing up. Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code "
1
2757
by: Mullin Yu | last post by:
But, I want is that I can have a Main app that will start a new process or kill one particular or all process. The process will open a console exe. But, I don't want the user to close the console windows by themselves, and force them to use the Main app. If I use Windows Services, I'm not sure can I create one dynamically, and then kill easily. But, if using console application, my following coding is working now. using System;
2
1278
by: Bardo | last post by:
I am trying to show a picture in a form but using visual studios C# I am getting a error everytime I want to deploy my program. I cannot find the reason Assembly assembly = Assembly.GetExecutingAssembly() Image image = Image.FromStream(assembly.GetManifestResourceStream("picture.jpg")) the debugger holds on the second line and tells me that he has no valid value for the stream. So my understanding is that he cannot find the file...
5
1828
by: Grant | last post by:
Hello, How come when I add a new row to my dataset table it shows up as changed (agencyData.Haschanges() = True) but when I delete a row the dataset thinks here are no changes(agencyData.Haschanges() = False)???? The bizaar thing is the row count before the delete and after is different so it definately is being deleted but I cannot update my main database table because the dataset thinks there are no changes?
0
1554
by: Alireza Haghshenass | last post by:
Dear All, I am facing a problem which I could not solve. I am writing an application which uses a notify icon and a context menu bound to it to show modal dialog forms. When these forms is shown there is no problem but while I am closing any of them which is shown in modal form throw an exception which is described below : Message : External component has thrown an exception. StackTrace : at...
1
3032
by: Henry | last post by:
I was trying to work through the Lab 2 exercises in the Microsoft's Windows-Based Applications in Visual C#. While I am not showing any errors I am also not seeing the mainMenu object when I run the application. I am wondering if someone could point out why in the code below: using System; using System.Drawing; using System.Collections;
2
5712
by: Greg Burns | last post by:
I added a toolbar to a form and added one button. I made sure ShowToolTips = true for the Toolbar, and have set a tooltip for the button. The problem is the tooltip only shows after clicking somewhere on the toolbar itself. It seems it needs to have the focus before tooltips will show. Any ideas? Greg
8
1315
by: jy836 | last post by:
I have been working on an application, which to this point has only involved one Windows Form. I need to create another one; but on the Project menu, there are two options: "Add Windows Form" and "Add Inherited Form." I don't know which one to use. Also, once I choose one of those two options, how can I show the second form when a user clicks a button in the first form? Thanks in advance.
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.