|
Public Class Form1
Dim g As Graphics
Dim db As Boolean
Dim x As Integer = 100
Dim y As Integer = 100
Dim w As Integer = 150
Dim h As Integer = 150
Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
Console.WriteLine(e.Delta.ToString)
If (e.Delta > 0) Then
Console.WriteLine("in zoomin")
w = IIf((w * (e.Delta / 100)) < 3, 3, (w * (e.Delta / 100)))
'w = w * (e.Delta / 100)
Console.WriteLine("inside zoomin e.delta " & e.Delta.ToString)
Console.WriteLine("w" & w)
h = IIf((h * (e.Delta / 100)) < 3, 3, (h * (e.Delta / 100)))
'h = h * (e.Delta / 100)
End If
If (e.Delta < 0) Then
Console.WriteLine("zoomout")
w = w / ((e.Delta * -1) / 100)
h = h / ((e.Delta * -1 / 100))
End If
Console.WriteLine("w" & w)
Me.Refresh()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawRectangle(Pens.Black, x, y, w, h)
End Sub
End Class
dinvit83
|
|
|
|
|
Not very efficient, but it works. I prefer to lead people to water, rather than throw water at them.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Christian Graus wrote: lead people to water, rather than throw water at them
Remind me never to spontaneously combust around you!!
|
|
|
|
|
Previously my code was working perfectly fine but suddenly showing up this error Unable to write data to the transport connection:An existing connection was forcibly closed by the remote host; whenever i try to write something on the network stream. Following is the code i am using right now:
Dim PacketSize As Integer = 8192
Dim client As New TcpClient
client.Connect(IPAddress.Parse("192.168.15.51"), 7771)
Dim ns As NetworkStream = client.GetStream
Dim fs As New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim buffer(PacketSize - 1) As Byte
Dim i As Integer
i = fs.Read(buffer, 0, PacketSize)
While i <> 0
ns.Write(buffer, 0, i) <-- this line cause the error
i = fs.Read(buffer, 0, PacketSize)
End While
fs.Close()
ns.Close()
There's no anti-virus or firewall on target machine. I've even turned window's firewall off. Do i have to start any service on the target machine which somehow stopped??? I've searched everywhere but didn't find solution. Please help.
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
modified on Tuesday, May 5, 2009 2:13 AM
|
|
|
|
|
http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/6981b252-30f0-4eb9-a3a6-bf6f2b138fb3/
Visit this.
dinvit83
|
|
|
|
|
I got exactly the same problem. this app used to works well....
|
|
|
|
|
Hi,
I've written the below code (using Visual Basic 2008 Express) to maximize a notepad window, close the notepad window and then restart the notepad window. During the debugging (F5), everything works fine.
Then i build the project. However, when i run the .exe file (in Release folder), the notepad window stops at ALT+TAB and did not maximize and close and then a new notepad application window is started. It is not working exactly the same as what i saw during debugging.
Can anyone pls advice me what went wrong? Thanks very much.
================================================================================================
Imports System.Runtime.InteropServices
Imports System.Threading
Module Module1
<DllImport("user32.dll")> Public Function _
FindWindow(ByVal strClassName As String, ByVal strWindowName As String) As Integer
End Function
<DllImport("User32.DLL")> Public Function _
SetForegroundWindow(ByVal Hwnd As Long) As Boolean
End Function
Sub Main()
Dim hwnd As Long
Dim ProcID As Integer
hwnd = FindWindow(vbNullString, "Untitled - Notepad")
If hwnd <> 0 Then
'MsgBox("The window handle is " & hwnd)
SetForegroundWindow(hwnd)
'Restore minimized Notepad window
Thread.Sleep(3000)
My.Computer.Keyboard.SendKeys("%( )X", True) 'ALT+SPACEBAR to restore minimize window
'Close Notepad
Thread.Sleep(3000)
My.Computer.Keyboard.SendKeys("%{F}X", True) 'ALT+F in Notepad
'Start Notepad after 10 seconds delay
Thread.Sleep(10000) 'Delay 10000 milliseconds
ProcID = Shell("NOTEPAD.EXE", AppWinStyle.NormalFocus) 'Start Notepad.exe
AppActivate(ProcID)
Else
GoTo Finish
'MsgBox("Notepad is not running")
End If
Finish:
End Sub
End Module
======================================================================================================
|
|
|
|
|
helen00 wrote: My.Computer.Keyboard.SendKeys("%( )X", True) 'ALT+SPACEBAR to restore minimize window
I'd avoid using SendKeys altogether. It's a bad method for controlling another application since the input focus can change to any window at ANY time. This includes the time between your call to SetForegroundWindow and the call to SendKeys.
Alt-Space, X closes the current window. It does not "restore minimize window".
helen00 wrote: the notepad window stops at ALT+TAB
Your code doesn't mention anything about Alt-Tab.
Your should be using .NET classes and methods to do this. The Process class makes it a lot easier and you don't have to PInvoke any Win32 functions to do it.
|
|
|
|
|
Hi,
Thanks for your prompt reply.
Can you advise me sample codes of the better way to control another application? My whole objective of writing the program is to look for the Notepad window, graceful close the notepad via File > Exit and then restart the Notepad.
Your help and guidance will be greatly appreciate.
Regards
|
|
|
|
|
Dave is right, what you want to do is very fragile. But, there's no other way to control a program that doesn't expose a way of doing it. Your best bet is probably not to do it at all.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Christian is right. "Controlling" another app like this is VERY fragile and VERY easily broken. You have no way of keeping a known state, or knowing what happened when something goes wrong, and just about no way of correcting the situation, other than abandoning the entire process and closing all the apps involved and restarting the whole app.
Your code looks for a Notepad window, closes it and restarts Notepad?? To what end?? Why??
|
|
|
|
|
Public Sub New(ByVal type As LocationType, ByVal element As InspectionEntity)
Me.New(type, New List(Of InspectionEntity){element})
End Sub
Public Sub New(ByVal type As LocationType, ByVal entities As List(Of InspectionEntity))
Me.New(type, entities, New InspectionEntity([LIB].Enumerations.TableIDDefault.NullKey, "", ""))
End Sub
Ok...so here's the problem - One of my constructors accepts a singular "InspectionEntity" and I need to shove it into a List(Of InspectionEntity) so that it can be indirected to the next constructor in my chain (Only the terminal constructor sets properties on the object)
However, I am getting a squiggle beneath the '{' in {element}
Comma, ')', or a valid expression continuation expected.
Does anyone know the VB syntax to initialize the contents of a List(Of T) in-line?
"I need build Skynet. Plz send code"
|
|
|
|
|
Try this:
New List(Of InspectionEntity)(new InspectionEntity() {element})
10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011
|
|
|
|
|
Good call!
I tried
new List(Of InspectionEntity)(element)
but the compiler lied to me! lol...or at least that's my story and I'm sticking to it. My code above gave an InvalidCastException - Cannot convert type "InspectionEntity" to "IEnumerable"
When I altered it to be
new List(Of InspectionEntity)(new InspectionEntity(){element})
everything cleared itself out nicely.
"I need build Skynet. Plz send code"
|
|
|
|
|
Ok...never mind - I should have known:
The call to the constructor has to be like this:
Public Sub New(ByVal type As LocationType, ByVal element As InspectionEntity)
Me.New(type, New List(Of InspectionEntity)(element))
End Sub
Public Sub New(ByVal type As LocationType, ByVal entities As List(Of InspectionEntity))
Me.New(type, entities, New InspectionEntity([LIB].Enumerations.TableIDDefault.NullKey, "", ""))
End Sub
Note the parentheses surrounding "element" instead of curly braces...which would be the standard in every language OTHER than VB.
New problem though: The element being passed in is null, and I get an ArgumentNullException saying that the list cannot be initialized with a null object. Anyone good enough with predicates that they could provide one that could initialize the list with element if !element.Equals(null) and suppress the initialization if the argument is null....I mean..."nothing"?
I'm pretty sure that an IIF will not work in this case, but please feel free to prove me wrong!
Update: I proved myself wrong! A chained IIF works...albeit wastefully since the true and false conditions must be evaluated, but it works
Public Sub Store(ByVal type As Location.LocationType, ByVal element As InspectionEntity)
'...
If Not typeAlreadyTracked Then
'Theres no actual line-continuation '_' in my code. I only placed it here because the forum posts will not scroll horizontally.
'The code is actually much more legible in a single line
Me._locations.Add(IIf((element Is Nothing), New Location(type), New Location(type, CType(_
IIf element Is Nothing, New InspectionEntity(-999, "", ""), element), InspectionEntity))))
typeAlreadyTracked = True
End If
End Sub
Both ternary conditions in the chain are the same check
I perform an IIF(element is nothing...) and another IIF(element is nothing...) within the transverse of the initial condition
(i.e. IIF(element is nothing) - "True of False" is a tautological impossibility because it requires element to be both null and !null at the same time; which essentially provides a true ternary evaluation (albeit with the computational slowdown of a full-scan evaluation)
"I need build Skynet. Plz send code"
modified on Monday, May 4, 2009 5:40 PM
|
|
|
|
|
btw...if anyone is interested in the whole constructor chain:
Public Sub New()
Me.New(LocationType.NonDeterminant)
End Sub
Public Sub New(ByVal type As LocationType)
Me.New(type, New List(Of InspectionEntity))
End Sub
Public Sub New(ByVal type As LocationType, ByVal element As InspectionEntity)
Me.New(type, New List(Of InspectionEntity)(element))
End Sub
Public Sub New(ByVal type As LocationType, ByVal entities As List(Of InspectionEntity))
Me.New(type, entities, New InspectionEntity([LIB].Enumerations.TableIDDefault.NullKey, "", ""))
End Sub
Public Sub New(ByVal location As Location)
Me.New(location.Type, location.Entities, location.Selected)
End Sub
Public Sub New(ByVal type As LocationType, ByVal entities As List(Of InspectionEntity), ByVal selected As InspectionEntity)
Me._type = type
Me._entities = entities
Me.setSelected = IIf(selected Is Nothing, New InspectionEntity([LIB].Enumerations.TableIDDefault.NullKey, "", ""), selected)
End Sub
"I need build Skynet. Plz send code"
|
|
|
|
|
--> i am having a problem with this code...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not Me.TextBox1.Text = "a" Or Not Me.TextBox1.Text = "b" Then
MsgBox("1")
Else
MsgBox("2")
End If
End Sub
--> this code always prints "1" in da message box..
--> what is the problem?
J A Nasir K
|
|
|
|
|
If TextBox1.Text is "a" then it is not "b", thus the first condition is fulfilled. The same for TextBox1.Text being "b". Any other value will also fulfill this condition.
You probably want to exclude both "a" AND "b".
10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">Jamal Abdul Nasir wrote:</div> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not Me.TextBox1.Text = "a" And Not Me.TextBox1.Text = "b" Then MsgBox("1") Else MsgBox("2") End If End Sub</blockquote>
Use And not Or
If it is not A and Not B then do something, else do something else.
------------------------------------
"Children today are tyrants. They contradict their parents, gobble their food and tyrannize their teachers. I despair for the future."
Socrates 400BC
|
|
|
|
|
Try to avoid "Not Logic". It is hard to read thus it can cause logic errors. Write you logic without the NOT operator and you will find it is much easier.
|
|
|
|
|
Try this condition
if me.textbox1.text = "a" or me.textbox1.text = "A" or me.textbox1.text = "b" or me.textbox1.text = "B" Then
MsgBox("2")
else
MsgBox("1")
end sub
|
|
|
|
|
This problem was solved hours ago. It's great you want to help people, but perhaps help people who still need help ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
On top of what Christian said, there are better ways of doing this than to make 4 conditions to check for 2 characters, while ignoring case.
|
|
|
|
|
How do I download the source code. When I open it in visual basic 2008 it's not working!?
|
|
|
|
|
|