|
string hostname=Dns.GetHostName();
IPHostEntry h=Dns.Resolve(hostname);
Console.WriteLine("IP addresses for "+hostname+":");
foreach (IPAddress ip in h.AddressList) {
Console.WriteLine(ip);
}
Also
http://www.codeproject.com/csharp/network.asp[^]
|
|
|
|
|
Is there a quick and easy way to get a bitmap from a control's Graphics object? I have a Panel object that I've drawn some stuff on, and I want to generate a bitmap from it. If that wasn't possible, I was also thinking of maybe drawing stuff onto a bitmap, but Bitmap objects don't have Graphics objects...
Any ideas or suggestions?
-Daniel
|
|
|
|
|
This may be of some use:
http://www.codeproject.com/csharp/imagecapture.asp[^]
Looking at the MSDN docs, it simply enough to get an Graphics object from an Image, but getting an Image from an existing Graphics object appears to harder. By the looks of it, it will involve handles/pointers and possibly using P/Invoke
-- modified at 19:58 Tuesday 25th April, 2006
|
|
|
|
|
|
The second alternative you are suggesting is the better one. You can get a Graphics for a bitmap this way:
Bitmap bitmap = new Bitmap(panel.Width, panel.Height);
using (Graphics g = Graphics.FromImage(bitmap)){
}
panel.DrawImageUnscaled(b, 0, 0);
bitmap.Save("C:\\test.bmp");
|
|
|
|
|
I felt kind of dumb after I found that method (Graphics.FromImage()). However, every time I try to save the bitmap, it gives me a sort of generic GDI+ error (but doesn't crash the program). I'll figure it out one of these days.
Basically, I'm trying to draw a lot of crap onto a Panel (on a tab page). The crap is dynamic (changes often during runtime, in different tab pages), and so it needs to be redrawn often. But I don't want it to redraw it all every time the Panel needs to be repainted (for some reason, it all disappears unless I tell it redraw all the crap, like with window resizing). I figured if I drew it once to a bmp (when needed), and then just set the bmp to the Panel's background image, it wouldn't flicker so bad with repainting (like with window resizing and stuff).
I'll figure it out eventually.
Thank you all for the help! I love this site!
-Daniel
|
|
|
|
|
That it needs to be repainted is just how windows works. You have to catch the Paint event (or override OnPaint) from the panel and draw your stuff there everytime it gets called. Using a back buffer is nevertheless a good idea.
|
|
|
|
|
Alrighty, thanks!
(I feel even dumber having forgot about OnPaint... blasted semester finals...)
-Daniel
|
|
|
|
|
I am a huge C# newb trying to learn how to write a simple program. I am having a problem copying a file to another directory.
Lets say i copy C:\test.exe to C:\copy\text.exe. The file copys to the right folder but it ends up with both files having 0 bytes.
any help would be appreciated
Private void button6_Click(object sender, EventArgs e)
{
string path = textbox1.text
string path = textbox2.text
try
{
using (FileStream fs = File.Create(path))
File.Delete(path2);
File.Copy(path, path2);
textbox3.text = "file is copied"
}
catch
{
textbox3.text = "error"
}
}
Don't be overcome by evil, but overcome evil with good
-- modified at 18:44 Tuesday 25th April, 2006
|
|
|
|
|
That's because you are overwriting the source file! Just delete these two lines, there are unnecessary:
using (FileStream fs = File.Create(path))
File.Delete(path2);
File.Copy is the only line you need to use within the try catch. If you want to allow overwrites of exsiting files you can add true as a third parameter.
Regards, Graham.
|
|
|
|
|
Thanks alot man i appreciate it alot. It works perfect.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Take a look at these two lines:
string path = textbox1.text<br />
string path = textbox2.text
You can't create two variables with the same name, so obviously this is not the code that you are actually using.
Assuming the rest of the code is at least reasonably similar to the one that you are using:
You create a new file but you are not writing anything to it. Of course the length of the file will be zero.
---
b { font-weight: normal; }
|
|
|
|
|
i accidently made a typo there. that wasn't what i had in my original code. It was path2 for textbox2.text.
thanks for you help tho
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
I have a DataGrid that uses a DataTable as its source of information to display and looks something like this:
Name Black_Car Brown_Car Red_Car
Ted 8 4 6
Jim 3 1 0
Bob 14 0 2
Total 25 5 8
Each Black_Car, Brown_Car, Red_Car, and Name column name is a link that sort the column in descending order when clicked. What I would like to do is add one more row at the bottom that say "Total" in the Name column and the sum for the other three columns. I was able to add the "Total" row with the sums, but whenever I click the column name link to resort, the "Total" row with the sums would be resorted also. I don't want the "Total" row to be resorted, I want it to always remain at the bottom of the table. I would really appreciate any help, thanks.
-- modified at 17:35 Tuesday 25th April, 2006
|
|
|
|
|
Hi,
the DataGrid doesn't have any inbuilt functionality to achieve what you want. But probably we can find a workaround. For this it is important to describe a bit more:
1. Should your grid be editable by the user?
2. Is the table filled via some sort of database connection or are you filling it manually?
|
|
|
|
|
The DataGrid is not editable by the user and the table is filled by reading in values from a text file.
|
|
|
|
|
I am new to dotnet developement so please excuse me if this has been answered before.
I need to change a textbox to a listbox or other type container at runtime based on user config options specified in a database.
The user will specify through another app the fields that they want activated, the type the field should be (check box, list box, date - calendar, number field etc). For list boxes, they will specify the list of values. They will also specify where on the container the item should be placed. All these specifications will be in a datagrid that I need to loop through at runtime and place the items in the appropriate container at the specified location and set up the display attributes (list box, check box etc)
Any help\ideas will be appreciated
|
|
|
|
|
To add controls dynamically, just call their constructor, set their properties, such as position, and add them to the Controls collection on the form. You can't *change* the type of a control, you need to either put all the controls you may need on the form, and show/hide them with the Visible property, or create them dynamically. They won't be member variables then, you'd need to search for them in the controls collection to do anything with them, or put them in a container of your own.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for the reply! I understand.
I want to be able to add the item to a specific page on a tabconrol. I assume I will have to use the parent method? But I am not sure how to do that?
TextBox mytext = new TextBox();
mytext.Name = myrow["FIELD_NAME"].ToString();
mytext.Parent = this.tabControl1. ??????
|
|
|
|
|
No, it's this.tabControl1.Controls.Add(mytext);
You still need to set the position and size of the control, at a minimum. I believe the Visible property defaults to true, but it's worth making sure.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi there!
Is it possible to retieve user nt name from the web request? This question
arose while thinking about authentication system implementation in the
asp.net.
my code --- string UserID = User.Identity.Name;
which returns Domainname\Userid
I want to make authentication process transparent for the user. E.g. if the
user is logged on the domain or is a member of the domain then perform
authentication autimatically - as a result user won't experience any login
windows, otherwise web-app will provide the form similar the IIS one for
authentication.
Can this be done from the web application?
Thanks in Advance
Krishna
|
|
|
|
|
Have you turned on the Impersonation ?
http://www.routeservices.com
|
|
|
|
|
Hi,
I've made Indentity Impersonation = "true" in webconfig, still im getting windows authentication login window.
|
|
|
|
|
Hi all!
I need a way to get all the groups of the AD to list.
I get the code of Umar_hasan at: http://www.codeproject.com/csharp/adtester.asp, but is not working in a WebForm... Anybody knows how I can do this?
|
|
|
|
|
As you're using ASP.NET, you'll be listing active directory stuff on the server, not on the client. Your code runs on the server.
What do you mean by 'not working' ?
Christian Graus - Microsoft MVP - C++
|
|
|
|