|
word is installed in my system and i want to open a word documet in half of my screen can any one help me
mail me at rajesh.batchu@cesltd.com
|
|
|
|
|
I told you what you need to do. If you want to control Word, you need to do it via COM or there's a .NET library you can use. I'd be surprised if there were no CP articles that show how.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi All.. I am having a few issues on creating a new form by raising an event from the child thread. I have created a small scenario demonstrating this, please could anyone give some sugestions.
' Main Form loaded
Dim f As New Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
start.start()
End Sub
Dim WithEvents start As New Class1
Private Sub newf()
'Dim f As New Form2
f.Show()
f.Visible = True
End Sub
Private Sub start_cge() Handles start.cge
newf()
End Sub
End Class
' Class containg the thread create and event
Imports System.Threading
Public Class Class1
Public Event cge()
Public WithEvents tr1 As New System.Windows.Forms.Timer
Dim t As Thread
Public Sub start()
tr1.Interval = 2000
tr1.Start()
End Sub
Public Sub ttick(ByVal s As Object, ByVal e As System.EventArgs) Handles tr1.Tick
t = New Thread(AddressOf ev)
t.Start()
End Sub
Public Sub ev()
RaiseEvent cge()
End Sub
End Class
Any help would be greatly appreciated
|
|
|
|
|
What's the problem exactly ?
You can't create UI elements on different threads, if they are going to interact. All operations for a UI element need to happen in the thread that created it. This is an artificial limitation, new to .NET 2.0, and you can turn it off if you want to, but you'd do better to live within it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi Christian, thanks for the response.
Sorry should have mentioned the problem. The problem is form2 displays then vanishes, or the controls do not update in the main form when and event is raised from the child thread. The code snippet is a small project to see if I can get around this instead of breaking my proper program it will be inserted into. Instead of a timer in the example I have a tcpclient with the socket reader stuck in a while loop eg
temptcpclnt = New TcpClient
temptcpclnt.Connect(details.ServerName, details.Port)
stmIn = temptcpclnt.GetStream()
tcpThd = New Thread(AddressOf ReadSocket)
tcpThd.Start()
The readsocket raises an event to the mainform to create a new form or update a grid when it has recieved all data
hope this explains a little more
|
|
|
|
|
Sounds likely that the mainform routine is creating a local variable for a form, and calling show, which would then cause it to go out of scope and get garbage collected. Can you post the routine so I can see if this is the case ? If it is, you need to keep a reference to the object, probably in a collection if the number of objects is likely to change at runtime.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
This code runs in my class which is running the thread
Public Sub LoginUser(ByVal Str As String)
If Mid(Str, 1, 2) = "UD" Then
Dim Userdets() As String
Str = TruncData(Str)
Userdets = Microsoft.VisualBasic.Split(Str, ",", -1, CompareMethod.Binary)
CnDetails.UserName = Userdets(3)
CnDetails.Curr_Id = Userdets(0)
CnDetails.Department = Userdets(1)
CnDetails.level = Userdets(2)
'Tell LoginForm That all is ok and continue
RaiseEvent LoggedIn(True)
End If
This is the code that the event raises in the form that created the class object
Dim WithEvents Login As New SocketControls.SocketControl
Private Sub Login_LoggedIn(ByVal Ok As Boolean) Handles Login.LoggedIn
If Ok = True Then
Hideloggin()
End If
End Sub
Private Sub Hideloggin()
'232, 168
Dim NewForm As Form
Try
'Application.DoEvents()
NewForm = New Form2
NewForm.Show()
Me.Refresh()
'Me.WindowState = FormWindowState.Maximized
'Me.FormBorderStyle = FormBorderStyle.Fixed3D
'Me.MinimizeBox = True
'GroupBox1.Visible = False
'GroupBox2.Visible = False
'lblErr.Visible = False
Catch ex As Exception
End Try
End Sub
I was reading some of the blogs on this and a few people said that the child thread even though raising an event the event will still run on the child thread, so the child thread needs to pass the request through to the parent thread to execute that bit of code so it runs there. I am not to sure on how to do this though
|
|
|
|
|
ryan@theglenns.co.za wrote: Dim NewForm As Form
Try
'Application.DoEvents()
NewForm = New Form2
NewForm.Show()
OK - there it is. As it's a member variable, and you don't put a reference to it anywhere, as soon as this method ends, NewForm is available for garbage collection, and so it disappears ( it didn't live long, so it's up for first cycle collection ). Create a list of Form objects, and push NewForm onto the list. OR make it a member variable if there's only going to be one. Then it will not be collected, and it will live on after the method ends.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
ok, sounds good, hate to ask this, could you please give me a small example. There will only be one new form created from the event once the user is logged in, this form will display the data for the user. I owe u one if it works
|
|
|
|
|
Sure:
Dim NewForm As Form
Private Sub Hideloggin()
if not NewForm is Nothing NewForm.Dispose() ' Delete it if it's already been created before
Try
'Application.DoEvents()
NewForm = New Form2
NewForm.Show()
Me.Refresh()
'Me.WindowState = FormWindowState.Maximized
'Me.FormBorderStyle = FormBorderStyle.Fixed3D
'Me.MinimizeBox = True
'GroupBox1.Visible = False
'GroupBox2.Visible = False
'lblErr.Visible = False
Catch ex As Exception
End Try
End Sub
Basically, NEwForm becomes a member, and I add some code to clean up memory if it's called more than once. You may want to play with that part of it, but broadly, it should work like that, even without the 'if not newform...' line.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Nope didn't help, I think it may be because the event raised within the child thread to call the event handler on the main form tells the code to run in it's own thread and not the parent. Is there any way to tell the child thread to execute the code on the main thread?
|
|
|
|
|
No, I don't know of any issues here, or ways to deal with them, sorry.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
ok no problem, I will check some more blogs out and hopefully find something, thank you for your help
|
|
|
|
|
It may be the threading because even if I try to change the layout of form1(main form) from the event it hangs the program ie
Me.WindowState = FormWindowState.Maximized
|
|
|
|
|
Hi Christian
I managed to get it write and thought you may be interested, it's pretty funny it only takes two lines of code. It was the issue of the child thread. The way to get round the problem is :
Imports System.Threading
Public Class Test
Public t As Thread
Public Sub Start()
t = New Thread(AddressOf tstartdes)
t.Start()
End Sub
Public caller As New MethodInvoker(AddressOf newform)
Public Sub tstartdes()
Form1.ActiveForm.Invoke(caller)
End Sub
Dim F As Form
Public Sub newform()
F = New Form2
F.Show()
End Sub
End Class
The method invoker is what does it, it is then invoked from the main thread running the main form.
Yay ... It's working
|
|
|
|
|
This is how your supposed to do it. Although it's possible to create forms on other threads, I don't recommend it because people, who mostly don't understand threading, always run into weird problems like this and can't seem to comprehend why it doesn't work. They spend dyas screwing around with a problem that's easily avoidable if you remember to keep all of your GUI elements (including entire forms) on the GUI thread and shovel off the real work to background threads.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
I have a datagrid displayed on a page with a few data column, one of the column is 'name'. can i create a hyperlink on the name field (to create link to other pages)? btw, i'm using vb.net. & mssql server (db) ,& still a beginner.
Thanx in advance.
|
|
|
|
|
Hi,
What I need to do is simple in concept but could be difficult to do, if at all. I need to know if it can be done.
I've got an application (Notification Icon) from which I launch different applications, and if they are already launched, simple set focus to them. This is simple enough when I create an instance of each application, on request, from my main application, and call a show/setfocus command if they already exists.
But what I would like to achieve is for these instances to continue running, even when my main application is shut down or crashes.
The shell command is an option, but I need something that provides more control.
Any Ideas?
|
|
|
|
|
If you just need to launch another application and forget about it, Shell could work fine for you.
If you need more control, you can look MSDN about System.Diagnostics.Process or System.Diagnostics.ProcessStartInfo
Marco Turrini
|
|
|
|
|
System.Diagnostics looks like it should do. I'll give it a try.
Thanks
Robert
|
|
|
|
|
You say that ‘you need to generate a new GUID so you have a new version’ how to generate a new GUID. I see on Project Property Window a ‘DLL Base Address’ is it useful for me please help me.
Sasmi
|
|
|
|
|
Please don't make a new post when you're discussing the same problem, respond to my post instead.
Do you know what a GUID is ? It's the unique ID that represents your COM object. The base address has nothing to do with it. I have to admit, I have no idea how it's set in VB6, I've only done it in C++. From memory, there's a text file which contains the GUID. Do NOT make up a GUID, use the tool to generate one for you. Make sure you also give it a new name, because in VB you generally use the name, not the GUID.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for giving direction.
Sasmi
|
|
|
|
|
Hi Guys,
I Have a dll name 'XYZ.dll' which i use in my project call 'ABC' and install it on users pc and i use same dll 'XYZ.dll' (with some major changes) in my another project call 'PQR' if i install this pqr on users PC i found it overwrite the first one dll which is use in 'ABC' project. can any one help me regarding this i am first time using this dll funda in vb6. if any one give me detail idea about 'How to use dll' it will really great for me.
Thanks in advanced
Sasmi
|
|
|
|
|
I assume this is a COM dll, otherwise you could just put the dlls in the directories with the apps and it would be fine.
You've done the wrong thing, and there's no easy way around it. If you're going to change a COM dll, you need to generate a new GUID so you have a new version. Either way, you should never break existing functionality, only add new functionality.
In .NET, dlls are not registered, and are just loaded from the local directory. This change was made because the recommended way to use COM would work fine, but too many people just didn't bother to do it properly/thoughtfully.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|