|
Any Other Solutions Or Suggestions,To solve this problem.....
|
|
|
|
|
Why? Did you try what I said and it did not work?
|
|
|
|
|
S you are right,i have changed it from "ToInt64" to "ToDouble"
but,it is converting now upto 9 characters only...........
|
|
|
|
|
Please post the code you changed like you did in the first post.
|
|
|
|
|
Here Is The code:-
Dim s1,s2 As string
Dim i1,i2 As Integer
s1=textbox1.Text
i1=Convert.Todouble(s1)
s2=Convert.ToString(i1, 8)
i2=Convert.Todouble(s2)
but It is limited only up to 9 characters.....
|
|
|
|
|
This is exactly the same problem...
Double is 64 bit, integer is 32 bit. You need to declare i1 and i2 as double's if you want to use ToDouble.
|
|
|
|
|
So here I am again. Something that should be easy is not.
I created a usercontrol (button_fancy). It works and all, but in the designer after I add my usercontrol, If I dbl click it generates a load event, All other controls generate a click event by default.
Of course I can just single click it and go to the event properties and create a click event. But how do I get the designer to default the click event?
Bonus question,
In the control I have a propery "mytext" I wanted to be consistant and have a property "Text". However that does not work. What little trick does it take to override a unexposed property?
Highflier
|
|
|
|
|
It is easy. It just doesn't work the way you think it should.
Double-clicking anything in a UserControl should generate a Load event header in the host form code, not a Click. This is because the UserControl, reguardless of what you put in it, IS the single control exposed to the host you drop it on. A UserControl is a container for other controls that have a related purpose, acting as a single control and, as such, should NOT expose this constituent controls to the host.
UserControls do not generate the Click event by default because they are not expected to be clicked on as a single control, like a button.
having said all that, it's very easy to change. In the UserControls code, at the top of the class where you inherit from UserControl, you simply add the DefaultEvent attribute to the class declaration, like this:
<DefaultEvent("Click")>
Public Class MyControl
Inherits UserControl
|
|
|
|
|
Thanks. However I needed [DefaultEvent("Click")]
It only took me about 10 seconds to figure that out after your post.
My life will be a lot easier now
Highflier
|
|
|
|
|
The code I posted was for VB.NET. You're using C#, which replaces the angle brackets with square ones.
|
|
|
|
|
Hi everybody,
my application runs on WinCE 5 device, it communicates with a PLC via modbus/TCP and it integrates a web server (code found in the article "Create your own Web Server using C#").
I'm trying to manage the remote access (from web browser) with user authentication and session timeout.
Every user is an object of the following class:
Public Class CWebUser
Private mUserName As String = ""
Private mPassword As String = ""
Private mIP As String = ""
Private mStartSession As Long = 0
Private mLogged As Boolean = False
Private WithEvents mWUTimer As System.Windows.Forms.Timer
Sub New()
mWUTimer = New System.Windows.Forms.Timer()
mWUTimer.Enabled = False
mWUTimer.Interval = 10000
AddHandler (mWUTimer.Tick), AddressOf WUTimer_Tick
End Sub
Private Sub WUTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
If ((DateTime.Now.Ticks - mStartSession) > (CGlobali.WebSessionDuration * 10000000)) Then
mWUTimer.Enabled = False
mIP = ""
mLogged = False
End If
End Sub
Public Property UserName() As String
Get
Return mUserName
End Get
Set(ByVal value As String)
mUserName = value
End Set
End Property
Public Property Password() As String
Get
Return mPassword
End Get
Set(ByVal value As String)
mPassword = value
End Set
End Property
Public Property IP() As String
Get
Return mIP
End Get
Set(ByVal value As String)
mIP = value
End Set
End Property
Public Property StartSession() As Long
Get
Return mStartSession
End Get
Set(ByVal value As Long)
mStartSession = value
End Set
End Property
Public Property Logged() As Boolean
Get
Return mLogged
End Get
Set(ByVal value As Boolean)
mLogged = value
End Set
End Property
Public Property WUTimer() As System.Windows.Forms.Timer
Get
Return mWUTimer
End Get
Set(ByVal value As System.Windows.Forms.Timer)
mWUTimer = value
End Set
End Property
End Class
When the application starts, it creates a list of authorized users.
When someone logs in, if UserName and Password are OK, I call the following sub:
Private Sub SetWUser(ByVal Name As String, ByVal IP As String)
Dim i As Int32
For i = 0 To (CGlobali.Users.Count - 1)
If (Name = CType(CGlobali.Users.Item(i), CWebUser).UserName) Then
CType(CGlobali.Users.Item(i), CWebUser).IP = IP
CType(CGlobali.Users.Item(i), CWebUser).Logged = True
CType(CGlobali.Users.Item(i), CWebUser).StartSession = DateTime.Now.Ticks
CType(CGlobali.Users.Item(i), CWebUser).WUTimer.Enabled = True
Exit Sub
End If
Next
End Sub
This sub should start the timer WUTimer of the specified user, and indeed the property WUTimer.Enabled is set to True, but the sub WUTimer_Tick is never executed as if it is not connected to the Tick event of the timer.
Can some one help me?
Thanks in advance.
I think I made some dumb mistake but I can not find it.
|
|
|
|
|
I'm pretty sure you have to Start the timer. If I were you, I would refactor the class so that you had a method like this in it:
Public Sub Start(ByVal IPAddress As String, ByVal IsLogged As Boolean)
IP = IPAddress
Logged = IsLogged
StartSession = DateTime.Now.Ticks
mUTimer.Enabled = True
muTimer.Start
End Sub Then you replace a lot of your code with a simple
CType(CGlobali.Users.Item(i), CWebUser).Start(IP, True)
|
|
|
|
|
Thanks Pete,
but unfortunately my application runs on Windows CE, so it uses the Compact Framework, not the full .NET and in Compact Framework there is not the method Start for the timer.
|
|
|
|
|
Ah. In that case, I would probably look at using System.Threading.Timer instead. Documentation[^]
|
|
|
|
|
Ok, I take a look at this timer.
Thanks
|
|
|
|
|
Sorry but I don't know how to use this kind of timer in the way I need (property of an object).
Any other suggestions about how to make a System.Windows.Forms.Timer work as I need?
Thanks
|
|
|
|
|
Put a breakpoint in your timer tick event and see if it's being hit when you run it in debug. Does it hit the method or not? My suspicion is that it is hitting the method, but there's a bug in the if statement.
|
|
|
|
|
I put a breakpoint on line
If ((DateTime.Now.Ticks - mStartSession) > (CGlobali.WebSessionDuration * 10000000)) Then
but the debug never stop there
|
|
|
|
|
And if you set the breakpoint in SetWUser? Is it actually executing this line?
CType(CGlobali.Users.Item(i), CWebUser).WUTimer.Enabled = True
|
|
|
|
|
yes, the line is executed and the property WUTimer.Enabled is really set to true, to check it I wrote just after that line something like this:
Dim aaa As Boolean
aaa = CType(CGlobali.Users.Item(i), CWebUser).WUTimer.Enabled
and aaa become true.
It seems like the instruction
AddHandler (mWUTimer.Tick), AddressOf WUTimer_Tick
does not link the sub WUTimer_Tick to the event mWUTimer.Tick
|
|
|
|
|
Try changing your class so that it looks like this:
Public Class CWebUser
Private mUserName As String = ""
Private mPassword As String = ""
Private mIP As String = ""
Private mStartSession As Long = 0
Private mLogged As Boolean = False
Private WithEvents mWUTimer As System.Windows.Forms.Timer
Sub New()
End Sub
Private Sub WUTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
If ((DateTime.Now.Ticks - mStartSession) > (CGlobali.WebSessionDuration * 10000000)) Then
mWUTimer.Enabled = False
mIP = ""
mLogged = False
End If
End Sub
Public Property UserName() As String
Get
Return mUserName
End Get
Set(ByVal value As String)
mUserName = value
End Set
End Property
Public Property Password() As String
Get
Return mPassword
End Get
Set(ByVal value As String)
mPassword = value
End Set
End Property
Public Property IP() As String
Get
Return mIP
End Get
Set(ByVal value As String)
mIP = value
End Set
End Property
Public Property StartSession() As Long
Get
Return mStartSession
End Get
Set(ByVal value As Long)
mStartSession = value
End Set
End Property
Public Property Logged() As Boolean
Get
Return mLogged
End Get
Set(ByVal value As Boolean)
mLogged = value
End Set
End Property
Public Property WUTimer() As System.Windows.Forms.Timer
Get
Return mWUTimer
End Get
Set(ByVal value As System.Windows.Forms.Timer)
mWUTimer = value
End Set
End Property
Public Sub EnableTimer(Byval IpAddress As String, ByVal Name As String)
IP = IpAddress
UserName = Name
mWUTimer = New System.Windows.Forms.Timer()
mWUTimer.Interval = 10000
AddHandler (mWUTimer.Tick), AddressOf WUTimer_Tick
mWUTimer.Enabled = True
End Sub
End Class Then call EnableTimer from your loop.
|
|
|
|
|
Thanks for your effort.
I did what you suggest but the result is the same: the tick event is not fired.
I fear it can be a problem related to thread.
The web server is a class with a thread that start the listener to receive connections from remote.
In the main thread of the application I instantiate an object WebServer and in this way I start its thread (the thread is created and started in the sub New() of the class).
The list of users (objects of the class CWebUser) is created in the main thread of the application.
The sub SetWUser(...) that enable the WUTimer is part of the class of the web server and is called by the function VerifyLogInData(...) called in the loop of the thread of the web server...
Is it possible that the problem is that I try to use from thread X a method of an object created in thread Y?
|
|
|
|
|
Yes it is...
I have solved the problem enabling the timer from a sub in the main thread and colling this sub with the Invoke function from the web server thread.
Bye!
|
|
|
|
|
steve_9496613 wrote: mWUTimer = New System.Windows.Forms.Timer() According to the documentation[^], that class isn't supported.
The Threading-timer[^] seems to be supported.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy, thanks for the replay.
Your link to the documentation about the System.Windows.Forms.Timer refers to .Net Framework 4.5 but, for this time, I'm luky and in Compact Framework 3.5 (and also .NET Framework 3.5) this timer is supported.
The System.Threading.Timer is supported, as Pete O'Hanlon suggested, but I have some problem to put one of this timer in my class as a property (I mean like I did with the Form.Timer).
|
|
|
|