I have attached a small project.
i have trouble getting access to controls on forms from other forms.
form3 cannot get access to the textbox on form2.
could someone look this over to see how I can access form 2 from form3??
Printable View
I have attached a small project.
i have trouble getting access to controls on forms from other forms.
form3 cannot get access to the textbox on form2.
could someone look this over to see how I can access form 2 from form3??
I haven't opened your zip file, but this is a quick access method:
Dim f As Form = Application.OpenForms("Form2")
You now have a variable referencing Form2; do with it what you will...
your code looks similar to the code below, it does not allow access to all forms, only some. open my code and look. I have approx. 35 forms and I want to use the method of calling them up that I already have if possible, other wise i will have too much code to change.
dim o2 as form1
in a command button:
o2 = new form2
o2.showdialog()
you seem to be labouring a different requirement here.
if showdialog works, but you can't access the textbox, then I wager that you have not set the textbox's modifier property to friend or public...
i don't open zip files, by the way.
oh, ok.
I will check the modifier property.
i can modify the textbox from form 2 but not from form3.
sorry, your solution did not help.
by the way, i sure as hell hope that you attempt to modify the textbox BEFORE you use the showdialog method. you realise, of course, that no code in form3 will execute until you have closed form2...?!
(in other words, use the show method, not the showdialog...)
I cannot use the .show method. it messes up the way the forms work.
since you have several forms, you will need to create a base form class which overloads showdialog (note that line 6 is for demo purposes only and should not be included in your production code):You will build MyEventArgs to house the most efficient collection type for handling the info you will be sending to your 30-something forms. You will call derived classes like this:vb.net Code:
Public Class Form2 Private _f As Form Overloads Sub ShowDialog(ByVal f As Form, ByVal e As MyEventArgs) _f = f ' _f now holds a reference to Form1, the public properties and fields of which can now be accessed Me.TextBox1.Text = e.TextString ' writes to the wretched textbox! Me.ShowDialog(_f) End Sub End Class Public Class MyEventArgs ' whatever needs to be passed to the forms, probably as a collection. this example uses a string only Private _msg As String Public Sub New(ByVal msg As String) _msg = msg End Sub ReadOnly Property TextString() As String Get Return _msg End Get End Property End Classvb.net Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim f As Form2 = New Form2 Dim fe As MyEventArgs = New MyEventArgs("Hello World") f.ShowDialog(Me, fe) End Sub
ok, i will start on it tomorrow.
i notice that most times there seem to be "Line Numbers" in vb.net code or is this just for the forum only?
thanks!!!!!
no. you can set line numbers to show in your vb ide by Tools > Options > Text Editor > Basic > General / (Display) Line Numbers.
ok and thanks!!!
The line numbers you see in posts on this forum are created by this forum. They have no relation to the line numbers in the original code, if it even came from an IDE. While you can turn line numbers on in VS I don't really see the point. It takes away some space that could otherwise be displaying code for one thing. 24" wide-screen, 1920x1200 monitor in portrait mode and I work with VS maximised all the time and I often wish the screen was wider. I don't know how people cope with smaller monitors. Also, how often do you really need to to see the line numbers? The IDE shows the current line number in the status bar so if you really need to get to a particular line you can using that.Quote:
Originally Posted by RonR
What is the problem with just doing this, it lets you do what you want ?
Code:Form2.ShowDialog()
'and
Form3.ShowDialog()
Quote:
Originally Posted by user name
no, it does not work when I have 3 forms on the screen and I want to access form 1.
now i know where BOTH line numbers come from.Quote:
Originally Posted by jmcilhinney
Quote:
Originally Posted by jmcilhinney
you've got a 24" wide-screen monitor!?
don't you just see a larger version of the same thing with a big monitor?
I have just opened your test project, changed the code to Form2.ShowDialog and Form3.ShowDialog and everything was ok.Quote:
Originally Posted by RonR
Quote:
Originally Posted by user name
try to get the text to display in form 2 from form3
You mean by pressing "to form 2" button like i did ?
Quote:
Originally Posted by user name
it does not work for me.
maybe it is because I have vb 2008 xe?
Just as a test for you, i have opened it in 2008pro, changed the code and zipped it back up.
i thought that i had to use the: o1 as new form3Quote:
Originally Posted by user name
does this create potential other issues??
If you have an A4 sheet of paper and an A3 sheet of paper, if the font is the same size on both then you get twice as much text on the A3 sheet. If you were to double the size of the font then then you get the same amount of text at twice the size.Quote:
Originally Posted by .paul.
If you've got more pixels on a screen you can fit more on it. If your screen is 1024x768 and you have a window a 1024x768 then it occupies the whole screen. The same form on a screen at 1920x1200 occupies only a fraction of the entire screen.