|
|
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++
|
|
|
|
|
Hi, I have 3 Solutions programmed in C#.
The first one is an assembly, a dll, that is used by applications in the other two Solutions.
I'd like to know if there's a way to debug my applications and trace into the code of the dll without rearranging my Solutions (i.e. without moving my application projects into the first Solution).
Thanks!
|
|
|
|
|
Instead of referencing the dll from the other two solutions, add the project to the other two solutions also, and reference the project.
---
b { font-weight: normal; }
|
|
|
|
|
I have a C# windows app. It looks like:
public class FormA
{
private ScanFile_Click
{
bool bSuccess = FormB.DoProcess("C:\textfile.txt");
}
}
public class FormB
{
public FormB
{
InitializeComponent();
}
public static bool DoProcess(string sInputFile)
{
FormB frmLocate= new FormB();
frmLocate.Show(frmParent);
// I want the new thread to finish processing before it comes to the statement below
// so that I can return the correct value to FormA
if(frmLocate.SuccessParsing)
{
strFileDetails = frmLocate.FileDetailArray;
}
return frmLocate.SuccessParsing;
}
private void OnLoad()
{
ParseDelegate calcPi = new ParseDelegate(ParseFile);
calcPi.BeginInvoke(this.m_sInputFile, null, null); // calling a new thread
}
// Worker thread
private void ParseFile(string sInputFile)
{
/* Do some calculations here */
/* I need to periodically update GUI controls */
}
My application is more like the one described in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
except that i do not have a button to start the new thread but i have to start the worker thread on load (like shown in my previous comment) and the worker thread communicates with the GUI thread (main thread) (in the ParseFile method ). After the worker thread finishes its work the DoProcess method must exit returning the result.
How should i proceed? Or Is there a better way of doing this?
|
|
|
|