|
-
Mar 17th, 2005, 02:17 PM
#1
Thread Starter
Fanatic Member
Minimize Form1 With MainForm Code [SOLVED]
This does not work...
VB Code:
Private MainFormResize(blah blah)
If Me.WindowState.Minimized = True Then
Form1.WindowState.Minimized = True
Else
Form2.WindowState.Normal = True
End If
End Sub
All I want to do is minimize a modeless (toolbox window) form when I minimize the MainForm.
How do I minimize a 2nd visible form from the Main form??
Thanks
Last edited by epixelman; Mar 17th, 2005 at 05:04 PM.
-
Mar 17th, 2005, 02:25 PM
#2
Re: Minimize Form1 With MainForm Code
 Originally Posted by epixelman
This does not work...
VB Code:
Private MainFormResize(blah blah)
If Me.WindowState.Minimized = True Then
Form1.WindowState.Minimized = True
Else
Form2.WindowState.Normal = True
End If
End Sub
All I want to do is minimize a modeless (toolbox window) form when I minimize the MainForm.
How do I minimize a 2nd visible form from the Main form??
Thanks
you just arent setting the properties right... check the other post you made in here.. i answered it there
-
Mar 17th, 2005, 02:29 PM
#3
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
This is a different question on minimizing a form, not displaying.
The other post is a mistake... duplicate
Thanks
-
Mar 17th, 2005, 02:34 PM
#4
Re: Minimize Form1 With MainForm Code
yeah but what I am saying is that you are not using those properties right..
Me.WindowState.Minimized will not evaluate to a boolean like you are trying.. I can tell you are coding without option strict on. I recommend putting it on.
VB Code:
Private MainFormResize(blah blah)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form2.WindowState = FormWindowState.Normal
End If
End Sub
see what i mean
-
Mar 17th, 2005, 02:37 PM
#5
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
I'm just getting into this .NET...
Is Option Strict like Option Explicit??
And where does it go?
-
Mar 17th, 2005, 02:44 PM
#6
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
 Originally Posted by kleinma
VB Code:
Private MainFormResize(blah blah)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form2.WindowState = FormWindowState.Normal
End If
End Sub
Does this minimize both forms when I minimize the Main Form??
I am getting an error on line... (ref to non-standard member requires obj ref)
Private MainFormResize(blah blah)
If Me.WindowState = FormWindowState.Minimized Then
------>> Form1.WindowState = FormWindowState.Minimized
Else
------>> Form1.WindowState = FormWindowState.Normal
End If
End Sub
I'm only trying to minimize Form1 (toolbox) when I minimize MainForm (that is the name)
Thanks
-
Mar 17th, 2005, 02:45 PM
#7
Re: Minimize Form1 With MainForm Code
 Originally Posted by epixelman
I'm just getting into this .NET...
Is Option Strict like Option Explicit??
And where does it go?
yes and no..
they work together really, but you can have one on and one off vice versa..
your best bet is to put option strict and option explicit both on. This will ensure your code is as clean and correct as possible from a syntax point of view.
Option Strict requires explicit conversions of datatypes..
for example
Dim b As Boolean = "true"
this is setting a string datatype to a boolean (it converts it in the background), but if you had option strict on.. it would not let you do this.. you would have to do
Dim b As Boolean = true
maybe thats a bad example.. but i hope you get the idea..
here is a better example
VB Code:
Dim i As Integer = 100
MessageBox.Show(i)
with option strict, you need to make the integer a string.. because technically, the messagebox.show method needs a string, not an integer
VB Code:
Dim i As Integer = 100
MessageBox.Show(i.ToString)
you can turn on option strict and explict in the options so by default they are always on.. and you always have the option to specify them on or off in a specific class/form/module by coding it at the very top like option explicit in VB6
hope that helps...
-
Mar 17th, 2005, 02:46 PM
#8
Re: Minimize Form1 With MainForm Code
well where are Form1 and Form2 declared? what form are you calling the code from?
-
Mar 17th, 2005, 03:46 PM
#9
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
It all comes from the MainForm...
VB Code:
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
Dim fForm1 As New Form1()
fForm1.Show()
End Sub
Private Sub MainFormResize(sender As System.Object, e As System.EventArgs)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form1.WindowState = FormWindowState.Normal
End If
End Sub
I am using SharpDevelop for my IDE. I do not have an option to set the "Option Explicit" and "Option Strict" on.
Where in raw code does it go?
Above the namespace section?
Thanks
-
Mar 17th, 2005, 03:52 PM
#10
Re: Minimize Form1 With MainForm Code
yes at the very top of everything... same place you would put option explicit
Option Explicit On
Option Strict On
your problem is that the scope of your form variables are limited to the subs you create them in... move the declarations for the forms to the module level...
VB Code:
Private fForm1 as Form1
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
fForm1 = New Form1()
fForm1.Show()
End Sub
Private Sub MainFormResize(sender As System.Object, e As System.EventArgs)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form1.WindowState = FormWindowState.Normal
End If
End Sub
-
Mar 17th, 2005, 03:55 PM
#11
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
Module Level???
Where and how would I call them?
-
Mar 17th, 2005, 04:10 PM
#12
Re: Minimize Form1 With MainForm Code
i did the code for you..
basically what i mean is if you do this:
VB Code:
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
Dim fForm1 As New Form1()
fForm1.Show()
End Sub
only this sub routine can see or access fForm1
if you put outside a routine (in the general declarations section) you can access it anywhere as long as there is a new instance created (which I do in the button click code i posted)
to put something at the entire form level, you declare it at the top, below the Class defenition, and below and inheritence or implements statements...
VB Code:
Public Class MyForm
Inherits System.WIndows.Forms.Form
Private fForm1 as Form1
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
fForm1 = New Form1()
fForm1.Show()
End Sub
Private Sub MainFormResize(sender As System.Object, e As System.EventArgs)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form1.WindowState = FormWindowState.Normal
End If
End Sub
-
Mar 17th, 2005, 04:10 PM
#13
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
Here is my entire code...
VB Code:
Option Explicit On
Option Strict On
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace DisplayForms
Public Class MainForm
Inherits System.Windows.Forms.Form
Private button1 As System.Windows.Forms.Button
Public Shared Sub Main
Dim fMainForm As New MainForm
fMainForm.ShowDialog()
End Sub
Public Sub New()
MyBase.New
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent
' Add constructor code after InitializeComponents
End Sub
#Region " Windows Forms Designer generated code "
' This method is required for Windows Forms designer support.
' Do not change the method contents inside the source code editor. The Forms designer might
' not be able to load this method if it was changed manually.
Private Sub InitializeComponent()
Me.button1 = New System.Windows.Forms.Button
Me.SuspendLayout
'
'button1
'
Me.button1.Location = New System.Drawing.Point(40, 28)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(120, 40)
Me.button1.TabIndex = 0
Me.button1.Text = "button1"
AddHandler Me.button1.Click, AddressOf Me.Button1Click
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(560, 396)
Me.Controls.Add(Me.button1)
Me.Name = "MainForm"
Me.Text = "MainForm"
AddHandler Resize, AddressOf Me.MainFormResize
Me.ResumeLayout(false)
End Sub
#End Region
Private fForm1 as Form1
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
fForm1 = New Form1()
fForm1.Show()
End Sub
Private Sub MainFormResize(sender As System.Object, e As System.EventArgs)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form1.WindowState = FormWindowState.Normal
End If
End Sub
End Class
End Namespace
-
Mar 17th, 2005, 04:17 PM
#14
Re: Minimize Form1 With MainForm Code
move the
Private fForm1 As Form1 to below Inherits System.Windows.Forms.Form and you should be ok
-
Mar 17th, 2005, 04:20 PM
#15
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
This is what I have...
VB Code:
Public Class MainForm
Inherits System.Windows.Forms.Form
Private fForm1 As Form1
End Class
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
fForm1 = New Form1()
fForm1.Show()
End Sub
Private Sub MainFormResize(sender As System.Object, e As System.EventArgs)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form1.WindowState = FormWindowState.Normal
End If
End Sub
I get error....
"fForm1 is not declared"
-
Mar 17th, 2005, 04:24 PM
#16
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
I moved the "Private fForm As Form" to the top. I had two MainForm Classes.
Now I get the error... for lines...
---> Form1.WindowState = FormWindowState.Minimized
---> Form1.WindowState = FormWindowState.Normal
ERROR..
Ref to non-shared member requires an object ref.
-
Mar 17th, 2005, 04:26 PM
#17
Re: Minimize Form1 With MainForm Code
man I dont know what you are doing.. but it sure is wacky...
you have a public sub main in your MainForm class.. that declares a variable of type MainForm....
VB Code:
Option Explicit On
Option Strict On
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace DisplayForms
Public Class MainForm
Inherits System.Windows.Forms.Form
Private button1 As System.Windows.Forms.Button
Private fForm1 As Form1
Public Sub New()
MyBase.New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
' Add constructor code after InitializeComponents
End Sub
#Region " Windows Forms Designer generated code "
' This method is required for Windows Forms designer support.
' Do not change the method contents inside the source code editor. The Forms designer might
' not be able to load this method if it was changed manually.
Private Sub InitializeComponent()
Me.button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'button1
'
Me.button1.Location = New System.Drawing.Point(40, 28)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(120, 40)
Me.button1.TabIndex = 0
Me.button1.Text = "button1"
AddHandler Me.button1.Click, AddressOf Me.Button1Click
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(560, 396)
Me.Controls.Add(Me.button1)
Me.Name = "MainForm"
Me.Text = "MainForm"
AddHandler Resize, AddressOf Me.MainFormResize
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
fForm1 = New Form1
fForm1.Show()
End Sub
Private Sub MainFormResize(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.WindowState = FormWindowState.Minimized Then
fForm1.WindowState = FormWindowState.Minimized
Else
fForm1.WindowState = FormWindowState.Normal
End If
End Sub
End Class
End Namespace
Module modMain
Public Sub Main()
Application.Run(New DisplayForms.MainForm)
End Sub
End Module
-
Mar 17th, 2005, 04:37 PM
#18
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
This is what I have...
The recent post I submitted code that was missing a section... Try this.
VB Code:
Option Explicit On
Option Strict On
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace DisplayForms
Public Class MainForm
Inherits System.Windows.Forms.Form
Private button1 As System.Windows.Forms.Button
Private fForm1 As Form1
Public Shared Sub Main
Dim fMainForm As New MainForm
fMainForm.ShowDialog()
End Sub
Public Sub New()
MyBase.New
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent
' Add constructor code after InitializeComponents
End Sub
#Region " Windows Forms Designer generated code "
' This method is required for Windows Forms designer support.
' Do not change the method contents inside the source code editor. The Forms designer might
' not be able to load this method if it was changed manually.
Private Sub InitializeComponent()
Me.button1 = New System.Windows.Forms.Button
Me.SuspendLayout
'
'button1
'
Me.button1.Location = New System.Drawing.Point(40, 28)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(120, 40)
Me.button1.TabIndex = 0
Me.button1.Text = "button1"
AddHandler Me.button1.Click, AddressOf Me.Button1Click
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(560, 396)
Me.Controls.Add(Me.button1)
Me.Name = "MainForm"
Me.Text = "MainForm"
AddHandler Resize, AddressOf Me.MainFormResize
Me.ResumeLayout(false)
End Sub
#End Region
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
fForm1 = New Form1()
fForm1.Show()
End Sub
Private Sub MainFormResize(sender As System.Object, e As System.EventArgs)
If Me.WindowState = FormWindowState.Minimized Then
Form1.WindowState = FormWindowState.Minimized
Else
Form1.WindowState = FormWindowState.Normal
End If
End Sub
End Class
End Namespace
-
Mar 17th, 2005, 04:55 PM
#19
Re: Minimize Form1 With MainForm Code
come on man.. i think you can take the code i provided you, and work it into yours.. no?
-
Mar 17th, 2005, 05:00 PM
#20
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
I got it!!!
The two lines...
Form1.WindowState = FormWindowState.Minimized
Form1.WindowState = FormWindowState.Normal
has to have fForm1 instead of just Form1
Thanks
Frank
-
Mar 17th, 2005, 05:03 PM
#21
Re: Minimize Form1 With MainForm Code
 Originally Posted by epixelman
I got it!!!
The two lines...
Form1.WindowState = FormWindowState.Minimized
Form1.WindowState = FormWindowState.Normal
has to have fForm1 instead of just Form1
Thanks
Frank
great
-
Mar 17th, 2005, 05:04 PM
#22
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code
 Originally Posted by kleinma
come on man.. i think you can take the code i provided you, and work it into yours.. no?
I'm trying to stick with what the IDE formats.
The only error I was doings was...
1) I left the Sub Main out on one post.
2) I had two MainForm classes
3) I put the "Private fForm As Form1" line in the upper class (which you said) but I put in the 2nd MainForm class. I deleted the 2nd class and put it where it goes... up top
4) I forgot to change the Form1.WindowState to fForm1.WindowState
Thanks Man!!
-
Mar 17th, 2005, 05:27 PM
#23
Re: Minimize Form1 With MainForm Code
 Originally Posted by epixelman
I'm trying to stick with what the IDE formats.
The only error I was doings was...
1) I left the Sub Main out on one post.
2) I had two MainForm classes
3) I put the "Private fForm As Form1" line in the upper class (which you said) but I put in the 2nd MainForm class. I deleted the 2nd class and put it where it goes... up top
4) I forgot to change the Form1.WindowState to fForm1.WindowState
Thanks Man!!
yeah its harder to help when you dont use the microsoft IDE either.. it just makes certain things harder to explain...
-
Mar 17th, 2005, 06:10 PM
#24
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code [SOLVED]
I've played with the Visual Studio... this SharpDevelop IDE is not that much different.
Can you do me a favor Klien?
Below is the most basic code that SharpDevelop creates when I create a new project. I have not edit it at all.
Can you post a raw new project code for me so I can compare the difference and see if SharpDevelop is going to work?
Thanks
VB Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace NewProject
Public Class MainForm
Inherits System.Windows.Forms.Form
Public Shared Sub Main
Dim fMainForm As New MainForm
fMainForm.ShowDialog()
End Sub
Public Sub New()
MyBase.New
'
' The Me.InitializeComponent call is required for Windows Forms designer support.
'
Me.InitializeComponent
'
' TODO : Add constructor code after InitializeComponents
'
End Sub
#Region " Windows Forms Designer generated code "
' This method is required for Windows Forms designer support.
' Do not change the method contents inside the source code editor. The Forms designer might
' not be able to load this method if it was changed manually.
Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "MainForm"
Me.Text = "MainForm"
End Sub
#End Region
End Class
End Namespace
-
Mar 17th, 2005, 10:05 PM
#25
Re: Minimize Form1 With MainForm Code [SOLVED]
imports like system and system.drawing arent needed because they are automatically added for you on the project level when you create a new project
VB Code:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
Me.Text = "Form1"
End Sub
#End Region
End Class
-
Mar 18th, 2005, 06:42 AM
#26
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code [SOLVED]
Klien..
Here are the major differences I see...
MY SHARPDEVELOP IDE
=====================================
VB Code:
Public Shared Sub Main
Dim fMainForm As New MainForm
fMainForm.ShowDialog()
End Sub
YOUR VISUAL STUDIO IDE
=====================================
VB Code:
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Mine has the startup main, yours don't
Yours has the Dispose sub, mine don't.
Why, and what impact will my apps have?
Thanks
-
Mar 19th, 2005, 07:23 AM
#27
Thread Starter
Fanatic Member
Re: Minimize Form1 With MainForm Code [SOLVED]
Klein,
I would still like an answer from the question of my previous post about the diffrence bewteen the code.
BTW... I have found something I do not like about .NET. If you care to know see this post...
http://www.vbforums.com/showthread.php?t=329756
-
Mar 19th, 2005, 12:26 PM
#28
Re: Minimize Form1 With MainForm Code [SOLVED]
the only differences there are that it appears your IDE creates a sub main to start up the app, but makes it shared in the form class itself.. generally from what I have seen, programmers usually make a module (which means all public things in it are shared already) and put a sub main there.
the disposing thing is when the form is going to be disposed, it calls the dispose method on any components in the form to clean it up.. i imagine any of these components should get disposed of eventually anyway by the GC, so perhaps what the VS IDE adds in is just to speed up the process and get resources free as soon as possible...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|