473,503 Members | 12,516 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.txtInput.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 1564
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(ByVal sender as Object, _
ByVal e As EventArgs) Handles btnOK.Click
frmForm1.SaveText(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@nospam_kolumbus.fi> wrote in message
news:%2****************@TK2MSFTNGP09.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.txtInput.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@nospam_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.txtInput.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**************@TK2MSFTNGP15.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(ByVal message As String)
Private WithEvents frm2 As Form2
Private MyThread As System.Threading.Thread
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) 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.EventArgs)
TextBox1.Text = (CInt(TextBox1.Text) + 1).ToString
DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) 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.Threading.Thread(AddressOf 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(AddressOf 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(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) 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.EventArgs) Handles MyBase.Activated
Me.Left = itsleft
Me.Top = itstop
Me.BringToFront()
Dim timenext As DateTime = Now.Add(TimeSpan.FromSeconds(10))
Do While timenext > Now
TextBox1.Text = Now.TimeOfDay.ToString
Application.DoEvents() 'to show the time
Threading.Thread.Sleep(50)
Me.Opacity -= 0.004
Loop
RaiseEvent ready(Now.TimeOfDay.ToString)
End Sub
Private Sub Form2_Closing(ByVal sender As Object, ByVal _
e As System.ComponentModel.CancelEventArgs) 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
3714
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...
4
1575
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
2712
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...
2
1267
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 =...
5
1816
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...
0
1540
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...
1
3026
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...
2
5697
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...
8
1308
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...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
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...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
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...
0
4696
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...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.