|
sure u can have answer, best 2 stare in space for long time - annswer will cum to u in flash
|
|
|
|
|
Yeah... annswer is a terrible guy he always make the same...
|
|
|
|
|
Norm .net wrote: best 2 stare in space for long time - annswer will cum to u in flash
That's what she said...
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Norm .net wrote: best 2 stare in space for long time - annswer will cum to u in flash
That's a completely different website.
|
|
|
|
|
Going to work I was listening a strange low music... you know that typical songs that are played during those old terror films just before the ghostly spirits make their entrance... I was wondering which kind of blasphemous horror had happened and then I saw your post...
|
|
|
|
|
Hi all,
I am developing a Winform appln in C#, which contains multiple tabs..
i want to use same shortcut keys on different tabs for different controls.
but i am not able to the same, can any one help ??
Thanks in advance..
|
|
|
|
|
Set the Form's KeyPreview property to true and handle the KeyDown/KeyPress events. Don't handle the KeyDown/KeyPress events of the tab or the constituent controls. Within the event handler, you can look for specific key combinations and take action based on the active tab.
|
|
|
|
|
I'd recommend a simple if or case statement (whichever you prefer) to identify the current selected tab.
switch (tabControl.SelectedIndex)
{
case 0:
break;
case 1:
break;
}
This would work under the assumption that you were using the tab indices to find out what's currently selected. There's also a function that allows you to check the current tab by its name. It'd work in the same respect as the .SelectedIndex function, expect you'd be using the tab names rather than the indices. It's the .SelectedTab function.
I hope this was of some help. Happy programming!
|
|
|
|
|
There are some cool classes and tricks and short cuts in C#. I know this but I have not worked with C# enough to have them memoried.
One cool trick is this. If you read from a file data that is arranged in a similar line-by-line structure where each line is arranged in columns spaced out by tabs, the data can be read into a kind of class in C# and then you can parse out one column of data by simply doing a "for each" command. Does anyone know off-hand how this is done?
I need to update this.
I wrote a C# program that reads code one line at a time. Each line has data seperated by tabs.
Here is what my C# code is supposed to do. The line is supposed to be split into a string array by using the "Split" string methodIt is supposed to be spit read in text one line at a time and I use the "Split" method to group the line according to the tab character.
But, as this screen shot shows, it does not work. Any idea why?
http://i67.photobucket.com/albums/h292/Athono/problem.png
-- modified 18-Aug-12 15:16pm.
|
|
|
|
|
You might want to phrase it as an obvious question next time; as soon as I read "One cool trick is this", I assumed you where sharing a tip and skipped reading the rest.
You're looking for the filehelpers[^] library. An alternative would be using OleDb[^].
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Let's look at a simple example: I want to create a Button class with a different BackColor and Size than the "normal" button (.Net 4, Windows Forms). Looks easy, doesnt't it? But I face some problems.
A simple "solution" would be:
public class BernieButton : Button
..
public BernieButton()
{
this.BackColor = Color.Green;
this.Size = new Size(150,50);
}
Compile the project, drag a BernieButton onto Form1, and everything looks fine.
But now Sales decides that the BackCOlor must be yellow, and the size is too big. OK, change that in the constructor, test the new button, looks fine. Rebuild the old projects, and - the buttons there look like before. Failure!
How could that fail? When the button was dragged onto the form, the Designer added some lines in the InitializeComponent method of the form:
this.BernieButton1.BackColor = Color.Green;
this.ernieButton1.Size = new Size(150,50);
and that code gets executed after the constructor of the button, thus overriding the recent changes of the default value.
I tried overriding the properties:
[DefaultValue(typeof(Color), "Green")]
public override Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}
and then set the default value in the constructor (using reflection, thus circumventing double storage of the new default value). That really works as it is intended, the designer does not write a line for BackColor in the InitializeComponent method.
But it does not work with Size. There is an important difference: BackColor is "virtual " in the Button class, Size is not.
I tried with the "new " keyword, but it fails: a line is added to InitializeComponent , and later changes of the default value are ignored.
I thought of setting the DefaultValueAttribute of the properties in the constructor. But that is not possible, attributes are read-only at run-time.
Do you have some ideas on how to overcome these limitations with inherited non-virtual properties?
|
|
|
|
|
There is a property DefaultSize that you can override. This works for me:
public class MyButton : Button
{
private static readonly Size SizeDefault = new Size(100, 50);
protected override Size DefaultSize
{
get { return SizeDefault; }
}
}
|
|
|
|
|
Sorry, it does not:
Drag the button onto a form, and it looks OK. Then change the DefaultSize, e.g.
private static readonly Size SizeDefault = new Size(200, 100); , rebuild your solution, and the button has still the old size. Only new buttons get the new default size, "old" buttons do not get updated.
Again, a look into Form1.Designer.cs shows the reason:
this.myButton1.Size = new System.Drawing.Size(100, 50); The key to the solution is (likely) in preventing the designer from writing that line - as with the BackColor property.
But a
public bool ShouldSerializeSize() does not help either.
And
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new Size Size
{
get { return base.Size; }
set { base.Size = value; }
} prevents individually sized buttons.
|
|
|
|
|
Hmmm, I see what you're getting at now. It seems this is the case with all controls so maybe it's something coded into System.Windows.Forms.Control ?
I don't have reflector here, but I will have a poke around later and have a look in the source code...
|
|
|
|
|
I have written a simple and minimalist HTTP proxy server that runs on command line. In the Start() method, a TcpListener blocks until it gets a client request and creates a new thread (ThreadHandleClient method) that processes this client, fetches its url and relays data.
The trouble is in the relay logic that I want to refine. In the first inner loop, I receive all webserver data and send it to client until zero bytes are left. In second inner loop, I do vice-versa: receive all client data and send to web-server until zero bytes left. However, the code gets blocked in the beginning of second inner-loop at client.receive(). This is what I'm basically doing:
Any help will be truly appreciated. Thanks in advance.
public void Start(IPAddress ip, int port)
{
try
{
TcpListener listener = new TcpListener(ip, port);
listener.Start(100);
while (!stopFlag)
{
Socket client = listener.AcceptSocket();
IPEndPoint rep = (IPEndPoint)client.RemoteEndPoint;
Thread th = new Thread(ThreadHandleClient);
th.Start(client);
}
listener.Stop();
}
catch (Exception ex)
{
Debug.Print("START: " + ex.Message);
}
}
public void ThreadHandleClient(object o)
{
try
{
Socket client = (Socket)o;
NetworkStream ns = new NetworkStream(client);
byte[] buffer = new byte[2048];
int rec = 0, sent = 0, transferred = 0, rport = 0;
string data = "";
do
{
rec = ns.Read(buffer, 0, buffer.Length);
data += Encoding.ASCII.GetString(buffer, 0, rec);
} while (rec == buffer.Length);
string line = data.Replace("\r\n", "\n").Split(new string[] { "\n" }, StringSplitOptions.None)[0];
Uri uri = new Uri(line.Split(new string[] { " " }, StringSplitOptions.None)[1]);
Debug.Print("CLIENT REQUEST RECEIVED: " + uri.OriginalString);
if (uri.Scheme == "https")
{
rport = 443;
Debug.Print("HTTPS - 443");
}
else
{
rport = 80;
Debug.Print("HTTP - 443");
}
IPHostEntry rh = Dns.GetHostEntry(uri.Host);
Socket webserver = new Socket(rh.AddressList[0].AddressFamily, SocketType.Stream, ProtocolType.IP);
webserver.Connect(new IPEndPoint(rh.AddressList[0], rport));
byte[] databytes = Encoding.ASCII.GetBytes(data);
webserver.Send(databytes, databytes.Length, SocketFlags.None);
Debug.Print("SENT TO SERVER. WILL NOW RELAY: " + data);
buffer = new byte[2048];
rec = 0;
data = "";
do
{
transferred = 0;
do
{
rec = webserver.Receive(buffer, buffer.Length, SocketFlags.None);
Debug.Print("RECEIVED FROM WEBSERVER[" + rec.ToString() + "]: " + Encoding.ASCII.GetString(buffer, 0, rec));
sent = client.Send(buffer, rec, SocketFlags.None);
Debug.Print("SENT TO CLIENT[" + sent.ToString() + "]: " + Encoding.ASCII.GetString(buffer, 0, rec));
transferred += rec;
} while (rec == buffer.Length);
Debug.Print("loop-1 finished");
if (transferred == 0)
break;
transferred = 0;
do
{
rec = client.Receive(buffer, buffer.Length, SocketFlags.None);
Debug.Print("RECEIVED FROM CLIENT: " + Encoding.ASCII.GetString(buffer, 0, rec));
sent = webserver.Send(buffer, rec, SocketFlags.None);
Debug.Print("SENT TO WEBSERVER[" + sent.ToString() + "]: " + Encoding.ASCII.GetString(buffer, 0, rec));
transferred += rec;
} while (rec == buffer.Length);
Debug.Print("loop-2 finished");
} while (transferred > 0);
Debug.Print("LOOP ENDS. EXITING THREAD");
}
catch (Exception ex)
{
Debug.Print("Error occured: " + ex.Message);
}
|
|
|
|
|
If no data has arrived, then Receive is going to block. If this is not what you want, then use BeginReceive .
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks Richard. For reasons of simplicity, I don't want to create anync calls and handle everything in thant one thread only. Is there no way to do this using the sync Receive() method ?
|
|
|
|
|
If you want, you could call Receive on a background worker thread, but that would entail multiple threads.
The bottom line is that Receive will behave synchronously, meaning it will block when there is no data.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Is there a way to check the data in the socket and call Receive() only when data is available for receiving. This way it should not block, right?
|
|
|
|
|
I see that Socket has a method called Poll . Take a look:
Socket.Poll[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks. The Poll() method really helped. I'm now polling for three seconds before receiving for both client and the server. However, there is still some logical issue with my code:
if (client.Poll(3000 * 1000, SelectMode.SelectRead))
{
rec = client.Receive(buffer, buffer.Length, SocketFlags.None);
Debug.Print("RECEIVED FROM CLIENT: " + Encoding.ASCII.GetString(buffer, 0, rec));
sent = webserver.Send(buffer, rec, SocketFlags.None);
Debug.Print("SENT TO WEBSERVER[" + sent.ToString() + "]: " + Encoding.ASCII.GetString(buffer, 0, rec));
transferred += rec;
}
else
{
Debug.Print("No data polled from client");
}
As I said, one logical fault still remains. In the proxy client machine, I'm able to open google.com. Then performed a search that also went fine. However, when I click on a search result, the proxy again gives me google.com!! What am I missing?
|
|
|
|
|
If i want a simple server to client communication as a background service on windows Os, that would only send ISP infor to a hosted domain, WHERE would i start? C# or VB.net or other? Which has an example or godd start?
Experience is the best teacher
|
|
|
|
|
kipchirchir wrote: WHERE would i start?
By explaining that in terms we can understand?
kipchirchir wrote: C# or VB.net or other?
Whichever you know and are comfortable with.
VB and C# are interchangeable, pretty much, anything you can do in one, you can do in the other.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
See my answer in the .NET forum; BTW, please do not post the same question in multiple forums.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
If I do something like this
XElement root = new XElement("Root",
new XAttribute("Att1", "a"),
new XAttribute("Att2", "b"),
new XAttribute("Att3", "c"));
XDocument document = new XDocument(root);
document.Save("file.xml");
Instead of it writing
Root Att1="a" Att2="b" Att3="c"/
it writes Root Att3="c" Att2="b" Att1="a"/
Even in debugging mode when I look at the XML contents of document it appears to be in the proper order, but when it writes to file it reverses them. Can anyone tell me why it is doing this?
|
|
|
|
|