|
How can i programatically send a shutdown or a restart command from a On_click event?
Is this possible in c#?
Thanks
|
|
|
|
|
|
how do we move a file containing an image eg pic.jpg to a certain path like "e:\vs2005\images in c#????and the file info and directory info methods cant do this.is ther any other way too move a file to a path?
any help/suggestions/ideas would be highly appreciated!
bia ali
|
|
|
|
|
biaali wrote: and the file info and directory info methods cant do this
Why not?
is ther any other way too move a file to a path?
Yes, but if you can't do it with System.IO, there is virtually no chance that any other method would work.
---
b { font-weight: normal; }
|
|
|
|
|
It seems likely to me that you've opened the file in your code and not disposed of it, which leaves a file handle open. This would cause the file to be inaccesible, and as has been said, if the IO classes won't do it, nothing will.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
can u still tell me how to do this using the IO classes....cause i m not able to find any method for moving a file to a certain directory....though ther are methods for moving a file to a certain file and moving a directory to a certain directory but i cant seem to find any metyhod for moving a file to a directory.i need help in this regard.
bia ali
|
|
|
|
|
What you're asking makes no sense. How do you turn a file into a directory ?
System.IO.File.Move()
This method will take file paths. How else could it move a file ? If the directory does not exist, you need to create it first.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
how can make textbox (with bold red line ) in Border ??
Palestine
|
|
|
|
|
win form load it will be normal textbox
but when mouse over (the border will be red color)
Palestine
|
|
|
|
|
Hello
You'd have to handle MouseEnter and MouseLeave events like this:
private void textBox1_MouseEnter(object sender, EventArgs e)
{
Graphics g = textBox1.CreateGraphics();
g.DrawRectangle(new Pen(Brushes.Red, 3), new Rectangle(0, 0, textBox1.Width - 5, textBox1.Height - 5));
}
private void textBox1_MouseLeave(object sender, EventArgs e)
{
Graphics g = textBox1.CreateGraphics();
g.DrawRectangle(new Pen(Brushes.White, 3), new Rectangle(0, 0, textBox1.Width - 5, textBox1.Height - 5));
}
Regards
|
|
|
|
|
Hi!
That's not a good advice you're giving there.
You're creating resource leaks because you don't dispose of the Graphics object and drawing to the textbox in this way is only visible as long as the textbox isn't redrawn.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Hello
mav.northwind wrote: you don't dispose of the Graphics object
Well, last time I checked my GC wasn't on vacation! My graphics objects are local variables, they will be disposable once the call to the handler is over.
mav.northwind wrote: drawing to the textbox in this way is only visible as long as the textbox isn't redrawn.
Unfortunately, no! This is not a webpage where the user may click refresh, and almost all the causes of paint are mouse involved. Once the mouse is out of the box, it doesn't matter!! Even when the user types in the box without moving the mouse out, the box is still there. Besides, this is just a hint. You want to handle the paint event as well, not a problem.
Thanks for the post though.
Regards
|
|
|
|
|
ReHi!
Nader Elshehabi wrote: Well, last time I checked my GC wasn't on vacation! My graphics objects are local variables, they will be disposable once the call to the handler is over
It's not that the GC isn't working correctly, you're not calling Dispose() !
You shoud use:
using (Graphics g = textBox.CreateGraphics())
{
} Nader Elshehabi wrote: Unfortunately, no! This is not a webpage where the user may click refresh, and almost all the causes of paint are mouse involved. Once the mouse is out of the box, it doesn't matter!!
Sorry to say that, but this is exactly the cause for many questions in this forum when people ask why they are having problems when they paint directly on top of controls.
The paint event is the only correct place to perform painting.
With your suggestion, just move another window over the textbox (or part of it) and you'll see what I mean.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Hello
I don't want to sound like I'm just arguing, but it's nice to have this talk with you.
mav.northwind wrote: you're not calling Dispose()
Best practice, you should call dispose() I know, but it occurs to me, why to dispose it, if it will be disposed by itself after the event handler is finished??
mav.northwind wrote: just move another window over the textbox (or part of it) and you'll see what I mean.
How could you do that without moving the mouse out of the textbox first?;P
Again, it's nice to have this talk with you.
Regards
|
|
|
|
|
Rehi!
Graphics implements IDisposable and is freeing the native GDI+ graphics handle in its Dispose() method.
When you don't call Dispose() the resource doesn't get freed and your app will crash the computer after a while because it's running out of GDI handles eventually.
Nader Elshehabi wrote: How could you do that without moving the mouse out of the textbox first?
Alt-Tab? And another Alt-Tab to get back to the original window. The mouse still is inside the TextBox but I'm pretty sure there'll be no red border.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Hello
Thank you for your kind advice. I'll make sure to dispose managed objects I create. Also I'd be happy to read an article -specially if you wrote it- about when to dispose and when to leave that to the GC.
About the Alt-Tab!! Nice catch!!
Extra Regards
|
|
|
|
|
Hello
If you were following the conversation I as having with mav.. There will be a slight change in the code for the sake of optimization
private bool DrawBox = false;
private void textBox1_MouseEnter(object sender, EventArgs e)
{
Drawbox = true;
}
private void textBox1_MouseLeave(object sender, EventArgs e)
{
Drawbox = false;
}
private void textBox1_Enter(object sender, EventArgs e)
{
Drawbox = true;
}
private void textBox1_Leave(object sender, EventArgs e)
{
Drawbox = false;
}
private void textBox1_Paint(object sender, EventArgs e)
{
Graphics g = textBox1.CreateGraphics();
if(DrawBox)
g.DrawRectangle(new Pen(Brushes.Red, 3), new Rectangle(0, 0, textBox1.Width - 5, textBox1.Height - 5));
else
g.DrawRectangle(new Pen(Brushes.White, 3), new Rectangle(0, 0, textBox1.Width - 5, textBox1.Height - 5));
g.Dispose();
}
i hope that work mav.. Thanks!
Regards
|
|
|
|
|
Formally, this could work (although you don't have to create a Graphics object - the Paint event has one in its event args - and your rectangles will not be centered), but unfortunately in real life it doesn't.
It's because the TextBox isn't signalling a Paint event to a caller out of the box and thus your rectangle isn't painted.
You could derive from TextBox and set some control styles (UserPaint, mainly), but altogether the effect is not worth the trouble IMO...
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
i want to add first column of datagrid as checkedbox against every row of datagrid. then from the list i will select some checkboxes according to need.how i will implement this thing plz tell me any simple way.
reply soon.
|
|
|
|
|
Can you elaborate?
As of how to accomplish this, have you ever tried Google?
|
|
|
|
|
yes i have tried all even i read many articales in codeproject also. they are very complex and webbased. i dont understand them i read one artical
http://www.codeproject.com/aspnet/ChkBoxInGrid.asp
i want to do the same thing but in windows form. i dont understand how to bind checkbox with datagrid.and i want to display checkboxe with every row of datagrid. so plz help me
|
|
|
|
|
To add a checkbox column just open the Column designer and add a column of type DataGridViewCheckBox .
If you want to perform the selecting and deselecting etc, why you can just use Control and Shift combinations to achieve the same thing. There should be a property called SelectedRows so you can enumerate them.
As of how to accomplish this, have you ever tried Google?
|
|
|
|
|
I'm working on a HTTP(S) proxy and I got the HTTP part working complete with authentication.
Only HTTPS keeps buggering me, how should I handle this?
Do I need to setup a connection and just relay the data between the client and the server?
Because if I do that, the user is unabe to request another URL afterwards, at least with HTTP 1.1 and internet explorer 6/7 that is.
For HTTP I made the relaying part work by intercepting each request from the client and handle it as if it were a request for the proxy. That works great, but I'm unsure about HTTPS...
Any ideas on how to get this part to work?
WM.
What about weapons of mass-construction?
|
|
|
|
|
I have a class library I wrote, which deals with sockets.
I raise events through this library, such as DataArrival (which gives me the problem btw).
This is a snippet from my receiveCallback function:
Buffer bf = (Buffer)result.AsyncState;
bf.QueuePacks();
if (OnDataArrival != null)
{
if (caller != null) caller.Invoke(OnDataArrival, bf);
else OnDataArrival(bf);
}
sck.BeginReceive(bf.Data, 0, bf.Data.Length, SocketFlags.None, new AsyncCallback(receiveCallBack), bf); Buffer is also a class I wrote, and caller is a reference to a form.
This code works most of the time.
I'm currently working on a new project which uses my class.
In this project, I sometimes get an "Parameter is invalid" exception, on this line:
caller.Invoke(OnDataArrival, bf); It works most of the time, and never happend in my previous projects.
Is it wrong to invoke an event?
What's wrong with my parameters?
|
|
|
|
|
shyagam wrote: Is it wrong to invoke an event?
What's wrong with my parameters?
Care to provide some more details?
As of how to accomplish this, have you ever tried Google?
|
|
|
|