|
How does class C call class B ? If it has an instance of B, then it won't be disposed. If it's a member of the main form, it shouldn't be disposed.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Class C is not in the main form... it's in a secondary form in the main .exe
I first initialize the assembly (which contains Class B) from Class A:
Sub b1()
This is Class B with its initializing sub:
Class B
Dim host as object
Sub b1(byval host as object)
Me.host = host
End sub
End Class
Then I call sub C1 which is in class C in the main .exe
host.C1()
Maybe this isn’t right, but I'm not sure what's wrong
thanks
|
|
|
|
|
This looks convoluted. Passing objects like this is always bad, you should use delegates.
Looks like the assembly is not a member variable, that's the cause of your main problem.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a form with a datagrid, a textbox and 3 buttons.
BtnAdd - Adds a new event to the database
BtnSave - Saves to the database
BtnUpdate - Refreshes it and shows the updated version in the datagrid
My table only has an ID number and name - type Number and Text, but it wont write to the database for me, can someone show me way to do this please??
|
|
|
|
|
I'm trying to write some code that creates a picture box at a certain location when a user clicks a button. I am using this statement to initialize the picturebox:
Dim blip As Bitmap
blip = New Bitmap(filename of bitmap goes here)
Dim blipcase As New PictureBox
blipcase.Image = blip
and this statement to place the picturebox:
Dim Theta As Double = (Point.Y * PI) / 180
Dim location As New Point
location.X = (225 + ((Cos(Theta) * (30 * Point.X)) - 5))
location.Y = (225 + ((Sin(Theta) * (30 * Point.X)) - 5))
blipcase.Location = location
(Point is a system.drawing.point that contains the polar coordinates of the point)
Now, during a break in the program, I can see that location contains the right coordinates. However, I cannot get the picturebox to appear. So I do not think it is the location part that is wrong, but the initialization that is wrong. Can anyone else see something that I might be missing?
|
|
|
|
|
You didn't add the new PictureBox to your Form's Controls collection:
Dim blipcase As New PictureBox()
Me.Controls.Add(blipcase)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thank you, that worked great!
|
|
|
|
|
Dear Techies
i have an xml file
<bookstore>
<book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin
<author>
<first-name>Benjamin
<last-name>Franklin
<price>8.99
<book genre="novel" publicationdate="1967" isbn="0-201-63361-2">
<title>The Confidence Man
<author>
<first-name>Herman
<last-name>Melville
<price>11.99
<book genre="philosophy" publicationdate="1991" isbn="1-861001-57-6">
<title>The Gorgias
<author>
<first-name>Sidas
<last-name>Plato
<price>9.99
**************************
I have a form that has textboxes and buttons like move first,last next previus to navigate thru xml and show the contents of the xml
the problems: when ever iterate thru loop i'm getting a loop of
"book" and value= "all attributes values concatenated"
i wanna know the to iterate each and every node of of the above xml file
Thanks in advance
btn_first code as follows...
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
Dim xmldoc As XPathDocument = New XPathDocument("c:\books.xml")
Dim nav As XPathNavigator = xmldoc.CreateNavigator()
Dim itr As XPath.XPathNodeIterator = nav.Select("/bookstore")
Try
nav.MoveToRoot()
nav.MoveToFirstChild()
Do While nav.MoveToNext()
If nav.NodeType = XPathNodeType.Element Then
If nav.HasChildren = True Then
nav.MoveToFirstChild()
Do While nav.MoveToNext()
System.Diagnostics.Debug.WriteLine(nav.Name + " : " + nav.Value)
Loop
End If
End If
Loop
Catch ex As XPathException
MsgBox("The Error XPathException: " & ex.Message)
Catch ex As Xml.XmlException
MsgBox("The Error Xml : " & ex.Message)
End Try
End Sub
End Class
|
|
|
|
|
Hello All,
I'm trying to retreive the menu that Windows Explorer displays when you cascade menus. Here's a link to a screen shot of the menu I mean.
http://img72.imageshack.us/my.php?image=foldermenuor5.jpg
I'm fairly new to vb.net and programming in general. I'm trying to make a little launcher program just to test myself.
Thanks
Benedict
|
|
|
|
|
suppose i have 3 forms wid one button on form1 and two on form2...
wen m clickin button1 on form 1 m gettin form 2.
by coding
dim a as new form2
a.show()
same can be done on clicking button2 on form 2..
nw wen m at form 2 i wanna get back to form1 by clickin button 3 on form2...
hw can i do that....??
thanks.
-- modified at 4:12 Sunday 25th February, 2007
|
|
|
|
|
Actually you have given answer to your question. If you are going to click Button3 on Form 2 to get back to Form1, just hide form2 and show form1
a.hide()
Dim F1 as new Form1
F1.Show()
What a curious mind needs to discover or penetrate a knowledge is noting else than a pin-hole.
|
|
|
|
|
its not workin ...
please check it out..
i suppose u have suggested as:
in class form1
for Button1:
dim a as new form2
a.show
for button2
a.hide()
dim f1 as new form1
f1.show()
button3:
f1.hide() or a.hide()
dim f2 as new form 3
f2.show
|
|
|
|
|
That is how you have described the problem "nw wen m at form 2 i wanna get back to form1 by clickin button 3 on form2". However you are trying to open a new form (FORM3) not Form1 in your given example above.
Sorry but I am little bit confused...
button3:
a.hide() 'a is Form2
dim f1 as new form 1
f1.show()
What a curious mind needs to discover or penetrate a knowledge is noting else than a pin-hole.
|
|
|
|
|
yeah it looks like u rnot gettin mah problem....
m sendin u the full procedure..
if possible please send me the code.....i will be highly oblodged
start:
i have form 1 having button1
on clickin it i'll get form 2
now form 2 has two butons 1 and 2
button1(for back to the form 1)
button2(for proceeding to form 3)
now form 3 will again have 2 buttons
one for form2 and one for form 4....
END
thanks
|
|
|
|
|
I'd try to help, but I can't read this. I suggest English classes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Well I decided to test it and it is working fine... I have included codes for both FORM1 and FORM2 below
'Use this code form1
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
Dim F2 As New Form2
F2.Show()
End Sub
End Class
'Use this code for Form2
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
Dim F1 As New Form1
F1.Show()
End Sub
End Class
I hope that helps...
What a curious mind needs to discover or penetrate a knowledge is noting else than a pin-hole.
|
|
|
|
|
yeah its workin man....
u rock buddy..
thanks a lot..
can i have yr ID..?
|
|
|
|
|
That code only appears to work but has a nasty consequence. Your just hiding the origninal forms and then createing a new instance every time you go back. So you have form1 which creates and shows form2 while hiding itself. You click to go back on form2 which creates a NEW instance of form1 and hides itself. Now you have TWO form1's and 1 form2. However only 1 instance of form1 is actually visible, but there are definitly two and the number of instances will continue to increase every time you go back and forth. As proof put this code in form1.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim output As String = "Open forms: " & vbCrLf
For Each frm As Form In My.Application.OpenForms
output &= frm.Text & vbCrLf
Next
MsgBox(output)
End Sub
When form1 is shown the second time you'll see there are actually two in existence.
-- modified at 14:29 Sunday 25th February, 2007
|
|
|
|
|
You can load, unload or hide a form according to form's properties. If we were unloading the form, how we could easily reload it again? If forms were not a class actually, we wouldn't need to create a new object instance.
You are right about it but what do you suggest? The common language runtime (CLR) throws an OutOfMemoryException error if there is insufficient memory to create the new instance. You can control the exception. If user doesn't want to minimize/maximize the form, it becomes unfortunate to go that way.
Thanks for your code!
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
The first form needs to have a global variable to track the form it wants to call. If it already exists then we just show it instead. The only reason the following code is a problem is because in your case instead of closing form2 you hid it. Thus everytime you clicked the button a new form was created and the hidden forms stayed hidden.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As Form = New Form2
frm.Show()
me.hide
End Sub
It's probably better to close form2 if that's possible which avoid the problem altogether. In that case this code is just fine.
If the form creating form2 is the main form you can't close it so hiding it is your only option. If you can close form1 then again you could avoid the whole problem of many instances by doing so. That way when form2 makes a new instance we don't leave hidden form1's all over the place. If you do need to hide form1 then you could pass the current instance onto form2 so form2 knows which form called it and can show that form again. This sample demonstrates all of this. It's not complex and I'm sure there are other ways. I think the technique used would depend on the situation. But here is one option.
Public Class Form1
Dim frm As Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create a new instance of Form2 if we don't have one
'Notice I passed this instance in the constructor
If frm Is Nothing OrElse frm.IsDisposed Then frm = New Form2(Me)
frm.Show()
Me.Hide()
End Sub
End Class
Public Class Form2
Private m_Caller As Form 'The calling form
Public Sub New(ByVal caller As Form)
InitializeComponent()
m_Caller = caller
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
m_Caller.Show()
Me.Hide() 'You could also call me.close instead which may be more appropriate
End Sub
End Class
|
|
|
|
|
Thanks for your advice, your advice is very acceptable but what I think is that tracking the each form like that would make coding little bit annoying. May be you are right about it there should be some other ways (more practical).
Thanks again!
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Well forms are classes and you need to create an instance so you can show it or work with it. If another form needs to interact with that form then one way or another it needs to know which instance it's dealing with, because there could be many. If you had a form where only one instance should exist you could create a singleton form. Try looking that term up and you should find some examples. That's certainly another approach which may be appropriate for a given situation. There are also other scenarios. For instance if you didn't hide form1 you wouldn't need to show it again and form2 wouldn't have to know about it. But if that's the way you want it to work then form2 will need to know which instance it should show. Truth be told though it is still possible to use forms the old VB6 way. I'm sure many people would frown upon that and I am not going to encourage it but it's an option. For example create a new project and add a a second form with the default name form2. Replace the code in both forms with the following.
Code for Form1
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
Me.Hide()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Set the text to the time of creation so we can tell this
'we are dealing with the same instance
Me.Text = Now.ToLongTimeString
End Sub
End Class Code for Form2
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Set the text to the time of creation so we can tell this
'we are dealing with the same instance
Me.Text = Now.ToLongTimeString
End Sub
End Class
|
|
|
|
|
This cannot be applied for forms because a form instance can be triggered from different procedures at same time. Therefore, sticking with creation time is not appropriate. Think about two timer components. Each timer shows the same form in every second because the each timer works independently.
The most practical way should be the set the caller form as parent form and then in 2nd form redirect user to parent form.
I wish .net would have a single statement to solve this problem instead of bunch of coding.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
B Journey wrote: The most practical way should be the set the caller form as parent form and then in 2nd form redirect user to parent form.
That's exactly what I did in the first example. Form2 excepts a caller, 'the parent', so it knows who to talk to. The thing that seems to bother you is the 4 lines of code it takes to do that. Sorry, I just don't consider that a "bunch of coding". It's a pretty simple straighforward solution. Not to mention the fact that you could actually create your own extended form class with this code in it. Then whenver you need a form like this you would inherit from this class. You would have no need to write that code ever again
Also there is another way. There always seems to be another way, huh. The show method is overloaded and excepts an 'owner' form. You could pass your forms instance when you call the show method. Every form has an 'Owner' property. You could then access the caller through this property from form2. One thing to note about an owned form is that it will minimize whenever the owner minimizes and restore whenver it's restored. This may be desired, and in your case it doesn't even matter because the owner would be hidden and couldn't be minimized. So for example
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.Show(Me)
End Sub
Form2 could then use the code Me.Owner.Show to show it's parent.
B Journey wrote: This cannot be applied for forms because a form instance can be triggered from different procedures at same time. Therefore, sticking with creation time is not appropriate. Think about two timer components. Each timer shows the same form in every second because the each timer works independently.
I'm not sure why you think this (the code I posted last time) can't be applied to forms. It most definitly can, and does work just fine. The reason I showed the creation time was to clearly demonstate the same instance of the form was being shown whenver you called Form1.show or Form2.show. The point of the code was to demonstrate that in vb.net there is already a built in way to show a form without having to worry about creating a new instance or tracking the old instance. Form2.Show will create a new instance for you if one doesn't already exist, and if it does that same instance will be shown (sound familiar). It should because that's exactly what I did in the original post I made. Now if you meant it wasn't appropriate because you thought each timer needed to show a different instance of the other form then yes of course that code woulnd't be appropriate. As I've stated from the begining different situation call for different solutions.
-- modified at 15:44 Tuesday 27th February, 2007
|
|
|
|
|
what is 192 bit encryption and how we encorporate in our programming
namita
|
|
|
|