|
Hi
I want to find if a machine is connected to network. bu the SystemInformation.network give me status as connected even when i unplug the network cable.
After looking in the internat I found this piece of code to overcome the problem.
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");
System.Management.ManagementObjectCollection objCol = searcher.Get();
foreach (System.Management.ManagementObject networkAdapter in objCol)
{
if (networkAdapter["NetConnectionStatus"] != null)
{
if (Convert.ToInt32(networkAdapter["NetConnectionStatus"]).Equals(2))
{
MessageBox.Show("true");
break;
}
else
{
MessageBox.Show("false");
}
}
but the above piece of code throws a exception "Invalid query". Can anyone let me know what the problem is.
Thanks
Sharath
|
|
|
|
|
Hello
Is there anyway to count Childrens of a directory Entry?
i am unable to count no of children in the following code
foreach (DirectoryEntry Site in W3SVC.Children)
{
}
Actually i want to store children Items in Array and I am unable to store in dynamic arrays
-adnan
|
|
|
|
|
hi, i hope i understand your question, you want to get the count of files or directories in a directory? if this is your question then here is the answer
string [] files;
files = Directories.GetFiles(directory path);
files.length gives you the count of files. this also applies to directories as well:
string [] directories;
directories = Directories.GetDirectories(directory path);
int numberofelements= directories.length+files.length;
hope this helps
|
|
|
|
|
Has anyone noticed AppendText being really really slow? It causes a Gen 0 garbage collection almost every call, and even more frequently as the text grows.
I looked at the AppendText code with .NET Reflector[^], and it turns out that that AppendText calls set_SelectedText, which does a lot.
set_SelectedText uses some SendMessage calls if base.IsHandleCreated, and otherwise splits all of the original text into two strings, and then concats them back into a new string which the Text property is assigned to. That's two new strings half the size of the whole text, and another string the size of the whole thing -- not too surprising that it's so inefficient.
I learned that SetStyle(ControlStyles.CacheText, true); is a remedy, but somehow it hasn't made any difference. I also tried checking to make sure base.IsHandleCreated is true, and surely enough it is, but in that case, it shouldn't even be doing much in managed code.
Any ideas? Thanks in advance.
|
|
|
|
|
AppendText is also buggy in v1.1, it doesn't allow text to be more that 32767 characters. Does this help?
<br />
textBox.Text += "Your Text";<br />
textBox.Focus();<br />
textBox.Select(textBox.Text.Length - 1, 0);<br />
textBox.ScrollToCaret();<br />
Regards
Senthil
My Blog
|
|
|
|
|
Nope
AppendText caused 47 GCs, Text += caused 68.
Thanks though.
|
|
|
|
|
Hi there,
I want to open a socket to a smtp server to send some command like when use telnet.
exp: helo mail.yahoo.com
Then receive message response.
exp: 250 mail.yahoo.com
I don't know is it OK?
Anh, when send a message to smtp server, how to send it like a string. send() method of class socket accept param type of byte[], so, how could I send a command string like "helo mail.yahoo.com"?
Thank you very much.
|
|
|
|
|
Hi,
It is possible to do this with the Socket class or the TcpClient class. I'd suggest you go with the latter. As for sending strings, you can wrap the NetworkStream in a StreamWriter like this,
<br />
TcpClient tcpClient = new TcpClient("smtp_server_name", 25);<br />
tcpClient.Connect();<br />
using (StreamWriter s = new StreamWriter(tcpClient.GetStream());<br />
{<br />
s.Write("HELO SERVER");<br />
}<br />
One thing you need to note is that the SMTP server need not have the same domain name as the webserver. For eg. mail.yahoo.com is the domain name for yahoomail webserver, but it is NOT a SMTP server. You then need to look for MX records.
Regards
Senthil
My Blog
|
|
|
|
|
Thank Senthil very much.
And I want to know to could get message receive from that server?
We'll using a StreamReader, get the stream of the socket and get the message?
Thank you again.
|
|
|
|
|
Yes, that'll work.
Regards
Senthil
My Blog
|
|
|
|
|
Hello,
I am displaying the contents of a rich text control on the printer using the EM_FORMATRANGE message. I would like for the text to be drawn over a colored background. However, it appears that during the processing of the EM_FORMATRANGE message a white rectangle gets drawn behind the text, spanning the width of the bounding rectangle and extending down to the last line of text. I have tried setting the background color of the graphics device context using SetBkColor, tried setting the background brush of the rich text control's client area using SetWindowLong, and tried changing the character format of the control using the EM_SETCHARFORMAT message. While changing the character format does draw the correct background color behind the printed text, the white rectangles still appear.
Maybe I'm doing something wrong, but I'm about to give up on the EM_FORMATRANGE message and draw the text myself. Does anybody know of the correct way to draw rich text over an arbitrary color?
BTW: If I draw to a bitmap, everything works fine.
Thanks in advance,
Jarrod
|
|
|
|
|
|
Thank you for your help, but this is not my problem. I have an extended text box already that uses EM_SETCHARFORMAT to alter the background color of the text. However, when this is drawn to the printer, there is a white rectangle "around" the text, presumably where the EM_FORMATRANGE message processing clears space for the text rectangle. For example, if I have a rich textbox with a blue background and "Hello World" centered at the top, the printout would be:
******************Hello World**********************
Where the "*"'s are white rather than blue. The area behind "Hello World" is blue, and the area underneath is blue. I can't seem to find anybody having this same problem. Please let me know if I misunderstood your solution in any way, and thanks again for the help.
- Jarrod
|
|
|
|
|
is it possible to set the color of particular Item of the list box?
for example i wnat to change the textcolor to Green if item`s text equals to "Item1"
any help will be appreciated
-adnan
|
|
|
|
|
|
|
Hello all.
Take a Label with Image or ImageList and add Click Event.
Then....
...Determine if click event occurred within the bounds of the image or within the bounds of the label text.
Any Ideas?
(I know I could just make two controls, an image and a label and put them next to each other....but humour me a little please )
|
|
|
|
|
You can get the screen coordinates of the mouse using the static Control.MousePosition property. Translate that to client coordinates using the instance method PointToClient on the control - presumably the Label or whatever you need - to get the control-relative coordinates:
void myLabel_Click(object sender, EventArgs E)
{
Point p = myLabel.PointToClient(MousePosition);
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello.
so I'm Japanese. sorry cheep english.
I want to create like a MainMenu Designer.
1st,I think create button component with edit on design time.
I want to know, way to Design time edit.
image...
MyButton Drag & Drop to form.
click the MyButton,after show edit box(like manu item edit)
Should I examine IDeginer?
I Can't find it,around IDeginer class.
Please teach when there is a person who has information.
thank you.
|
|
|
|
|
|
Hi All,
I want to migrate my app from VB.net to C#. How feasible it is?
|
|
|
|
|
Very feasible, if you know both languages. If not, you can use various online translators to translate your code for you, though they are not perfect and will not translate your entire application all at once.
Other than that, it's entirely up to your skill set.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
|
Try this[^].
It worked pretty well for me.
Cheers,
Simon
sig :: "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
article :: animation mechanics in SVG blog:: brokenkeyboards "Most of us are programmers, but a few use VB", Christian Graus
|
|
|
|