|
|
I guess that would be helpful information The control is based on System.Windows.Forms.Panel .
Actually, I have found some code -- A Multipanel Control in C#[^] -- that has something similar to what I want. This example serializes through the designer; what I ultimately want is to start off with a few components whether or not the designer is invoked at design time.
|
|
|
|
|
Lovely town on the northern California coast; I lived theren when I went to college. But in any case, I have a solution. It is based on liron.levi[^]'s article from last year, A Multipanel Control in C#[^]
The answer turned out to be in the designer. In the CodeProject article linked directly above, the AddPage method gets a reference to IDesignerHost , then calls CreateComponent to create a new instance of the object (in this case, an untabbed "tab" panel.) Called without the name parameter, the created object is given a default instance name, which solves a different problem I had been trying to figure out.
My solution for serializing two child controls into InitializeComponent was to replicate this part of AddPage into the Initialize method. The whole method (translated into VB, sorry) looks like this:
Public Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
Dim iccs As IComponentChangeService = _
DirectCast(GetService(GetType(IComponentChangeService)), IComponentChangeService)
If iccs IsNot Nothing Then AddHandler iccs.ComponentRemoved, AddressOf ComponentRemoved
Dim s As ISelectionService = DirectCast(GetService(GetType(ISelectionService)), ISelectionService)
If s IsNot Nothing Then AddHandler s.SelectionChanged, AddressOf sSelectionChanged
'Attempt to add two pages
Dim DH As IDesignerHost = DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)
If DH IsNot Nothing Then
Dim MPP As MultiPanelPage = _
DirectCast(DH.CreateComponent(GetType(MultiPanelPage)), MultiPanelPage)
MPP.Text = MPP.Name
_MPanel.Controls.Add(MPP)
_MPanel.SelectedPage = MPP
MPP = DirectCast(DH.CreateComponent(GetType(MultiPanelPage)), MultiPanelPage)
MPP.Text = MPP.Name
_MPanel.Controls.Add(MPP)
End If
End Sub
With this, dropping a MultiPanel control onto a form causes the form's InitializeComponent to declare the control, two autonamed panels, initialize everything and assemble them properly.
If this is confusing, don't worry: I'm working on a simplified version which will become a new article.
|
|
|
|
|
|
Hi Guys,
I am trying to send bytes over TCP/IP using the StreamWriter and/or the BinaryWriter.(visual Studios 2008 - VB)
I am so confused, and tried various other ways.
what I want to do:
send 1st data packet as a Long (47, 4, 0)
get a reply (automatic one)
then send long (001)
I can open a connection using the Client connect....
using Dim Client as new Net.sockets.TCPclient
then just send the packets as above!
Really could do with some help!
Cheers,
James
|
|
|
|
|
gymgym_jim wrote: Really could do with some help!
And what exactly do you want help with? Try and describe what you are doing (include a code snippet to clarify), and what is not working.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Hi,
Ok, I have a piece of hardware that can communicate with a PC over TCP/IP.
I want to write a Visual Basic program to be able to send packets of data (as a Long) to this Hardware. The response coming back from this card is not Important.
I have tried different things, and now my code is in a bit of a mess.
I am now trying Winsock.
This makes the connection:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If AxWinsock1.CtlState = MSWinsockLib.StateConstants.sckConnected Then
MessageBox.Show("Server is already connected")
Exit Sub
Else
AxWinsock1.RemoteHost = "10.0.0.202"
AxWinsock1.RemotePort = 7655
AxWinsock1.Connect()
End If
and this sends the data:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If AxWinsock1.CtlState <> MSWinsockLib.StateConstants.sckConnected Then
MessageBox.Show("Server is not connected")
Else
AxWinsock1.SendData(TextBox1.Text)
End If
End Sub
and this is the data Type:
Private Sub AxWinsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
Dim strData As Object
Dim i As Integer
Dim tstring As String
tstring = ""
AxWinsock1.GetData(strData)
For i = 0 To UBound(strData)
tstring = tstring + Chr(strData(i))
Next
TextBox2.Text = tstring
End Sub
How do i get this to not send strings, But Longs only?
Cheers
|
|
|
|
|
I'm not sure of the actual syntax for the library you are using, but you can send and receive data as a sequence of bytes rather than as a string. Just build your message as a byte array and send from there. Similarly on receive store your data into a byte array. If you are putting long values in the array then you need to know where the value starts in order to extract it.
This link[^] has some sample code that should help you.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Would you know how I change this to send a Byte Aray?
|
|
|
|
|
I don't know anything about AxWinsock (could not find it in MSDN), but the link I sent you explains how to do it with tcp.send. If you are having trouble figuring this out it is always best to go to the documentation and look at the samples provided.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I try this and it works succesfully:
''Client
Imports System
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Private Const portNum As Integer = 13
Private Const hostName As String = "hostMachineName" ' or IP "192.168.131.67"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim client As New TcpClient(hostName, portNum)
Dim ns As NetworkStream = client.GetStream()
Dim bytes(1024) As Byte
Dim bytesRead As Integer = ns.Read(bytes, 0, bytes.Length)
Dim xx$
xx = Encoding.ASCII.GetString(bytes, 0, bytesRead)
Beep()
'client.Connect
client.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
'Return 0
End Sub
End Class
'Host
Imports System
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Private Const portNum As Integer = 13
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim done As Boolean = False
Dim listener As New TcpListener(portNum)
listener.Start()
While Not done
Console.Write("Waiting for connection...")
Dim client As TcpClient = listener.AcceptTcpClient()
Console.WriteLine("Connection accepted.")
Dim ns As NetworkStream = client.GetStream()
Dim byteTime As Byte() = _
Encoding.ASCII.GetBytes(DateTime.Now.ToString())
Try
ns.Write(byteTime, 0, byteTime.Length)
ns.Close()
client.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End While
listener.Stop()
End Sub
End Class
|
|
|
|
|
I am trying to implement a HTTP Proxy.
For my implementation I need to detect the end of response object.
What my current implementation does is, it constantly hears from the remote host ( eg. wwww.google.com ) and forwards to whatever data it receives to the requesting process ( eg. web browser )
What I need to do is try to figure out when a particular http response has ended ?
At this point i need to run a piece of code.
Can somebody tell in the byte array that I receive, how do I detect that a http response has finished ?
|
|
|
|
|
If memory serves, the header of the response will have a content length in it. After that, it's just a matter of counting bytes. There is no special sequence of bytes you can look for that terminates the end of the response.
|
|
|
|
|
|
Excellent! I'm glad someone can confirm my insanity!
|
|
|
|
|
This URL States the various rules for detecting end of HTTP
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4[^]
But this point is not clear to me
"2.If a Transfer-Encoding header field (section 14.41) is present and has any value other than "identity", then the transfer-length is defined by use of the "chunked" transfer-coding (section 3.6), unless the message is terminated by closing the connection. "
Any idea what this means, and how to use this information to detect end of response.
|
|
|
|
|
I suggest taking a look at an open source proxy like squid and see what it does.
|
|
|
|
|
Dear All,
Can i have a simple example application to generate a licences key for one of my application. Sp that when the client runs the setup in his meachine it need to ask for a key.
Regards,
P.Sri Pavan.
|
|
|
|
|
There are many ways to generate and validate license keys; the good ones are proprietary and there is no code available for them. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You basicly have two chooses:
a) create and develope your own licensing system
b) buy a 3rd party licensing system
|
|
|
|
|
|
Forums are Discussion Boards.
Deepali
|
|
|
|
|
Were you doing some testing on this board? Asking question yourself... answering yourself?
|
|
|
|
|
Possibly trying to boost his reputation?
|
|
|
|
|
its 'Her' actually.
Deepali is a female name. Deepali... are you in India?
|
|
|
|