|
Arun Bhalla wrote:
I need to implement my own MouseHover event
Why? It's built into WinForms.
If you really need to roll your own, try TrackMouseEvent[^].
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'm writing a library of lightweight control-like objects which paint themselves on controls, such as Panel. I need to mimic MouseHover for these control-like objects. If I use Panel's MouseHover event, I only get the hover event once, while the cursor is in Panel's bounds, even if it hovers over my different control-like objects, all within Panel.
TrackMouseEvent seems like it may be the way to go, or at least I'll know where to dig for the default value. (Yet another setting missing from SystemInformation.) Thanks!
|
|
|
|
|
Arun Bhalla wrote:
I'm writing a library of lightweight control-like objects which paint themselves on controls, such as Panel.
Hehe, my team is creating a library of lightweight controls, called Fluid UI Toolkit[^]
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Cool! I look forward to seeing that near completion... as we all know, the Microsoft-provided WinForms library is not so hot.
I guess my library is quite different from yours... mine is more like Visio shape objects rather than things like toolbars.
|
|
|
|
|
Arun Bhalla wrote:
I guess my library is quite different from yours... mine is more like Visio shape objects rather than things like toolbars.
I figured that. Actually, I plan to use mine for document drawing objects, as it will probably lend itself well to that.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
The main reason (or rather, the straw that broke the camel's back) I wrote the library is that Control.Location, etc. didn't inherently support the location on a ScrollableControl relative to AutoScrollPos. Very annoying. There were other issues, though.
|
|
|
|
|
.NET AutoScroll== .
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Yeah, and I'm lazy. AutoScroll seems to mostly work, but in a tricky and incomplete way. Oh well!
|
|
|
|
|
I have a multiline textbox and wanted to know if there was any way to limit the characters that are entered to HEX characters ... I wanted to find an easier way than using the || against all the possible characters that I want to accept ...
Thanks
![Confused | :confused:](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|
Add a handler for the KeyPress event of your text box
<br />
private void myHexTextbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)<br />
{<br />
string Allowed = @"0123456789ABCDEFabcdef";
if (Allowed.IndexOf(e.KeyChar)==-1)<br />
{<br />
e.Handled = true;
}<br />
}<br />
|
|
|
|
|
I have a database application that using a form to present records from the database to the user and let them navigate through the records using foward and back buttons. I use a BindingManagerBase object to navigate the records and everything works fine. However, I have some wierdness going on. When I add a new record, the new record should become record 0 (because the DataView is sorted by a column that is left blank when I create a new record) and I should be able to set the form to display that record by doing this after inserting the new record:
<br />
myBindingManger.Position = 0;<br />
Only it doesn't work. The form still displays the data from the record I was looking at when I inserted the new record. However, if I do this:
<br />
myBindingManger.Position = 1;<br />
myBindingManger.Position--;<br />
It works just fine. Can anybody explain to me what's going on here? It's a mystery to me!
|
|
|
|
|
Can anyone tell me what function is used in c# to canonicalizes a URL, which includes converting unsafe characters and spaces into escape sequences?
In Visual c++ exists this function
BOOL InternetCanonicalizeUrl(
LPCTSTR lpszUrl,
LPTSTR lpszBuffer,
LPDWORD lpdwBufferLength,
DWORD dwFlags
);
but i didn't find the correspondent in c#
thank you
|
|
|
|
|
System.Web.HttpServer.UrlEncode() might be what you need.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Uri url = new System.Uri(myString);
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I have logging code that I want to set a global variable for the whole application, something like bool logging = true;
I don't want to have to go to all my classes and set this variable. What is the best way to handle this? Can I set it in the web.config file? If so, how?
Thanks!
|
|
|
|
|
You could use compiler directives:
#if DEBUG
#endif
This has the benefit of being compiled out when you go to release code.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Take a look at the Trace and TraceSwitch classes.
Brian
|
|
|
|
|
One approach is to create a class that handles the logging and keeps track of whether it's enabled or not, like this:
class Log
{
private static bool m_enabled = System.Configuration.ConfigurationSettings.AppSettings["Logging"] == "true";
public static bool Enabled
{
get { return m_enabled; }
}
public static void Error(string message)
{
if (Enabled)
}
public static void Info(string message)
....
}
Then you can call Log.Error, Log.Info, etc. in your code. For more details on how to use web.config, check out MSDN[^].
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
Thanks Alvaro. That is exactly what I was looking for.
I will keep the other suggestions in mind for other things, however.
Cheers.
|
|
|
|
|
Hi guys,
I am trying to create TCP Listener windows services using C# to listen to a local TCP port continuously.
I have written a windows console application which does the job properly but when I convert it to windows services it did not work, as you know definitely I can not use infinity loop on the OnStart method but I want the services to keep listen to synchronous connection by a client and send response when data received.
The senior as following:
I want to listen to a port which I will receive a string 200 characters from a client then send response as acknowledgement.
Your response is highly appreciated.
Regards,
|
|
|
|
|
You will need to create a thread to listen on, its a simple task,
Create a function in your service class which has the listneing socket and the loop in it, eg:
private void ListeningThread(void)<br />
{<br />
TcpListener oListener = new TcpListener();<br />
<br />
_mnThreadCount ++;<br />
<br />
oListener.Listen(nWhateverPortYouWant)<br />
while(!_mbCloseThreads)<br />
{<br />
}<br />
<br />
_mnThreadCount -- ;<br />
}
In OnStart, create your thread
public override OnStart()<br />
{<br />
_mbCloseThreads = false;<br />
_mnThreadCount = 0;<br />
<br />
ThreadStart oThreadStart = new ThreadStart((void)this.ListeningThread);<br />
Thread oThread = new Thread(oThreadStart);<br />
<br />
oThread.Start();<br />
}
and in your OnStop you need to signal the thread to close (_mbCloseThreads) and wait for the threads to shut down (_mnThreadCount)
public override OnStop()<br />
{<br />
_mbCloseThreads = true;<br />
while(_mnThreadCount > 0)<br />
Thread.Sleep(1);<br />
}
Things to remember:
If the thread crashed, always decrement the threadcount, put it in a finally block and that should be ok.
Use Thread.Sleep(1); at the beginning of each continuous loop so it fress up CPU time else your CPU will run at 100%
The code above might not be 100% correct as its strtaight out of my head, but I am sure you will get the general idea of it.
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|
|
Dear James,
Thanks for your replay, I was doing the same way what you have descripted but to make thing exact what you have mentioned please see below code:
the problem is when I start the services and send first stream data it work for the first request and it send proper response but for the second request it did not work I need to stop & start the services then it work for the first request what do you thing the problem???
public void ListeningThread()
{
//Get application Setting information from app.config
strIpAddress = ConfigurationSettings.AppSettings["IPAddress"];
intPort = Int32.Parse(ConfigurationSettings.AppSettings["Port"]);
strConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
IPAddress IpAddress = IPAddress.Parse(strIpAddress);
TcpListener ilListener = new TcpListener(IpAddress,intPort);
//Start listening
ilListener.Start();
_mnThreadCount ++;
LogError("ilListener.Start();");
while ( !_mbCloseThreads)
{
try
{
TcpClient ilSocket = ilListener.AcceptTcpClient();
NetworkStream networkStream = ilSocket.GetStream();
if(networkStream.CanRead)
{
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[165];
networkStream.Read(bytes, 0, 165);
// Returns the data received from the host to the console.
strRecievedData = Encoding.ASCII.GetString(bytes);
}
else
{
//error
}
if ( (int) ilSocket.ReceiveBufferSize >=165)
{
LogError("data size read" + ilSocket.ReceiveBufferSize + strRecievedData );
EnCodeData(strRecievedData);//here I am doing some changeson srtRecievedData
strSendResponse = strResponse;
if(networkStream.CanWrite)
{
Byte[] sendBytes = Encoding.ASCII.GetBytes(strResponse);
networkStream.Write(sendBytes, 0, sendBytes.Length);
}
else
{
// error here
}
LogError("data Sent:" + strSendResponse);
}
}
catch (Exception ex)
{
//
}
}
_mnThreadCount -- ;
ilListener.Stop();
}
protected override void OnStart(string[] args)
{
_mbCloseThreads = false;
_mnThreadCount = 0;
ThreadStart oThreadStart = new ThreadStart(this.ListeningThread);
Thread oThread = new Thread(oThreadStart);
oThread.Start();
LogError("Service Started");
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
_mbCloseThreads = true;
while(_mnThreadCount > 0)
Thread.Sleep(1);
LogError("Service Stopped");
}
I appreciate you immediate response and Thanks in advance.
Regards,
Baqer
|
|
|
|
|
Ok, my immediate advice would be to do the following:
1) Put the client connection into a new thread - for this you will need a new class with a member for the TcpClient object and a function for the thread. Reasonm being i think the Read function blocks the thread until it gets some data so your accept wont be getting called - unless the Accept also blocks, im not sure.
2) The ocrrect way to accept the connection you need to first see if a connection is pending, there is a Pending property/function on the listener, if this true then accept the connection, create a instance of the client thread class mentioned above - set a member variable of the class to the connection and start a new thread using the thread function you need to create in the new class. This leaves the server thread still available to accept more incoming connections. You need to keep track of the thread count and the _mbCloseThread information now, you could create a static instance of the data in another class and access it like that or pass in class with the thread counts and just make them public.
3) When receiving data from the client connection, you may want to read how much data is available and read the data accordingly, or you could use a BinaryFormatter and pass around an 'Envelope' (dont know if its the right terminiology but it fits!) object which is a wrapper class you create to store the data you want to send, eg:
Public Class MyEnvelope
{
string Data
}
Set the Data to what you want to send then use the BinarryFormatter to serialize it into the NetworkStream of the connection, and on the receive end, you can Deserialize from the stream.
Sorry if this doesnt make all much sense! I have just woken up!
If you are still having trouble I will email you a simple client/server test service in C# I havent got one to hand at the moment, but I could put one together later.
Cheers, James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|
|
Thanks James,
I will try it then tell you about the result.
cheers,
Baqer
|
|
|
|
|
Hi James,
I am still having the same problem. The issue that the client software who sends the information is not written by me it is software provided by customer. Which send a string & receive a string as acknowledgement.
now the question is does it mater if you send the data binary or string coz as you know the write or send method of the socket is accepting byte anyway I have used as well the Networkstream.write which send as string.
James if you have any code can help or if you have any other way to be done please suggest.
I need this service to work.
Best Regards,
Baqer
|
|
|
|