Click here to Skip to main content
15,900,906 members
Home / Discussions / Windows Forms
   

Windows Forms

 
GeneralRe: Secondhand comp BIOS disk Pin
Granny200712-May-11 19:20
Granny200712-May-11 19:20 
GeneralRe: Secondhand comp BIOS disk Pin
Richard MacCutchan12-May-11 22:15
mveRichard MacCutchan12-May-11 22:15 
AnswerRe: Secondhand comp BIOS disk Pin
Abhinav S12-May-11 22:50
Abhinav S12-May-11 22:50 
GeneralRe: Secondhand comp BIOS disk Pin
Granny200713-May-11 12:57
Granny200713-May-11 12:57 
GeneralRe: Secondhand comp BIOS disk Pin
Thomas Krojer24-May-11 3:29
Thomas Krojer24-May-11 3:29 
QuestionHow come I can call Public Methods of a Form as if they were Shared? Pin
Sander Rossel11-May-11 8:49
professionalSander Rossel11-May-11 8:49 
AnswerRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Luc Pattyn11-May-11 9:47
sitebuilderLuc Pattyn11-May-11 9:47 
GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Sander Rossel11-May-11 10:27
professionalSander Rossel11-May-11 10:27 
Luc Pattyn wrote:
If this is about VB6 or older

Nope, the code example I showed was VB.NET, Framework 4.0.

Luc Pattyn wrote:
In VB.NET, your code does not compile.

It compiles, runs great and works as expected (the Form is called with its Width set, the Buttons Text set etc.).

I just can't get over the fact that it goes against everything I have learned about encapsulation and that .NET is right there supporting it.

Luc Pattyn wrote:
You would need "Form1 implements Form", and then all methods/properties in DoSomethingElse() generate compile errors.

It gets worse....
VB
Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Form2.Something()
		Form2.Button1.Text = "Hello"
                Form2.Show()
	End Sub

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

End Class

Public Class Form2

	Public Sub Something()
		Me.Text = "Test"
		Me.NothingIsSacredAnymore()
	End Sub

	Private Sub NothingIsSacredAnymore()
		MessageBox.Show("Hello")
	End Sub

End Class

I am starting Form1, which immediatly calls Form2.Something, without first instantiating it. Form2.Something calls a Private Sub and everything is ok. I can't call NothingIsSacredAnymore directly from Form1 though.
When I start the application I first get the MessageBox saying "Hello", then Form1 and Form2 show and Form2 has it's text set to "Test" and its Buttons Text set to "Hello".
When I click the Button1 on Form1 nothing happens if Form2 is already open. If it is not it opens Form2, but with default property settings.
It's an OO world.

GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Dave Kreskowiak11-May-11 10:56
mveDave Kreskowiak11-May-11 10:56 
GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Sander Rossel11-May-11 11:09
professionalSander Rossel11-May-11 11:09 
GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Luc Pattyn11-May-11 12:41
sitebuilderLuc Pattyn11-May-11 12:41 
AnswerRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Eddy Vluggen11-May-11 10:44
professionalEddy Vluggen11-May-11 10:44 
GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Sander Rossel11-May-11 11:05
professionalSander Rossel11-May-11 11:05 
GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Eddy Vluggen11-May-11 11:34
professionalEddy Vluggen11-May-11 11:34 
GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
MicroVirus30-May-11 4:55
MicroVirus30-May-11 4:55 
AnswerRe: How come I can call Public Methods of a Form as if they were Shared? Pin
CS140124-Jun-11 0:53
CS140124-Jun-11 0:53 
GeneralRe: How come I can call Public Methods of a Form as if they were Shared? Pin
Sander Rossel24-Jun-11 7:58
professionalSander Rossel24-Jun-11 7:58 
QuestionOnly one Exe at an instance Pin
pix_programmer23-Apr-11 6:19
pix_programmer23-Apr-11 6:19 
AnswerRe: Only one Exe at an instance Pin
Luc Pattyn23-Apr-11 7:18
sitebuilderLuc Pattyn23-Apr-11 7:18 
AnswerRe: Only one Exe at an instance Pin
Shameel26-Apr-11 2:00
professionalShameel26-Apr-11 2:00 
QuestionHow can i create a receipt(size 400*400) in crystal report C# 2.0 windows application [modified] Pin
Member 436368017-Apr-11 20:14
Member 436368017-Apr-11 20:14 
AnswerRe: How can i create a receipt(size 400*400) in crystal report C# 2.0 windows application Pin
thatraja7-Jun-11 1:15
professionalthatraja7-Jun-11 1:15 
QuestionWindows 7 doest launch application on startup Pin
Xmen Real 17-Apr-11 3:06
professional Xmen Real 17-Apr-11 3:06 
AnswerRe: Windows 7 doest launch application on startup Pin
RobCroll17-Apr-11 4:46
RobCroll17-Apr-11 4:46 
GeneralRe: Windows 7 doest launch application on startup Pin
Xmen Real 17-Apr-11 5:22
professional Xmen Real 17-Apr-11 5:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.