|
On top of what everyone else said, you have to be careful creating and disposing the System.Windows.Forms.Timer. Most people do not realize you have to call Dispose on them when you destroy them. Since Timers are not unlimited, you will eventually run the system dry on resources if you constantly create and destory Timers in your app.
|
|
|
|
|
Thank you everyone I really appreciate it.
I took some time out and realised I only need one timer event.
There is still one thing I am struggling with to understand but I put it in a new thread as its a different question.
|
|
|
|
|
Im not quite sure I understand why it is you needed alot of timers, as im sure there would be a better way to do it.
I would have thought that you could just use Threads.
Dim t As New Threading.Thread(AddressOf myThread)
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
t.Start()
End Sub
Private Sub myThread()
Do
'Work to be done
'....
' Waits 5 seconds before next iteration
Threading.Thread.Sleep(New TimeSpan(0, 0, 5))
'Or for miliseconds use this: Threading.Thread.Sleep(500)
Loop
End Sub
The myThread method will continue running until either you run a t.stop() from somewhere else in your code or you call an "Exit Loop" from within the Do Loop.
Please Note:
If you are updating controls on a form from a threaded function you will need to use a Delegate, I can send you an example if you cannot find one.
Also if you have a number of threads accessing the same resources you might need to use a Mutex to limit access violations.
Hope this helps.
|
|
|
|
|
Also might I add, from experience you might want to monitor how much memory your application uses after 1 hour of your software running then 2.... Just in case there are any memory leaks.
Hope this helps
|
|
|
|
|
Hi All,
I'm using ListView to show several columns of data. (View = Details)
Everything worked fine until I wanted to let the user to hide/show certain column(s).
I hide the column this way:
ListView1.Columns.Remove()
Problem is to get the column correctly visible again, so that columnheaders are correctly ordered into subitem-columns.
When I use ListView1.Columns.Insert() or ListView1.Columns.Add() to get the column visible again it links the columnheader to wrong subitem-column.
Is there any way to link a columnheader into subitem-column?
|
|
|
|
|
When you use remove, you are not hiding it, you are deleting it from the collection.
When you use insert, you can specifying the position you want to add the column, have you tried that?
Why not set the column width to 0 instead to hide it? that way it will remain in the same place.
|
|
|
|
|
Further to my original response, i just did a quick test and can confirm that if you insert a column at the appropriate index, the subitems remain correctly with the columns;
e.g. lv.removeat(2), lv.insert(2, "Col 3")
As a quick demo, create a form, add a listview in details view, add three pushbuttons, drop in the following code and run the app;
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Add some columns
ListView1.Columns.Add("Col 1")
ListView1.Columns.Add("Col 2")
ListView1.Columns.Add("Col 3")
ListView1.Columns.Add("Col 4")
'Add some test data
Dim x As New ListViewItem
x.Text = "1"
x.SubItems.Add("2")
x.SubItems.Add("3")
x.SubItems.Add("4")
ListView1.Items.Add(x)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListView1.Columns.RemoveAt(2)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListView1.Columns.Insert(2, "col 3")
End Sub
And you will see the test data remains in the 1,2,3,4 sequence before and after the remove and insert operations.
|
|
|
|
|
Thanks for Your answer.
To hide a column via setting column width is not an option, because the user is and must be able to resize the column width.
In Your example, if You first remove 2, 3 and 4 columns. And then insert only 4. column back, it causes an error.
Problem is, that there are more subitems than there are columns. And in that case the columnheader can't necessarily be inserted over correct subitem.
|
|
|
|
|
There does not appear to be anywayto map the subitems to columns.
However this IS doable using the width. refere back to the orginal form example i gave earlier and add the code below;
You will see, when you remove a column its width is set to 0 and added to a list of locked columns, then when the user tries to resize the locked column the columnresizing event checks if the column is in the locked collection, cancel the event and sets the width to 0.
Public Class Form1
Dim listLocked As New List(Of Integer) 'Locked columns
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Add some columns
ListView1.Columns.Add("Col 1")
ListView1.Columns.Add("Col 2")
ListView1.Columns.Add("Col 3")
ListView1.Columns.Add("Col 4")
'Add some test data
Dim x As New ListViewItem
x.Text = "1"
x.SubItems.Add("2")
x.SubItems.Add("3")
x.SubItems.Add("4")
ListView1.Items.Add(x)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim colIndex As Integer = 2
ListView1.Columns(colIndex).Width = 0
If Not listLocked.Contains(colIndex) Then listLocked.Add(colIndex)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim colIndex As Integer = 2
ListView1.Columns(colIndex).Width = 25
If listLocked.Contains(colIndex) Then listLocked.Remove(colIndex)
End Sub
Private Sub ListView1_ColumnWidthChanging(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnWidthChangingEventArgs) Handles ListView1.ColumnWidthChanging
'Check column is not hidden
If listLocked.Contains(e.ColumnIndex) Then
e.Cancel = True
e.NewWidth = 0
End If
End Sub
End Class
|
|
|
|
|
Yes, this seems to be the final solution.
Actually I had this kind of solution earlier for hiding columns.
But then something happened and ListView ColumnWidthChanging event stopped working. I mean that ColumnWidthChanging event does not fire att all.
And I have not found any solution for that.
Do You have any ideas how to get this ColumnWidthChanging-event problem fixed?
|
|
|
|
|
No idea what would stop the columnwidthchanging event, other than some code you added to your original solution getting in the way.
|
|
|
|
|
Maybe if you block some columns to resize.
This is my code to block them standard all with property to release some
Imports System.Runtime.InteropServices
Namespace Controls
Public Class ListView_FixColumns
Inherits ListView
Private _KolommenVrij(1024) As Boolean
Public Const WM_NOTIFY As Integer = &H4E
Public Const HDN_FIRST As Integer = 0 - 300
Public Const HDN_BEGINTRACKA As Integer = HDN_FIRST - 6
Public Const HDN_BEGINTRACKW As Integer = HDN_FIRST - 26
<StructLayout(LayoutKind.Sequential)> Public Structure NMHDR
Public hwndFrom As IntPtr
Public idFrom As Integer
Public code As Integer
End Structure
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_NOTIFY Then
Dim hdr As NMHDR = CType(m.GetLParam(GetType(NMHDR)), NMHDR)
If hdr.code = HDN_BEGINTRACKA OrElse hdr.code = HDN_BEGINTRACKW OrElse hdr.code = HDN_DIVIDERDBLCLICKW Then
Dim nmHeader As NMHEADER = CType(m.GetLParam(GetType(NMHEADER)), NMHEADER)
If Not _FreeColumns(nmHeader.iItem) Then
m.Result = New IntPtr(1)
Exit Sub
End If
End If
End If
MyBase.WndProc(m)
End Sub
Public Property AllowColumnResize(ByVal Column As Integer) As Boolean
Get
Return _KolommenVrij(Column)
End Get
Set(ByVal value As Boolean)
_KolommenVrij(Column) = value
End Set
End Property
End Class
End Namespace
If you add a property to select witch columns may not be blocked it will do
|
|
|
|
|
Thanks in advance.
I am using SendKeys to Handle an application it works fine when i call SendKeys Functionality on Button click , means when user clicks , but when i calls it
on Form load it does not work and goes to wrong menu
Any SuggestionBest Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
What are you trying to sendkeys to? a different app? the same app? clarity required. what code are you using?
|
|
|
|
|
i am opening a Screen/Form of another application and it simple i m sending "%F" , "V"
mean ALT F then v to open a form , but it works only one i press/ click button on the form , i want to do it on Timer or on form load but same function
commands does not work on form load or timer but works fine on User Click
Best Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
I have seen similiar things in the past trying to do things in the load events of forms, but that is neither here nor there.
Are you sure the application you want to send the keys to is active? have you tried an AppActive("Caption") or Appactivate(PID) immediately before the send keys?
|
|
|
|
|
try postponing your SendKeys action by using the Shown event instead of the Load event.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
If u want to use with ur application then skip SendKeys and Use Tabindex.
if u want to do with another application then use Keyboard Hooking.
If you can think then I Can.
|
|
|
|
|
Hi all.
I am trying to access registry values of Windows 7 using vb.net (VS2005) but each time when I am trying to read or write some values, it gives some permission check kind of error messages. When I am trying to execute program in admin mode, it gives the same error message.
Suggest me what should I do.
Thanks.
Gagan
|
|
|
|
|
Without knowing what the error message is and what the code looks like that's generating the message, it's pretty much impossible to tell you what's wrong.
|
|
|
|
|
Hi,
Im getting an error "Automation error" when trying to use word from web server.
i have word 2000 and its a windows 2k3 server R2.
Thanks,
Bad Programmer
|
|
|
|
|
I would post a code snipet and the actual error message so that we might be able to help.
Can we assume that MS-Word is installed on the server which your program is running ?
|
|
|
|
|
Automating Word, or any Office app, from ASP.NET is a really bad idea. Read this[^] to find out why.
|
|
|
|
|
have u add all your reference of word 9.0...?
have u create objects...?
can u post your code...?
Rating always..... WELCOME
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
hi guyz...
-> i need some good articles or help regarding bluetooth programming in dotnet... i am also searching
the web but i am unable to find good one... plz help me out with this...
thanks...
take care...
J A Nasir K
|
|
|
|