|
Hi,everyone.New in this forum to stay
situation
I have a form with three(3) panes and an array of usercontrols(various labels on it)
question
I need to click on label1 of the control(controls because of the array) with diferent answers deppending on which pane the control is
ej.
mysusercontrol(0) is over panel1. If I click on label1 I want the backcolor to be blue.If a move the mysusercontrol(0) to panel2 then if I click on label1 with the left button I want to change the label1.text and if myusercontrol(0) is on pane3 I want the control to be destroyed.
I can do it for myusercontrol(0) but I want to do it for all the controls of the array(mysuercontrol(1) etc,)
kind regards
|
|
|
|
|
Is you myUserControl() a child of these panels or is it just sitting on top of them as a child of the Form?
If it's a child of the panel, then you should be able to get it's parent or container property to determine which panel currently owns your control. If it's not a child of the panel, then your going to have to use the position coordinates of your myUserControl and compare them to the coordinates and size of the panel controls to determine which one the control is sitting on top of.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
'this code go in the form_load
Dim mycontrolarray As arraycontrol
mycontrolarray = New arraycontrol(Me)
For i = 0 To j - 1
mycontrolarray.AddNewUsercontrol()
mycontrolarray(i).getdata = arrText(i)
mycontrolarray(i).Parent = Panel5
mycontrolarray(i).Top = Panel5.Height - 35 * (i + 1)
Next
mlabel01 = mycontrolarray(0).Label1
mlabel010 = mycontrolarray(0).Label10
mlabel11 = mycontrolarray(1).Label1
mlabel110 = mycontrolarray(1).Label10
Private Sub mlabel01_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mlabel01.MouseDown
Select Case e.Button
Case MouseButtons.Left
If Panel3.Contains(mycontrolarray(0)) Then
mycontrolarray(0).Label1.BackColor = Color.Yellow
mycontrolarray(0).Label1.ForeColor = Color.Black
End If
End Select
End Sub
As you can see I can manage the situation for a single control in this case mycontrolarray(0) but I need to manage all of them with a single sub as they all the same.
|
|
|
|
|
marisolera wrote:
mycontrolarray.AddNewUsercontrol()
mycontrolarray(i).getdata = arrText(i)
mycontrolarray(i).Parent = Panel5
mycontrolarray(i).Top = Panel5.Height - 35 * (i + 1)
Next
This is illegal. There are no such things as control arrays in VB.NET like there were in VB6.
Besides, you doing two very different things here:
First, you define mycontrolarray as a single instance of type arraycontrol :
Dim mycontrolarray As arraycontrol
mycontrolarray = New arraycontrol(Me)
I have no idea what your doing with the Me reference because it's handled by the constructor code inside your arraycontrol code.
Then, later you refer to mycontrolarray as an indexed array:
mycontrolarray(i).getdata = arrText(i)
mycontrolarray(i).Parent = Panel5
mycontrolarray(i).Top = Panel5.Height - 35 * (i + 1)
This is illegal since your now trying to treat the mycontrolarray as an array and it wasn't defined as such.
Secondly, you have an event handler for a label that doesn't exist on the form. mlabel01 appears to be a member of arraycontrol . The event must be handled inside the control and not on the form.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
On the one hand you see , and by the other, what can I tell you.
And nevertheless it moves....
See Control arrays in Visual Basic .Net in Microsoft Knowledge base.
|
|
|
|
|
dave,I sent you the code as marisolera because this is my name for the work
|
|
|
|
|
I am tring to use the copymemory API and it works fine in vb 6.0 but when i try to use this in .net. It throws an error and says that the object is not set to an instance. The API is declared in a public module and you do not have to instance a module. Well i never have and i have also tried putting the call in the class im working in. Still nothing. I have tried many variations in the coding of the call to satisfy its needs but always throws the error. This is the code that i am using in .NET
<br />
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination As Int32, ByRef Source As Object, ByVal Length As Int32)
This is the code that works in 6.0
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any,ByVal Length As Long)
And also is the a equivalent of the any data type in 6.0 Object in a manner of speaking.
|
|
|
|
|
Yout want to post the code that is throwing the exception, including the above declare. What your doing will not directly translate to VB.NET simply because your trying to marshal managed objects to unmanaged code.
We need the code, including what your trying to copy, and what your trying to accomplish in order to help you. There may be alternative ways to do this...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This is a blowfish cryptography program that i am converting from 6.0 to .NET.
This project has to 2 Textboxs "Textbox1, Textbox2" 2 buttons "btnEncrypt, btnDecrypt" and 1 active X control named VbCryptoEngine1
This program begins when you click the encrypt button
Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click<br />
<br />
VbCryptoEngine1.CryptAlgorithm = CryptoEngine.vbCryptoEngine.enuCRYPTO_ALGORITHMS.acuBlowfish<br />
TextBox2.Text = VbCryptoEngine1.EncryptString(TextBox1.Text, VbCryptoEngine1.key, True)<br />
End Sub
The VbCryptoEngine1.CryptAlgorithm line works fine it sets a new instance of the class blowfish where all the code for blowfish is contained.
the function EncryptString looks like this
Public Function EncryptString(ByVal Text As String, Optional ByVal Key As String = "Cool", _<br />
Optional ByVal OutputInHex As Boolean = False) As String<br />
<br />
On Error GoTo errhandler<br />
If m_status = STAT_BUSY Or m_status = STAT_ERROR Then Exit Function<br />
EncryptString = <font color = "blue">m_Engine</font>.EncryptString(Text, Key, OutputInHex)<br />
m_status = STAT_READY<br />
RaiseEvent statuschanged(m_status)<br />
Exit Function<br />
errhandler:<br />
<br />
' ---------------------------------------------------------------------------<br />
' Raise friendly error to the handler<br />
' ---------------------------------------------------------------------------<br />
Call Err.Raise(Err.Number, "CryptoEngine:EncryptString", Err.Description)<br />
<br />
End Function
I was going to us the try catch statement but i will update code later.
the line with the blue sends the string info and a few other variables to the instances blowfish class
The Function looks like this
Public Function EncryptString(ByVal Text As String, Optional ByVal Key As String = "Cool", Optional ByVal OutputInHex As Boolean = False) As String Implements IAlgorithm.EncryptString<br />
Dim ByteArray() As Byte<br />
<br />
Dim [unicode] As Encoding = Encoding.Unicode<br />
Dim ascii As Encoding = Encoding.ASCII<br />
Dim unicodebytes As Byte()<br />
Dim asciibytes As Byte()<br />
m_status = STAT_BUSY<br />
RaiseEvent statuschanged(m_status)<br />
<br />
On Error GoTo errhandler<br />
<font color = "blue">unicodebytes = [unicode].GetBytes(Text)</font><br />
Encoding.Convert([unicode], Encoding.Default, unicodebytes)<br />
ByteArray = unicodebytes<br />
<font color = "Red">Call EncryptByte(ByteArray, Key)</font><br />
unicodebytes = Encoding.Default.GetBytes(CStr(CObj(ByteArray)))<br />
Encoding.Convert(Encoding.Default, [unicode], unicodebytes)<br />
<font color = "blue">EncryptString = CStr(CObj(unicodebytes))</font><br />
If OutputInHex = True Then EncryptString = EnHex(EncryptString)<br />
m_status = STAT_READY<br />
RaiseEvent statuschanged(m_status)<br />
Exit Function<br />
errhandler:<br />
m_status = STAT_ERROR<br />
RaiseEvent statuschanged(m_status)<br />
' ---------------------------------------------------------------------------<br />
' Raise friendly error to the handler<br />
' ---------------------------------------------------------------------------<br />
Call Err.Raise(Err.Number, Err.Source, Err.Description)<br />
End Function
Im not cofindent that my conversions are working in the manner that they should but they are not throwing the exception. I need the conversions to do the same thing that the StrConv did to convert from unicode and also to unicode. The lines between the blue are the ones with the converstion. The line in red is what is throwing the exception
The function EncryptByte looks like this
Public Function EncryptByte(ByVal ByteArray() As Byte, Optional ByVal Key As String = "Cool") As String<br />
<br />
<br />
Dim Offset As Long, OrigLen As Long, LeftWord As Long, RightWord As Long, CipherLen As Long, CipherLeft As Long, CipherRight As Long, CurrPercent As Long, NextPercent As Long<br />
<br />
If (Len(Key) > 0) Then Key = Keys<br />
OrigLen = UBound(ByteArray) + 1<br />
CipherLen = OrigLen + 12<br />
If (CipherLen Mod 8 <> 0) Then CipherLen = CipherLen + 8 - (CipherLen Mod 8)<br />
ReDim Preserve ByteArray(CByte(CipherLen - 1))<br />
<br />
<font color = "Red">call CopyMemory(CInt(ByteArray(12)), CInt(ByteArray(0)), CInt(OrigLen))</font><br />
Call CopyMemory(CInt(ByteArray(8)), CInt(OrigLen), 4)<br />
Call Randomize()<br />
Call CopyMemory(ByteArray(0), CInt(2147483647 * Rnd()), 4)<br />
Call CopyMemory(ByteArray(4), CInt(2147483647 * Rnd()), 4)<br />
<br />
For Offset = 0 To (CipherLen - 1) Step 8<br />
Call GetWord(CInt(LeftWord), ByteArray, Offset)<br />
Call GetWord(CInt(RightWord), ByteArray, Offset + 4)<br />
LeftWord = LeftWord Xor CipherLeft<br />
RightWord = RightWord Xor CipherRight<br />
Call EncryptBlock(LeftWord, RightWord)<br />
Call PutWord(LeftWord, ByteArray, Offset)<br />
Call PutWord(RightWord, ByteArray, Offset + 4)<br />
CipherLeft = LeftWord<br />
CipherRight = RightWord<br />
If (Offset >= NextPercent) Then<br />
CurrPercent = CInt((Offset / CipherLen) * 100)<br />
NextPercent = CInt((CipherLen * ((CurrPercent + 1) / 100)) + 1)<br />
RaiseEvent Process(CurrPercent)<br />
End If<br />
Application.DoEvents()<br />
Next<br />
<br />
If (CurrPercent <> 100) Then RaiseEvent Process(100)<br />
Exit Function<br />
errhandler:<br />
<br />
' ---------------------------------------------------------------------------<br />
' Raise friendly error to the handler<br />
' ---------------------------------------------------------------------------<br />
Call Err.Raise(Err.Number, Err.Source, Err.Description)<br />
End Function
The line in red is when it throws the exception back to the function EncryptString{^} and says that Object reference not set to an instance of an object. The API call is in a public module class along with many public varibles that you do dont see declared. Any help with be appreciated. Just tell me if anyone needs anything else.
|
|
|
|
|
First, why are you even using CopyMemory? From what I see here you don't need it.
OK. You've got two problems. Your code:
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination As Int32, ByRef Source As Object, ByVal Length As Int32)
.
.
.
call CopyMemory(CInt(ByteArray(12)), CInt(ByteArray(0)), CInt(OrigLen))
.
.
.
What your doing here is nasty to say the least. CopyMemory takes 3 parameters, a Destination address, a Source address, and a Length to copy, in bytes. What you've done is tell VB to marshal the Destination address as an Int32 and the Source as a reference to an Object. What your doing is converting ByteArray(12) and ByteArray(0) to Integers, then by the definition you setup in the Declare statement, you're passing the VALUE of ByteArray(12) to CopyMemory, NOT the address! Next, your passing a reference (or address) as the second argument, but your passing an Object reference to another byte converted to an Integer. CopyMemory expects an address for the first and second arguments, you got one right.
You might want to take a look at this[^] article before trying to use CopyMemory.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What suggestions do you have for the replacements for my current code.
|
|
|
|
|
I want to open large tiff images (ex 29350 x 7172) just for viewing
not editing. I tried Image.FromFile but it works very slow.
Also I don't want to use a viewer activex. Please help
|
|
|
|
|
Of course it works slow, your image is a monster! Even at an 8-bit color depth it's 210MB. What kind of performance did you want?!
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There is no good site for this. What you want to do is going to be tedious to code and there is no easy way around this. You will have to compare each property seperately like Font.Name, Font.Size, Font.Bold, Font.Color, Value, Borders, Forumla, ... Just go through the Excel documentation for a Range object and you'll find a very large list of properties. Are you sure you really want to compare all these, because there's no way to do all of them in one shot...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This sounds way too much like a homework project.
I already told you how to do the comparison in your other thread that you posted. You don't have to use the loops the way they are written, but you do have to get the Range objects of the worksheets your comparing. You have to write the code, we can't do it for you. We can help if you post some of the code your having problems with.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
yea thx anywy im still working on the code actully I will post code if i cant figure it out my self but meanwhile, i do wana work it out ma self I nevr thot VB.Net could be come this addictive actully! Is that bad or good?!...:P
rubdub
|
|
|
|
|
Does anyone know how to set environment variables in VB.NET?
|
|
|
|
|
There is no support in the .NET BCL to SET environment variables. You can get them, but you'll have to make calls into the Win32 API to actually set them.
There are two sets of environment variables, user and system. When you launch an application, the process gets a copy of the system and user variables for it own use. Calling the GetEnvironmentStrings and SetEnvironmentVariable API functions will modify the PROCESS'S copy of the environment, not the master copy in the OS.
In order to change the System environment variables, you would have to make the changes to the Registry under the key:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
User variables are stored (I THINK!) under:
HKEY_CURRENT_USER\Environment
or
HKEY_CURRENT_USER\Volatile Environment
Then you call the SendMessage API function and tell it to HWND_BROADCAST the WM_SETTINGCHANGE message. This will update the OS copy of the environment variables and tell the running applications that this changes has been made so they can update also.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello
I have created a class which starts a new thread to listen for a connection on a tcp port, which seems to work very well. However, I have a problem that I do not want the background thread to allow the connection if the main thread is busy processing.
Does anyone know if there is a way I can check if the main thread in not responsive from a background thread? I have tried threadstate and isalive, but the thread is still running and alive... just busy.
Thanks
Atari 800XL
|
|
|
|
|
Wouldn't that, by definition, defeat the purpose of a multithreaded app? I mean, you start other threads to handle tasks independent of the main thread so the main thread can go on it's merry way and do something else...
Anyway, I think this isn't as easy as it would sound, because you can't call a method/property on either thread that returns this state because the calling thread would be blocked waiting for the other thread to actually free up and execute your call... I think...
You could look into the Application.Idle event, but that will only fire when your code starts to Idle. There is no event that fires when your code comes OUT of idle, so there is no way to determine when your app is busy.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I aggree it is quite a strange use of multi-threading, but I need to monitor remotely if the program is still responding.
I had a look at the application.idle event and think this could work, the problem is I can't hook up to this event from the class as system.windows.forms.application is not available
|
|
|
|
|
The Application object isn't from Forms. It also doesn't fire an Event that can be used just like any other... I haven't figured how to use it yet, and frankly, don't have the time right now.
What do you mean by Remotely? From another machine? You original post said from a seperate thread. So which is it?
Does this app that your monitoring have a GUI user interface?
You could use the Process class to see if the user interface is still responding, just get the processes on a remote machine using Process.GetProcessByName(machinename, processname) . Then check the Process.Responding() property to see if the GUI is still responding. If not, you could end the process using the Process.Kill() method.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yeah I wasn't very clear, but what I was attempting to do was monitor remotely using a socket to find out if my program was still responding, but I was getting into trouble because the socket listener was running in a seperate thread. So even though the main thread had hung, my background thread was quite happily telling me everything was ok!
This Process.GetProcessByName is exactly what I needed, no need to bother with sockets or threads at all... superb, thanks!
By the way I managed to access the Application.Idle event by adding a reference to System.Windows.Forms in my class library, then I used the following code to check if the calling thread was idle.
AddHandler System.Windows.Forms.Application.Idle, AddressOf Idle_app<br />
<br />
Private Sub Idle_app(ByVal sender As Object, ByVal e As System.EventArgs)<br />
iIdleTime = 0<br />
<br />
End Sub<br />
<br />
|
|
|
|
|
Found one slight problem with the Process.GetProcessByName, running it against a remote machine returns a System.NotSupportedException with the message
Feature is not supported for remote machines.
|
|
|
|
|
execute a file in automathic mode using VB.net?
Now I explain myself better.......
I should make run the file xxx. exe in automatic during the execution of a program.........making this in DOS I would do:
C:\> cd C:\WINNT\ServicePackFiles\i386
C:\WINNT\ServicePackFiles\i386>msinfo32.exe /report FILE_NAME.txt /categories
Can I do this two simple operations whith vb??
Please Answer me ASAP....it's very important....
Thanks All.
Night Soul!!!
|
|
|
|
|