473,397 Members | 2,056 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,397 software developers and data experts.

Form Background Image Disappears

I am using the following code to get a background image for my form

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Clic
If OpenFileDialog1.ShowDialog() = DialogResult.OK The
Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName
Me.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName
sr.Close(
End I
End Su

This works great. However, this is on frmMain and when I switch to form2 and then return to frmMain the background image is gone. What am I missing here

Thank you
John
Nov 20 '05 #1
39 3004
* "=?Utf-8?B?amNyb3VzZQ==?=" <an*******@discussions.microsoft.com> scripsit:
I am using the following code to get a background image for my form:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName)
Me.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName)
sr.Close()
End If
End Sub

This works great. However, this is on frmMain and when I switch to form2 and then return to frmMain the background image is gone. What am I missing here?


How do you "switch and return"? Are the two forms visible at the same
time or one after the other?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Hi,

Why are you creating a stream reader if you are not using it? Why don't
you try something like this?

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal
e
As System.EventArgs) Handles mnuBgroundImage.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName)
Dim bm as new Bitmap(sr)
sr.Close()
Me.BackgroundImage = bm
End If
End Sub

Ken
-------------

"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com:
I am using the following code to get a background image for my form:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mnuBgroundImage.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName)
Me.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName)
sr.Close()
End If
End Sub

This works great. However, this is on frmMain and when I switch to form2
and then return to frmMain the background image is gone. What am I missing
here?

Thank you,
John


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
Nov 20 '05 #3
Probably because I have no idea what I am doing. When I use your code

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mnuBgroundImage.Clic

If OpenFileDialog1.ShowDialog() = DialogResult.OK The
Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName
Dim bm as new Bitmap(sr
sr.Close(
Me.BackgroundImage = b
End I
End Su

It doesn't like the line "Dim bm as New Bitmap(sr)". It underlines the "sr" and says a lot about can't convert from ... to ..

Any more ideas
Joh

Nov 20 '05 #4
I switch from form1 to form2 with this code

Dim frmLC as new frmLabelControl
frmlc.Show(
Me.Hide(

I then switch back with this code

Dim frm1 As New Form
frm1.Show(
Me.Hide(

I also have something very weird going on now. I have a loop created somehow in the declaring of my frm statements. I am totally lost. It errors out with a stack overflow. I'm not even sure where the heck i have to declare things anymore

more to come,
John
Nov 20 '05 #5
Hi,

Sorry should have used a filestream instead of a streamreader.

Dim fs As New System.IO.FileStream("C:\Camera.bmp",
IO.FileMode.Open)
Dim bm As New Bitmap(fs)
fs.Close()

Ken
---------------

"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com:
Probably because I have no idea what I am doing. When I use your code:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e _

As System.EventArgs) Handles mnuBgroundImage.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName)
Dim bm as new Bitmap(sr)
sr.Close()
Me.BackgroundImage = bm
End If
End Sub

It doesn't like the line "Dim bm as New Bitmap(sr)". It underlines the
"sr" and says a lot about can't convert from ... to ...

Any more ideas,
John


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.1.2 - Release Date: 6/7/2004
Nov 20 '05 #6
Well Ken...The code seems to work but I keep getting an Out of Memory Exception error. I'll try it in an hour or so when I get home and then post back

John
Nov 20 '05 #7
Ken
Here's my code

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Clic
If OpenFileDialog1.ShowDialog() = DialogResult.OK The
Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open
Dim bm As New Bitmap(fs
fs.Close(
Me.BackgroundImage = b
End I
End Su

Any idea why I get an out of memory error

John
Nov 20 '05 #8
Try getting your bitmap like this:

Dim bm as New Bitmap(OpenFileDialog1.FileName)


"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Ken,
Here's my code:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Click If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open) Dim bm As New Bitmap(fs)
fs.Close()
Me.BackgroundImage = bm
End If
End Sub

Any idea why I get an out of memory error?

John

Nov 20 '05 #9
Did you know by using the code below you're actually creating a new instance
of Form1? That's why the image disappears.

I switch from form1 to form2 with this code:

Dim frmLC as new frmLabelControls
frmlc.Show()
Me.Hide()

I then switch back with this code:

'---------Creates a New Form1 WITHOUT the image!
Dim frm1 As New Form1
frm1.Show()
Me.Hide()


"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Ken,
Here's my code:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Click If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open) Dim bm As New Bitmap(fs)
fs.Close()
Me.BackgroundImage = bm
End If
End Sub

Any idea why I get an out of memory error?

John

Nov 20 '05 #10
How do I switch back wthout creating a new instance?

John

"yEaH rIgHt" wrote:
Did you know by using the code below you're actually creating a new instance
of Form1? That's why the image disappears.

I switch from form1 to form2 with this code:

Dim frmLC as new frmLabelControls
frmlc.Show()
Me.Hide()

I then switch back with this code:

'---------Creates a New Form1 WITHOUT the image!
Dim frm1 As New Form1
frm1.Show()
Me.Hide()


"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Ken,
Here's my code:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles mnuBgroundImage.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName,

IO.FileMode.Open)
Dim bm As New Bitmap(fs)
fs.Close()
Me.BackgroundImage = bm
End If
End Sub

Any idea why I get an out of memory error?

John


Nov 20 '05 #11
No workie. What next?

John

"yEaH rIgHt" wrote:
Try getting your bitmap like this:

Dim bm as New Bitmap(OpenFileDialog1.FileName)


"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Ken,
Here's my code:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles mnuBgroundImage.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName,

IO.FileMode.Open)
Dim bm As New Bitmap(fs)
fs.Close()
Me.BackgroundImage = bm
End If
End Sub

Any idea why I get an out of memory error?

John


Nov 20 '05 #12
Try these two pieces of code. This should do what you want.
'-----------In Form1
Option Explicit On
Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents fm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
End If
fm.Show()
Me.Hide()
End Sub

Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.VisibleChanged
Me.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub
End Class
'-----------End Form1

'-----------In Form2

Option Explicit On
Option Strict On

Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
End Class


"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
How do I switch back wthout creating a new instance?

John

"yEaH rIgHt" wrote:
Did you know by using the code below you're actually creating a new instance of Form1? That's why the image disappears.

I switch from form1 to form2 with this code:

Dim frmLC as new frmLabelControls
frmlc.Show()
Me.Hide()

I then switch back with this code:

'---------Creates a New Form1 WITHOUT the image!
Dim frm1 As New Form1
frm1.Show()
Me.Hide()


"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Ken,
Here's my code:

Private Sub mnuBgroundImage_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles mnuBgroundImage.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim fs As New
System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open)
Dim bm As New Bitmap(fs)
fs.Close()
Me.BackgroundImage = bm
End If
End Sub

Any idea why I get an out of memory error?

John


Nov 20 '05 #13
Hi YEaHRight,

It is almost the same code I would have showed for this.

However one thing, why are you doing this?
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub

And not
fm.dispose

A class object should in my opinon never be set to "nothing" in VB.net only
properties.

Cor
Nov 20 '05 #14
It removes the event handler. Actually, I should have done this instead:

Private Sub fm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles fm.Closing
fm = Nothing
End Sub

And not the Form1.Closing.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Hi YEaHRight,

It is almost the same code I would have showed for this.

However one thing, why are you doing this?
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub
And not
fm.dispose

A class object should in my opinon never be set to "nothing" in VB.net

only properties.

Cor

Nov 20 '05 #15
Worked great!. I had to add some logic incase the users didn't enter frm2 because then there was nothing to dispose.

Thanks guys,
John

"Cor Ligthert" wrote:
Hi YEaHRight,

It is almost the same code I would have showed for this.

However one thing, why are you doing this?
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub

And not
fm.dispose

A class object should in my opinon never be set to "nothing" in VB.net only
properties.

Cor

Nov 20 '05 #16
> Private Sub fm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles fm.Closing
fm = Nothing
End Sub


If it is right, that should do nothing, you are telling that there is no
reference anymore to fm so you cannot use it anymore, however it still
exist.

What needs to be done is the clean up from the unmanaged resources which
seems to be in a dialogbox, so after a frm.showdialog, there should as well
always be a frm.dispose.

(I am telling only what I have read, not what I have tested in this)

Cor
Nov 20 '05 #17
Read Page 255 in Applied Microsoft .Net Framework Programming in Microsoft
Visual Basic .Net. By Jeffery Richter and Francesco Balena.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Private Sub fm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles fm.Closing
fm = Nothing
End Sub
If it is right, that should do nothing, you are telling that there is no
reference anymore to fm so you cannot use it anymore, however it still
exist.

What needs to be done is the clean up from the unmanaged resources which
seems to be in a dialogbox, so after a frm.showdialog, there should as

well always be a frm.dispose.

(I am telling only what I have read, not what I have tested in this)

Cor

Nov 20 '05 #18
Hi yEaHricht,

Intresting that it is in a book.

However, do it as you wish, I tried only to make you attent on it.

Cor
Read Page 255 in Applied Microsoft .Net Framework Programming in Microsoft
Visual Basic .Net. By Jeffery Richter and Francesco Balena.

Nov 20 '05 #19
The following code works great:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub

Now, how do i remove the background Image or set it to null or nothing?

Thanks,
John

"yEaH rIgHt" wrote:
Try these two pieces of code. This should do what you want.
'-----------In Form1
Option Explicit On
Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents fm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
End If
fm.Show()
Me.Hide()
End Sub

Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.VisibleChanged
Me.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub
End Class
'-----------End Form1

'-----------In Form2

Option Explicit On
Option Strict On

Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
End Class


"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
How do I switch back wthout creating a new instance?

John

"yEaH rIgHt" wrote:
Did you know by using the code below you're actually creating a new instance of Form1? That's why the image disappears.

I switch from form1 to form2 with this code:

Dim frmLC as new frmLabelControls
frmlc.Show()
Me.Hide()

I then switch back with this code:

'---------Creates a New Form1 WITHOUT the image!
Dim frm1 As New Form1
frm1.Show()
Me.Hide()


"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
> Ken,
> Here's my code:
>
> Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Click
> If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open)
> Dim bm As New Bitmap(fs)
> fs.Close()
> Me.BackgroundImage = bm
> End If
> End Sub
>
> Any idea why I get an out of memory error?
>
> John


Nov 20 '05 #20
'-- Remove Image
Me.BackgroundImage = Nothing
"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
The following code works great:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub

Now, how do i remove the background Image or set it to null or nothing?

Thanks,
John

"yEaH rIgHt" wrote:
Try these two pieces of code. This should do what you want.
'-----------In Form1
Option Explicit On
Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents fm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
End If
fm.Show()
Me.Hide()
End Sub

Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.VisibleChanged
Me.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub
End Class
'-----------End Form1

'-----------In Form2

Option Explicit On
Option Strict On

Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
End Class


"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
How do I switch back wthout creating a new instance?

John

"yEaH rIgHt" wrote:

> Did you know by using the code below you're actually creating a new

instance
> of Form1? That's why the image disappears.
>
> I switch from form1 to form2 with this code:
>
> Dim frmLC as new frmLabelControls
> frmlc.Show()
> Me.Hide()
>
> I then switch back with this code:
>
> '---------Creates a New Form1 WITHOUT the image!
> Dim frm1 As New Form1
> frm1.Show()
> Me.Hide()
>
>
>
>
> "jcrouse" <an*******@discussions.microsoft.com> wrote in message
> news:8C**********************************@microsof t.com...
> > Ken,
> > Here's my code:
> >
> > Private Sub mnuBgroundImage_Click(ByVal sender As
System.Object, ByVal
> e As System.EventArgs) Handles mnuBgroundImage.Click
> > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> > Dim fs As New

System.IO.FileStream(OpenFileDialog1.FileName,
> IO.FileMode.Open)
> > Dim bm As New Bitmap(fs)
> > fs.Close()
> > Me.BackgroundImage = bm
> > End If
> > End Sub
> >
> > Any idea why I get an out of memory error?
> >
> > John
>
>
>


Nov 20 '05 #21
Another thing. I use the following code on form2 (frmLC):

Private Sub chkP1JoyUp_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkP1JoyUp.CheckedChanged
If chkP1JoyUp.Checked = True Then
frm1.lblP1JoyUp.Visible = True
frm1.lblP1JoyUp.Top = (frm1.Height / 2) - (frm1.lblP1JoyUp.Height / 2)
frm1.lblP1JoyUp.Left = (frm1.Width / 2) - (frm1.lblP1JoyUp.Width / 2)
Else
frm1.lblP1JoyUp.Visible = False
frm1.lblP1JoyUp.Top = 10
frm1.lblP1JoyUp.Left = 10
End If
End Sub

If I check a checkbox it makes a label on form1 visible and moves it to the center of the form. It now seems to be broken. The label never becomes visible when I step through the code in my debugger. This happened after I change my code to your method for switching between forms (which works great). Any ideas what I'm missing here?

Thanks,
John

"yEaH rIgHt" wrote:
Try these two pieces of code. This should do what you want.
'-----------In Form1
Option Explicit On
Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents fm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
End If
fm.Show()
Me.Hide()
End Sub

Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.VisibleChanged
Me.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub
End Class
'-----------End Form1

'-----------In Form2

Option Explicit On
Option Strict On

Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
End Class


"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
How do I switch back wthout creating a new instance?

John

"yEaH rIgHt" wrote:
Did you know by using the code below you're actually creating a new instance of Form1? That's why the image disappears.

I switch from form1 to form2 with this code:

Dim frmLC as new frmLabelControls
frmlc.Show()
Me.Hide()

I then switch back with this code:

'---------Creates a New Form1 WITHOUT the image!
Dim frm1 As New Form1
frm1.Show()
Me.Hide()


"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
> Ken,
> Here's my code:
>
> Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Click
> If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open)
> Dim bm As New Bitmap(fs)
> fs.Close()
> Me.BackgroundImage = bm
> End If
> End Sub
>
> Any idea why I get an out of memory error?
>
> John


Nov 20 '05 #22
Hi John,

As I said in this thread, properties can set to nothing.
I would make this a little bit else because bitmaps seems to be expensive
for memory and therefore should be disposed when not used anymore.

I hope this is what you where looking for?

Cor
\\\
Private bm As Bitmap
Private Sub Button2_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim openfiledialog1 As New OpenFileDialog
If openfiledialog1.ShowDialog() = DialogResult.OK Then
bm = New Bitmap(openfiledialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Me.BackgroundImage = Nothing
bm.Dispose()
End Sub
///
Nov 20 '05 #23
Do you have a reference to form1 in form2? You need a reference to that form
if you want to minipulate any of the labels.

"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Another thing. I use the following code on form2 (frmLC):

Private Sub chkP1JoyUp_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkP1JoyUp.CheckedChanged If chkP1JoyUp.Checked = True Then
frm1.lblP1JoyUp.Visible = True
frm1.lblP1JoyUp.Top = (frm1.Height / 2) - (frm1.lblP1JoyUp.Height / 2) frm1.lblP1JoyUp.Left = (frm1.Width / 2) - (frm1.lblP1JoyUp.Width / 2) Else
frm1.lblP1JoyUp.Visible = False
frm1.lblP1JoyUp.Top = 10
frm1.lblP1JoyUp.Left = 10
End If
End Sub

If I check a checkbox it makes a label on form1 visible and moves it to the center of the form. It now seems to be broken. The label never becomes
visible when I step through the code in my debugger. This happened after I
change my code to your method for switching between forms (which works
great). Any ideas what I'm missing here?
Thanks,
John

"yEaH rIgHt" wrote:
Try these two pieces of code. This should do what you want.
'-----------In Form1
Option Explicit On
Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents fm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
End If
fm.Show()
Me.Hide()
End Sub

Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.VisibleChanged
Me.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub
End Class
'-----------End Form1

'-----------In Form2

Option Explicit On
Option Strict On

Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
End Class


"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
How do I switch back wthout creating a new instance?

John

"yEaH rIgHt" wrote:

> Did you know by using the code below you're actually creating a new

instance
> of Form1? That's why the image disappears.
>
> I switch from form1 to form2 with this code:
>
> Dim frmLC as new frmLabelControls
> frmlc.Show()
> Me.Hide()
>
> I then switch back with this code:
>
> '---------Creates a New Form1 WITHOUT the image!
> Dim frm1 As New Form1
> frm1.Show()
> Me.Hide()
>
>
>
>
> "jcrouse" <an*******@discussions.microsoft.com> wrote in message
> news:8C**********************************@microsof t.com...
> > Ken,
> > Here's my code:
> >
> > Private Sub mnuBgroundImage_Click(ByVal sender As
System.Object, ByVal
> e As System.EventArgs) Handles mnuBgroundImage.Click
> > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> > Dim fs As New

System.IO.FileStream(OpenFileDialog1.FileName,
> IO.FileMode.Open)
> > Dim bm As New Bitmap(fs)
> > fs.Close()
> > Me.BackgroundImage = bm
> > End If
> > End Sub
> >
> > Any idea why I get an out of memory error?
> >
> > John
>
>
>


Nov 20 '05 #24
I believe so. I have the following code at the top of form1:

Imports System
Imports System.IO
Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mouseX As Integer
Dim mouseY As Integer
Dim _mouseDown As Boolean = False
Dim myMouseDown As Boolean
Dim WithEvents frmlc As frmLabelControls
Dim bmGlobal As Bitmap

The next to last line should do it.

????,
John

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
Do you have a reference to form1 in form2? You need a reference to that form if you want to minipulate any of the labels.

"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Another thing. I use the following code on form2 (frmLC):

Private Sub chkP1JoyUp_CheckedChanged(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles chkP1JoyUp.CheckedChanged
If chkP1JoyUp.Checked = True Then
frm1.lblP1JoyUp.Visible = True
frm1.lblP1JoyUp.Top = (frm1.Height / 2) -

(frm1.lblP1JoyUp.Height / 2)
frm1.lblP1JoyUp.Left = (frm1.Width / 2) -

(frm1.lblP1JoyUp.Width / 2)
Else
frm1.lblP1JoyUp.Visible = False
frm1.lblP1JoyUp.Top = 10
frm1.lblP1JoyUp.Left = 10
End If
End Sub

If I check a checkbox it makes a label on form1 visible and moves it to

the center of the form. It now seems to be broken. The label never becomes
visible when I step through the code in my debugger. This happened after I
change my code to your method for switching between forms (which works
great). Any ideas what I'm missing here?

Thanks,
John

"yEaH rIgHt" wrote:
Try these two pieces of code. This should do what you want.
'-----------In Form1
Option Explicit On
Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents fm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
End If
fm.Show()
Me.Hide()
End Sub

Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.VisibleChanged
Me.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim bm As New Bitmap(OpenFileDialog1.FileName)
Me.BackgroundImage = bm
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
fm = Nothing
End Sub
End Class
'-----------End Form1

'-----------In Form2

Option Explicit On
Option Strict On

Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub
End Class


"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
> How do I switch back wthout creating a new instance?
>
> John
>
> "yEaH rIgHt" wrote:
>
> > Did you know by using the code below you're actually creating a new instance
> > of Form1? That's why the image disappears.
> >
> > I switch from form1 to form2 with this code:
> >
> > Dim frmLC as new frmLabelControls
> > frmlc.Show()
> > Me.Hide()
> >
> > I then switch back with this code:
> >
> > '---------Creates a New Form1 WITHOUT the image!
> > Dim frm1 As New Form1
> > frm1.Show()
> > Me.Hide()
> >
> >
> >
> >
> > "jcrouse" <an*******@discussions.microsoft.com> wrote in message
> > news:8C**********************************@microsof t.com...
> > > Ken,
> > > Here's my code:
> > >
> > > Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal
> > e As System.EventArgs) Handles mnuBgroundImage.Click
> > > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> > > Dim fs As New
System.IO.FileStream(OpenFileDialog1.FileName,
> > IO.FileMode.Open)
> > > Dim bm As New Bitmap(fs)
> > > fs.Close()
> > > Me.BackgroundImage = bm
> > > End If
> > > End Sub
> > >
> > > Any idea why I get an out of memory error?
> > >
> > > John
> >
> >
> >


Nov 20 '05 #25
Hi John,

Again, why not using that shared class I showed you.
With settings things in that from form2 you can do everything in the visible
event from form1.

Cor
Nov 20 '05 #26
Cor...I think I found it in your earlier post. I do not understand it.
Again, i am a n00b. It appears to examine the checkboxes as an array? My
checkboxes are individual controls. I may put them in an array for
addressing purposes in a loop at a later time when I understand .Net 2003
syntax a little bit better. Right now I just want to get it working. Here is
the code from my test application:

Form 1:

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents frm2 as Form2

Windows Form Designer Generated Code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If frm2 Is Nothing OrElse frm2.IsDisposed Then

frm2 = New Form2

End If

frm2.Show()

Me.Hide()

End Sub

Private Sub frm2_visiblechanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles frm2.VisibleChanged

Me.Show()

End Sub

Private Sub frm2_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles frm2.Closing

frm2 = Nothing

End Sub

End Class

Public Class Checked

Private Shared mCheck(25) As Boolean

Public Shared Sub SetCheck(ByVal index As Integer, ByVal setting As
Boolean)

mCheck(index) = setting

End Sub

Public Shared Function GetCheck(ByVal index As Integer) As Boolean

Return mCheck(index)

End Function

End Class

Form 2:

Public Class Form2

Inherits System.Windows.Forms.Form

Dim frm1 As Form1

Windows Form Designer Generated Code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm1 As New Form1

Me.Hide()

End Sub

Public Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles CheckBox1.CheckedChanged

If CheckBox1.Checked = True Then

CheckBox1.Checked = Checked.GetCheck(1)

End If

End Sub

End Class

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OS*************@TK2MSFTNGP12.phx.gbl...
Hi John,

Again, why not using that shared class I showed you.
With settings things in that from form2 you can do everything in the visible event from form1.

Cor

Nov 20 '05 #27
Umm, you don't need this in Form1. Unless, of course, you created your
lables this way. Did you?

'-- You don't need this
Dim WithEvents frmlc As frmLabelControls
You need this in form2

Dim frm1 as Form1

Public WriteOnly Property SetForm() As Form1
Set(ByVal Value As Form1)
frm1 = Value
End Set
End Property

Then in form1, Set the form. Like this.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
fm.SetForm = Me
End If
fm.Show()
Me.Hide
End Sub


"news.microsoft.com" <jcrouse> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
I believe so. I have the following code at the top of form1:

Imports System
Imports System.IO
Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mouseX As Integer
Dim mouseY As Integer
Dim _mouseDown As Boolean = False
Dim myMouseDown As Boolean
Dim WithEvents frmlc As frmLabelControls
Dim bmGlobal As Bitmap

The next to last line should do it.

????,
John

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
Do you have a reference to form1 in form2? You need a reference to that

form
if you want to minipulate any of the labels.

"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Another thing. I use the following code on form2 (frmLC):

Private Sub chkP1JoyUp_CheckedChanged(ByVal sender As
System.Object,
ByVal e As System.EventArgs) Handles chkP1JoyUp.CheckedChanged
If chkP1JoyUp.Checked = True Then
frm1.lblP1JoyUp.Visible = True
frm1.lblP1JoyUp.Top = (frm1.Height / 2) -

(frm1.lblP1JoyUp.Height / 2)
frm1.lblP1JoyUp.Left = (frm1.Width / 2) -

(frm1.lblP1JoyUp.Width / 2)
Else
frm1.lblP1JoyUp.Visible = False
frm1.lblP1JoyUp.Top = 10
frm1.lblP1JoyUp.Left = 10
End If
End Sub

If I check a checkbox it makes a label on form1 visible and moves it
to the center of the form. It now seems to be broken. The label never becomes visible when I step through the code in my debugger. This happened after I change my code to your method for switching between forms (which works
great). Any ideas what I'm missing here?

Thanks,
John

"yEaH rIgHt" wrote:

> Try these two pieces of code. This should do what you want.
>
>
> '-----------In Form1
> Option Explicit On
> Option Strict On
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
>
> Dim WithEvents fm As Form2
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e

As > System.EventArgs) Handles Button1.Click
> If fm Is Nothing OrElse fm.IsDisposed Then
> fm = New Form2()
> End If
> fm.Show()
> Me.Hide()
> End Sub
>
> Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles fm.VisibleChanged
> Me.Show()
> End Sub
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button2.Click
> If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> Dim bm As New Bitmap(OpenFileDialog1.FileName)
> Me.BackgroundImage = bm
> End If
> End Sub
>
>
> Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
> System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
> fm = Nothing
> End Sub
>
>
> End Class
> '-----------End Form1
>
> '-----------In Form2
>
> Option Explicit On
> Option Strict On
>
> Public Class Form2
> Inherits System.Windows.Forms.Form
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click
> Me.Hide()
> End Sub
> End Class
>
>
>
>
>
>
> "jcrouse" <jc*****@discussions.microsoft.com> wrote in message
> news:17**********************************@microsof t.com...
> > How do I switch back wthout creating a new instance?
> >
> > John
> >
> > "yEaH rIgHt" wrote:
> >
> > > Did you know by using the code below you're actually creating a new > instance
> > > of Form1? That's why the image disappears.
> > >
> > > I switch from form1 to form2 with this code:
> > >
> > > Dim frmLC as new frmLabelControls
> > > frmlc.Show()
> > > Me.Hide()
> > >
> > > I then switch back with this code:
> > >
> > > '---------Creates a New Form1 WITHOUT the image!
> > > Dim frm1 As New Form1
> > > frm1.Show()
> > > Me.Hide()
> > >
> > >
> > >
> > >
> > > "jcrouse" <an*******@discussions.microsoft.com> wrote in message
> > > news:8C**********************************@microsof t.com...
> > > > Ken,
> > > > Here's my code:
> > > >
> > > > Private Sub mnuBgroundImage_Click(ByVal sender As

System.Object,
> ByVal
> > > e As System.EventArgs) Handles mnuBgroundImage.Click
> > > > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> > > > Dim fs As New
> System.IO.FileStream(OpenFileDialog1.FileName,
> > > IO.FileMode.Open)
> > > > Dim bm As New Bitmap(fs)
> > > > fs.Close()
> > > > Me.BackgroundImage = bm
> > > > End If
> > > > End Sub
> > > >
> > > > Any idea why I get an out of memory error?
> > > >
> > > > John
> > >
> > >
> > >
>
>
>



Nov 20 '05 #28
Remove the Dim frm1 As New Form1 in the Button click event in form2. You
created a new Form1 with that code. Why?

"jcrouse" <me> wrote in message
news:en**************@TK2MSFTNGP11.phx.gbl...
Cor...I think I found it in your earlier post. I do not understand it.
Again, i am a n00b. It appears to examine the checkboxes as an array? My
checkboxes are individual controls. I may put them in an array for
addressing purposes in a loop at a later time when I understand .Net 2003
syntax a little bit better. Right now I just want to get it working. Here is the code from my test application:

Form 1:

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents frm2 as Form2

Windows Form Designer Generated Code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If frm2 Is Nothing OrElse frm2.IsDisposed Then

frm2 = New Form2

End If

frm2.Show()

Me.Hide()

End Sub

Private Sub frm2_visiblechanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles frm2.VisibleChanged

Me.Show()

End Sub

Private Sub frm2_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles frm2.Closing

frm2 = Nothing

End Sub

End Class

Public Class Checked

Private Shared mCheck(25) As Boolean

Public Shared Sub SetCheck(ByVal index As Integer, ByVal setting As
Boolean)

mCheck(index) = setting

End Sub

Public Shared Function GetCheck(ByVal index As Integer) As Boolean

Return mCheck(index)

End Function

End Class

Form 2:

Public Class Form2

Inherits System.Windows.Forms.Form

Dim frm1 As Form1

Windows Form Designer Generated Code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm1 As New Form1

Me.Hide()

End Sub

Public Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

If CheckBox1.Checked = True Then

CheckBox1.Checked = Checked.GetCheck(1)

End If

End Sub

End Class

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OS*************@TK2MSFTNGP12.phx.gbl...
Hi John,

Again, why not using that shared class I showed you.
With settings things in that from form2 you can do everything in the

visible
event from form1.

Cor


Nov 20 '05 #29
The only place that string appears in Form2 is here:

Public Class frmLabelControls
Inherits System.Windows.Forms.Form
Dim frm1 as New Form1

I am suspecting the code you are looking at has since been changed. Please
see the other post for the code from my test app.

Thank you for your help,
John

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
Remove the Dim frm1 As New Form1 in the Button click event in form2. You
created a new Form1 with that code. Why?

"jcrouse" <me> wrote in message
news:en**************@TK2MSFTNGP11.phx.gbl...
Cor...I think I found it in your earlier post. I do not understand it.
Again, i am a n00b. It appears to examine the checkboxes as an array? My
checkboxes are individual controls. I may put them in an array for
addressing purposes in a loop at a later time when I understand .Net 2003 syntax a little bit better. Right now I just want to get it working.
Here is
the code from my test application:

Form 1:

Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents frm2 as Form2

Windows Form Designer Generated Code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If frm2 Is Nothing OrElse frm2.IsDisposed Then

frm2 = New Form2

End If

frm2.Show()

Me.Hide()

End Sub

Private Sub frm2_visiblechanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles frm2.VisibleChanged

Me.Show()

End Sub

Private Sub frm2_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles frm2.Closing

frm2 = Nothing

End Sub

End Class

Public Class Checked

Private Shared mCheck(25) As Boolean

Public Shared Sub SetCheck(ByVal index As Integer, ByVal setting As
Boolean)

mCheck(index) = setting

End Sub

Public Shared Function GetCheck(ByVal index As Integer) As Boolean

Return mCheck(index)

End Function

End Class

Form 2:

Public Class Form2

Inherits System.Windows.Forms.Form

Dim frm1 As Form1

Windows Form Designer Generated Code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm1 As New Form1

Me.Hide()

End Sub

Public Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,

ByVal
e As System.EventArgs) Handles CheckBox1.CheckedChanged

If CheckBox1.Checked = True Then

CheckBox1.Checked = Checked.GetCheck(1)

End If

End Sub

End Class

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OS*************@TK2MSFTNGP12.phx.gbl...
Hi John,

Again, why not using that shared class I showed you.
With settings things in that from form2 you can do everything in the

visible
event from form1.

Cor



Nov 20 '05 #30
It seems that I need form2 declared somehow in form1. If I comment out this
line:

Dim WithEvents frm2 as Form2

then the following code is no good.\

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If frm2 Is Nothing OrElse frm2.IsDisposed Then

frm2 = New Form2

frm2.SetForm = Me

End If

frm2.Show()

Me.Hide()

End Sub

It underlines all of the frm2's in the Button1 Click event since they are
not declared.

Thanks, what now, I think we're close,

John



"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
Umm, you don't need this in Form1. Unless, of course, you created your
lables this way. Did you?

'-- You don't need this
Dim WithEvents frmlc As frmLabelControls
You need this in form2

Dim frm1 as Form1

Public WriteOnly Property SetForm() As Form1
Set(ByVal Value As Form1)
frm1 = Value
End Set
End Property

Then in form1, Set the form. Like this.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
fm.SetForm = Me
End If
fm.Show()
Me.Hide
End Sub


"news.microsoft.com" <jcrouse> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
I believe so. I have the following code at the top of form1:

Imports System
Imports System.IO
Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mouseX As Integer
Dim mouseY As Integer
Dim _mouseDown As Boolean = False
Dim myMouseDown As Boolean
Dim WithEvents frmlc As frmLabelControls
Dim bmGlobal As Bitmap

The next to last line should do it.

????,
John

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
Do you have a reference to form1 in form2? You need a reference to that
form
if you want to minipulate any of the labels.

"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
> Another thing. I use the following code on form2 (frmLC):
>
> Private Sub chkP1JoyUp_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkP1JoyUp.CheckedChanged
> If chkP1JoyUp.Checked = True Then
> frm1.lblP1JoyUp.Visible = True
> frm1.lblP1JoyUp.Top = (frm1.Height / 2) -
(frm1.lblP1JoyUp.Height / 2)
> frm1.lblP1JoyUp.Left = (frm1.Width / 2) -
(frm1.lblP1JoyUp.Width / 2)
> Else
> frm1.lblP1JoyUp.Visible = False
> frm1.lblP1JoyUp.Top = 10
> frm1.lblP1JoyUp.Left = 10
> End If
> End Sub
>
> If I check a checkbox it makes a label on form1 visible and moves it to the center of the form. It now seems to be broken. The label never becomes visible when I step through the code in my debugger. This happened
after
I change my code to your method for switching between forms (which works
great). Any ideas what I'm missing here?
>
> Thanks,
> John
>
> "yEaH rIgHt" wrote:
>
> > Try these two pieces of code. This should do what you want.
> >
> >
> > '-----------In Form1
> > Option Explicit On
> > Option Strict On
> >
> > Public Class Form1
> > Inherits System.Windows.Forms.Form
> >
> >
> > Dim WithEvents fm As Form2
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As
> > System.EventArgs) Handles Button1.Click
> > If fm Is Nothing OrElse fm.IsDisposed Then
> > fm = New Form2()
> > End If
> > fm.Show()
> > Me.Hide()
> > End Sub
> >
> > Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e
As > > System.EventArgs) Handles fm.VisibleChanged
> > Me.Show()
> > End Sub
> >
> > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button2.Click
> > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> > Dim bm As New Bitmap(OpenFileDialog1.FileName)
> > Me.BackgroundImage = bm
> > End If
> > End Sub
> >
> >
> > Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
> > System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
> > fm = Nothing
> > End Sub
> >
> >
> > End Class
> > '-----------End Form1
> >
> > '-----------In Form2
> >
> > Option Explicit On
> > Option Strict On
> >
> > Public Class Form2
> > Inherits System.Windows.Forms.Form
> >
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As
> > System.EventArgs) Handles Button1.Click
> > Me.Hide()
> > End Sub
> > End Class
> >
> >
> >
> >
> >
> >
> > "jcrouse" <jc*****@discussions.microsoft.com> wrote in message
> > news:17**********************************@microsof t.com...
> > > How do I switch back wthout creating a new instance?
> > >
> > > John
> > >
> > > "yEaH rIgHt" wrote:
> > >
> > > > Did you know by using the code below you're actually creating
a new
> > instance
> > > > of Form1? That's why the image disappears.
> > > >
> > > > I switch from form1 to form2 with this code:
> > > >
> > > > Dim frmLC as new frmLabelControls
> > > > frmlc.Show()
> > > > Me.Hide()
> > > >
> > > > I then switch back with this code:
> > > >
> > > > '---------Creates a New Form1 WITHOUT the image!
> > > > Dim frm1 As New Form1
> > > > frm1.Show()
> > > > Me.Hide()
> > > >
> > > >
> > > >
> > > >
> > > > "jcrouse" <an*******@discussions.microsoft.com> wrote in

message > > > > news:8C**********************************@microsof t.com...
> > > > > Ken,
> > > > > Here's my code:
> > > > >
> > > > > Private Sub mnuBgroundImage_Click(ByVal sender As
System.Object,
> > ByVal
> > > > e As System.EventArgs) Handles mnuBgroundImage.Click
> > > > > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then > > > > > Dim fs As New
> > System.IO.FileStream(OpenFileDialog1.FileName,
> > > > IO.FileMode.Open)
> > > > > Dim bm As New Bitmap(fs)
> > > > > fs.Close()
> > > > > Me.BackgroundImage = bm
> > > > > End If
> > > > > End Sub
> > > > >
> > > > > Any idea why I get an out of memory error?
> > > > >
> > > > > John
> > > >
> > > >
> > > >
> >
> >
> >



Nov 20 '05 #31
Hi John,

I thought bellow is your whole application.
(With 2 textboxes, without the XML, without BackImage)

It is just a sample, I have done nothing to let it look nice.

I hope this shows you an easy way?

Cor
-------------------------------------------------------
It needs a project with 2 forms
on form 1
2 labels and a button
on form 2
2 checkboxes and a button

And than paste in this code
\\\Form 1
Private WithEvents frm2 As New Form2
Private lblArea() As Label = New Label() {Label1, Label2}
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lblArea = New Label() {Label1, Label2}
frm2.Show()
frm2.TopLevel = True
End Sub
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
For i As Integer = 0 To lblArea.Length - 1
lblArea(i).Visible = Checked.GetCheck(i)
Next
Me.Show()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
frm2.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm2.Show()
Me.Hide()
End Sub
End Class
Public Class Checked
Private Shared mCheck(25) As Boolean
Public Shared Sub SetCheck(ByVal index As _
Integer, ByVal setting As Boolean)
mCheck(index) = setting
End Sub
Public Shared Function GetCheck(ByVal _
index As Integer) As Boolean
Return mCheck(index)
End Function
'End Class
///
\\\form2
\\\Form2
Private chkArea() As CheckBox
Private Sub Form2_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
chkArea = New CheckBox() {CheckBox1, CheckBox2}
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To chkArea.Length - 1
Checked.SetCheck(i, chkArea(i).Checked)
Next
Me.Hide()
End Sub
///

Nov 20 '05 #32
With the above mention line in, everything works the way it should. I really
want to say thanks for your (and Cor's) help on this issue. See my posts in
a few days when I start the XML reader portion. That ought to be fun. I'll
be looking for you Cor.

Thanks,
John
"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
Umm, you don't need this in Form1. Unless, of course, you created your
lables this way. Did you?

'-- You don't need this
Dim WithEvents frmlc As frmLabelControls
You need this in form2

Dim frm1 as Form1

Public WriteOnly Property SetForm() As Form1
Set(ByVal Value As Form1)
frm1 = Value
End Set
End Property

Then in form1, Set the form. Like this.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If fm Is Nothing OrElse fm.IsDisposed Then
fm = New Form2()
fm.SetForm = Me
End If
fm.Show()
Me.Hide
End Sub


"news.microsoft.com" <jcrouse> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
I believe so. I have the following code at the top of form1:

Imports System
Imports System.IO
Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mouseX As Integer
Dim mouseY As Integer
Dim _mouseDown As Boolean = False
Dim myMouseDown As Boolean
Dim WithEvents frmlc As frmLabelControls
Dim bmGlobal As Bitmap

The next to last line should do it.

????,
John

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
Do you have a reference to form1 in form2? You need a reference to that
form
if you want to minipulate any of the labels.

"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
> Another thing. I use the following code on form2 (frmLC):
>
> Private Sub chkP1JoyUp_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkP1JoyUp.CheckedChanged
> If chkP1JoyUp.Checked = True Then
> frm1.lblP1JoyUp.Visible = True
> frm1.lblP1JoyUp.Top = (frm1.Height / 2) -
(frm1.lblP1JoyUp.Height / 2)
> frm1.lblP1JoyUp.Left = (frm1.Width / 2) -
(frm1.lblP1JoyUp.Width / 2)
> Else
> frm1.lblP1JoyUp.Visible = False
> frm1.lblP1JoyUp.Top = 10
> frm1.lblP1JoyUp.Left = 10
> End If
> End Sub
>
> If I check a checkbox it makes a label on form1 visible and moves it to the center of the form. It now seems to be broken. The label never becomes visible when I step through the code in my debugger. This happened
after
I change my code to your method for switching between forms (which works
great). Any ideas what I'm missing here?
>
> Thanks,
> John
>
> "yEaH rIgHt" wrote:
>
> > Try these two pieces of code. This should do what you want.
> >
> >
> > '-----------In Form1
> > Option Explicit On
> > Option Strict On
> >
> > Public Class Form1
> > Inherits System.Windows.Forms.Form
> >
> >
> > Dim WithEvents fm As Form2
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As
> > System.EventArgs) Handles Button1.Click
> > If fm Is Nothing OrElse fm.IsDisposed Then
> > fm = New Form2()
> > End If
> > fm.Show()
> > Me.Hide()
> > End Sub
> >
> > Private Sub fm_VisibleChanged(ByVal sender As Object, ByVal e
As > > System.EventArgs) Handles fm.VisibleChanged
> > Me.Show()
> > End Sub
> >
> > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button2.Click
> > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
> > Dim bm As New Bitmap(OpenFileDialog1.FileName)
> > Me.BackgroundImage = bm
> > End If
> > End Sub
> >
> >
> > Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
> > System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
> > fm = Nothing
> > End Sub
> >
> >
> > End Class
> > '-----------End Form1
> >
> > '-----------In Form2
> >
> > Option Explicit On
> > Option Strict On
> >
> > Public Class Form2
> > Inherits System.Windows.Forms.Form
> >
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As
> > System.EventArgs) Handles Button1.Click
> > Me.Hide()
> > End Sub
> > End Class
> >
> >
> >
> >
> >
> >
> > "jcrouse" <jc*****@discussions.microsoft.com> wrote in message
> > news:17**********************************@microsof t.com...
> > > How do I switch back wthout creating a new instance?
> > >
> > > John
> > >
> > > "yEaH rIgHt" wrote:
> > >
> > > > Did you know by using the code below you're actually creating
a new
> > instance
> > > > of Form1? That's why the image disappears.
> > > >
> > > > I switch from form1 to form2 with this code:
> > > >
> > > > Dim frmLC as new frmLabelControls
> > > > frmlc.Show()
> > > > Me.Hide()
> > > >
> > > > I then switch back with this code:
> > > >
> > > > '---------Creates a New Form1 WITHOUT the image!
> > > > Dim frm1 As New Form1
> > > > frm1.Show()
> > > > Me.Hide()
> > > >
> > > >
> > > >
> > > >
> > > > "jcrouse" <an*******@discussions.microsoft.com> wrote in

message > > > > news:8C**********************************@microsof t.com...
> > > > > Ken,
> > > > > Here's my code:
> > > > >
> > > > > Private Sub mnuBgroundImage_Click(ByVal sender As
System.Object,
> > ByVal
> > > > e As System.EventArgs) Handles mnuBgroundImage.Click
> > > > > If OpenFileDialog1.ShowDialog() = DialogResult.OK Then > > > > > Dim fs As New
> > System.IO.FileStream(OpenFileDialog1.FileName,
> > > > IO.FileMode.Open)
> > > > > Dim bm As New Bitmap(fs)
> > > > > fs.Close()
> > > > > Me.BackgroundImage = bm
> > > > > End If
> > > > > End Sub
> > > > >
> > > > > Any idea why I get an out of memory error?
> > > > >
> > > > > John
> > > >
> > > >
> > > >
> >
> >
> >



Nov 20 '05 #33
WOW, thanks Cor. That's a lot of effort. I appreciate it. I'll look at it
this evening. No the code I've been posting is just a sample application. My
real code is probably 30 pages long. Mostly because i haven't implimented
and arrays or loops yet. Just lots of IF then ELSE's until I get the hang of
it. Believe it or not the sad thing here is that I actually taught a few
semesters of Basic and about 6 semesters of Intro to VB5 and VB6 at the
local college. Things sure have changed. I don't know how you guys keep up
with it all.

Later,
John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eQ*************@TK2MSFTNGP11.phx.gbl...
Hi John,

I thought bellow is your whole application.
(With 2 textboxes, without the XML, without BackImage)

It is just a sample, I have done nothing to let it look nice.

I hope this shows you an easy way?

Cor
-------------------------------------------------------
It needs a project with 2 forms
on form 1
2 labels and a button
on form 2
2 checkboxes and a button

And than paste in this code
\\\Form 1
Private WithEvents frm2 As New Form2
Private lblArea() As Label = New Label() {Label1, Label2}
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lblArea = New Label() {Label1, Label2}
frm2.Show()
frm2.TopLevel = True
End Sub
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
For i As Integer = 0 To lblArea.Length - 1
lblArea(i).Visible = Checked.GetCheck(i)
Next
Me.Show()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
frm2.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm2.Show()
Me.Hide()
End Sub
End Class
Public Class Checked
Private Shared mCheck(25) As Boolean
Public Shared Sub SetCheck(ByVal index As _
Integer, ByVal setting As Boolean)
mCheck(index) = setting
End Sub
Public Shared Function GetCheck(ByVal _
index As Integer) As Boolean
Return mCheck(index)
End Function
'End Class
///
\\\form2
\\\Form2
Private chkArea() As CheckBox
Private Sub Form2_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
chkArea = New CheckBox() {CheckBox1, CheckBox2}
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To chkArea.Length - 1
Checked.SetCheck(i, chkArea(i).Checked)
Next
Me.Hide()
End Sub
///

Nov 20 '05 #34
Cor,
This will cause an error if the user closes Form2 and the clicks this again.
Go ahead and try it. I think this project is now going backwards instead of
forwards. Good Luck

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm2.Show()
Me.Hide()
End Sub

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eQ*************@TK2MSFTNGP11.phx.gbl...
Hi John,

I thought bellow is your whole application.
(With 2 textboxes, without the XML, without BackImage)

It is just a sample, I have done nothing to let it look nice.

I hope this shows you an easy way?

Cor
-------------------------------------------------------
It needs a project with 2 forms
on form 1
2 labels and a button
on form 2
2 checkboxes and a button

And than paste in this code
\\\Form 1
Private WithEvents frm2 As New Form2
Private lblArea() As Label = New Label() {Label1, Label2}
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lblArea = New Label() {Label1, Label2}
frm2.Show()
frm2.TopLevel = True
End Sub
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
For i As Integer = 0 To lblArea.Length - 1
lblArea(i).Visible = Checked.GetCheck(i)
Next
Me.Show()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
frm2.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm2.Show()
Me.Hide()
End Sub
End Class
Public Class Checked
Private Shared mCheck(25) As Boolean
Public Shared Sub SetCheck(ByVal index As _
Integer, ByVal setting As Boolean)
mCheck(index) = setting
End Sub
Public Shared Function GetCheck(ByVal _
index As Integer) As Boolean
Return mCheck(index)
End Function
'End Class
///
\\\form2
\\\Form2
Private chkArea() As CheckBox
Private Sub Form2_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
chkArea = New CheckBox() {CheckBox1, CheckBox2}
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To chkArea.Length - 1
Checked.SetCheck(i, chkArea(i).Checked)
Next
Me.Hide()
End Sub
///

Nov 20 '05 #35
Hi,
This will cause an error if the user closes Form2 and the clicks this again. Go ahead and try it. I think this project is now going backwards instead of forwards. Good Luck


May I show John, how to use a shared class, which prevents him from writting
at least 25 complext methods with events?

Your sample has one and it is even difficult to explain

What you told will not give an error, however I left a piece what should be
removed
\\\Form 1
Private WithEvents frm2 As New Form2
Private lblArea() As Label = New Label() {Label1, Label2}
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lblArea = New Label() {Label1, Label2}
frm2.Show()
frm2.TopLevel = True

The last 2 rows should be deleted.

And to prevent that the user closes form 2 you can hide the control box or
prevent just closing of that form using the control box by.

Private Sub Form2_Closing(ByVal sender As _
Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
e.Cancel = True
End Sub

Cor
Nov 20 '05 #36
It won't create an error? You're nuts. You didn't tell him to cancel the
close or hide the control box, did you?
Your sample has one and it is even difficult to explain
People with low IQs (Cor), everything is hard to explain. Good riddance
genuis.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O%****************@TK2MSFTNGP10.phx.gbl... Hi,
This will cause an error if the user closes Form2 and the clicks this again.
Go ahead and try it. I think this project is now going backwards instead

of
forwards. Good Luck


May I show John, how to use a shared class, which prevents him from

writting at least 25 complext methods with events?
What you told will not give an error, however I left a piece what should be removed
\\\Form 1
Private WithEvents frm2 As New Form2
Private lblArea() As Label = New Label() {Label1, Label2}
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lblArea = New Label() {Label1, Label2}
frm2.Show()
frm2.TopLevel = True

The last 2 rows should be deleted.

And to prevent that the user closes form 2 you can hide the control box or
prevent just closing of that form using the control box by.

Private Sub Form2_Closing(ByVal sender As _
Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
e.Cancel = True
End Sub

Cor

Nov 20 '05 #37
Why are you hostile to Cor? He was trying to help. You should have just
said "thank you" and been on your way.

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com:
It won't create an error? You're nuts. You didn't tell him to cancel the
close or hide the control box, did you?
Your sample has one and it is even difficult to explain


People with low IQs (Cor), everything is hard to explain. Good riddance
genuis.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O%****************@TK2MSFTNGP10.phx.gbl...
Hi,
This will cause an error if the user closes Form2 and the clicks
this

again.
Go ahead and try it. I think this project is now going backwards
instead

of
forwards. Good Luck


May I show John, how to use a shared class, which prevents him from

writting
at least 25 complext methods with events?
What you told will not give an error, however I left a piece what
should

be
removed
> \\\Form 1
> Private WithEvents frm2 As New Form2
> Private lblArea() As Label = New Label() {Label1, Label2}
> Private Sub Form1_Load(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> lblArea = New Label() {Label1, Label2}
> frm2.Show()
> frm2.TopLevel = True

The last 2 rows should be deleted.

And to prevent that the user closes form 2 you can hide the control box
or
prevent just closing of that form using the control box by.

Private Sub Form2_Closing(ByVal sender As _
Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
e.Cancel = True
End Sub

Cor


Nov 20 '05 #38
Thank you for what? Please explain.

"scorpion53061" <ad***@nospampleasekjmsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Why are you hostile to Cor? He was trying to help. You should have just
said "thank you" and been on your way.

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com:
It won't create an error? You're nuts. You didn't tell him to cancel the
close or hide the control box, did you?
Your sample has one and it is even difficult to explain


People with low IQs (Cor), everything is hard to explain. Good riddance
genuis.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O%****************@TK2MSFTNGP10.phx.gbl...
Hi,

> This will cause an error if the user closes Form2 and the clicks
> this
again.
> Go ahead and try it. I think this project is now going backwards
> instead
of
> forwards. Good Luck

May I show John, how to use a shared class, which prevents him from

writting
at least 25 complext methods with events?
What you told will not give an error, however I left a piece what
should

be
removed

> > \\\Form 1
> > Private WithEvents frm2 As New Form2
> > Private lblArea() As Label = New Label() {Label1, Label2}
> > Private Sub Form1_Load(ByVal sender As Object, _
> > ByVal e As System.EventArgs) Handles MyBase.Load
> > lblArea = New Label() {Label1, Label2}
> > frm2.Show()
> > frm2.TopLevel = True
The last 2 rows should be deleted.

And to prevent that the user closes form 2 you can hide the control box or
prevent just closing of that form using the control box by.

Private Sub Form2_Closing(ByVal sender As _
Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
e.Cancel = True
End Sub

Cor

Nov 20 '05 #39
My fault. I had not read the whole thread.

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com:
Thank you for what? Please explain.

"scorpion53061" <ad***@nospampleasekjmsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Why are you hostile to Cor? He was trying to help. You should have
just
said "thank you" and been on your way.

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com:
It won't create an error? You're nuts. You didn't tell him to cancel
the
close or hide the control box, did you?

> Your sample has one and it is even difficult to explain

People with low IQs (Cor), everything is hard to explain. Good
riddance
genuis.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O%****************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> > This will cause an error if the user closes Form2 and the clicks
> > this
> again.
> > Go ahead and try it. I think this project is now going backwards
> > instead
> of
> > forwards. Good Luck
>
> May I show John, how to use a shared class, which prevents him
> from
writting
> at least 25 complext methods with events?
>
>
> What you told will not give an error, however I left a piece what
> should
be
> removed
>
> > > \\\Form 1
> > > Private WithEvents frm2 As New Form2
> > > Private lblArea() As Label = New Label() {Label1, Label2}
> > > Private Sub Form1_Load(ByVal sender As Object, _
> > > ByVal e As System.EventArgs) Handles MyBase.Load
> > > lblArea = New Label() {Label1, Label2}
> > > frm2.Show()
> > > frm2.TopLevel = True
> The last 2 rows should be deleted.
>
> And to prevent that the user closes form 2 you can hide the
> control box > or
> prevent just closing of that form using the control box by.
>
> Private Sub Form2_Closing(ByVal sender As _
> Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles
> MyBase.Closing
> e.Cancel = True
> End Sub
>
> Cor
>
>


Nov 20 '05 #40

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

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
5
by: Chris Beall | last post by:
I'm displaying an image that is also a link against a black background. In Netscape 7.1, the current background color is displayed as a horizontal bar below the image. This allows :hover effects...
21
by: Dan V. | last post by:
I have tried a number of things including preloading, but the background image (water tile in header) in IE 6 will not display where other browsers will....
1
by: Bill | last post by:
Problem: Combo box data disappears from view when a requery is done See "Background" below for details on tables, forms & controls On a form, I want to use the setting of bound combo box C1...
4
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all I have the following code: I am trying to use the value of the image button to evaluate what plan the user has chosen, i.e. it request("submit1")="Basic", then the user chose basic plan...
1
by: Jim in Arizona | last post by:
I created a public application based variable not within any procedure, like so: Partial Class lobbytimes_lobbytimes Inherits System.Web.UI.Page Public BackgroundImage As String Protected...
1
by: Rohit111111 | last post by:
I have my base form which has background image , tool bar etc,All other forms inherit it. The background image size is162kb and it is in PNG format.All the other forms also has many images since...
0
by: Vyas111111 | last post by:
I have my base form which has background image , tool bar etc,All other forms inherit it. The background image size is162kb and it is in PNG format.All the other forms also has many images since we...
13
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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,...
0
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...
0
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...

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.