|
File|Add|New
Expand "Other Project Types"
Select "Setup and Deployment"
Select "Setup Project"
Give it a name, click OK
|
|
|
|
|
I tried this:
<br />
System.IO.DriveInfo[] allDrives = DriveInfo.GetDrives();<br />
<br />
foreach (DriveInfo d in allDrives)<br />
{<br />
if (d.IsReady == true & d.DriveType == "Removable")<br />
{<br />
listBox1.Items.Add(d.Name);<br />
}<br />
}<br />
...and it did not work.
I'm getting a headache. How do I accomplish what I'm trying to do?
|
|
|
|
|
What type of error did you receive? Your if statement is incorrect. Your if statement should contain && not &. This may be a typo but add another & and see what happens.
Nathan
|
|
|
|
|
Try replacing d.DriveType == "Removable" with d.DriveType == System.IO.DriveType.Removable .
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Thanks a bunch, guys. The world's easiest way to list all USB drives on the system...This worked:
System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo d in allDrives)
{
if (d.IsReady == true && d.DriveType == System.IO.DriveType.Removable)
{
listBox1.Items.Add(d.Name);
}
}
Ok. Now that we have that worked out. Let me say this: I have this code in "form1.designer.cs", which I know is incorrect. How do I get it where it belongs (in form1.cs) and have it work right? I put it in there previously, and it didn't work.
|
|
|
|
|
simplicitylabs wrote: I put it in there previously, and it didn't work.
It works fine for me. Was there an error message?
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Oh, it compiles and runs nicely. However, because I have it in form1.designer.cs, which is automatically generated by the designer, and not form1.cs, I get a warning and cannot view the form in design mode:
-------The warning-------
The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.
-------------------------
I'm using Visual Studio 2005.
|
|
|
|
|
I got it. Thank you for your help, everyone. I'm sure I'll be back with more questions soon.
|
|
|
|
|
Have a look at:
http://icsharpcode.net/OpenSource/SharpUSBLib/default.aspx
|
|
|
|
|
hi
i don't know how to show relationalData in treeView, how to ?
plz give an example.
thanks
|
|
|
|
|
|
Here's an example I just whipped up. The constructor populates a DataSet with some hierarchical data, and the Form.Load populates a TreeView with it.
There are many other ways this same data could be displayed in the TreeView, which is why there's no "automatic" way. You need to decide how you want your tree to look (this is one of the reasons I use a TreeView much more frequently than a DataGridView).
namespace PlayGround
{
public partial class Form1 : System.Windows.Forms.Form
{
private enum Gender { Male , Female } ;
private System.Data.DataSet ds = new System.Data.DataSet() ;
public Form1 ( string[] args )
{
InitializeComponent() ;
System.Data.DataRow dr ;
ds.Tables.Add ( new System.Data.DataTable ( "PetType" ) ) ;
ds.Tables.Add ( new System.Data.DataTable ( "Person" ) ) ;
ds.Tables.Add ( new System.Data.DataTable ( "Pet" ) ) ;
ds.Tables [ "PetType" ].Columns.Add ( new System.Data.DataColumn ( "Id" , typeof(int) ) ) ;
ds.Tables [ "PetType" ].Columns.Add ( new System.Data.DataColumn ( "Type" , typeof(string) ) ) ;
ds.Tables [ "PetType" ].Columns.Add ( new System.Data.DataColumn ( "DisplayColor" , typeof(string) ) ) ;
ds.Tables [ "Person" ].Columns.Add ( new System.Data.DataColumn ( "Id" , typeof(int) ) ) ;
ds.Tables [ "Person" ].Columns.Add ( new System.Data.DataColumn ( "Name" , typeof(string) ) ) ;
ds.Tables [ "Person" ].Columns.Add ( new System.Data.DataColumn ( "Gender" , typeof(string) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Id" , typeof(int) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "PetType" , typeof(int) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Owner" , typeof(int) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Name" , typeof(string) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Gender" , typeof(string) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Age" , typeof(int) ) ) ;
ds.Relations.Add ( new System.Data.DataRelation ( "TypeOfPet" , ds.Tables [ "PetType" ].Columns [ "Id" ] , ds.Tables [ "Pet" ].Columns [ "PetType" ] ) ) ;
ds.Relations.Add ( new System.Data.DataRelation ( "OwnerOfPet" , ds.Tables [ "Person" ].Columns [ "Id" ] , ds.Tables [ "Pet" ].Columns [ "Owner" ] ) ) ;
dr = ds.Tables [ "PetType" ].NewRow() ;
dr [ "Id" ] = 0 ;
dr [ "Type" ] = "Dog" ;
dr [ "DisplayColor" ] = "Green" ;
ds.Tables [ "PetType" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "PetType" ].NewRow() ;
dr [ "Id" ] = 1 ;
dr [ "Type" ] = "Cat" ;
dr [ "DisplayColor" ] = "Blue" ;
ds.Tables [ "PetType" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Person" ].NewRow() ;
dr [ "Id" ] = 0 ;
dr [ "Name" ] = "Joe" ;
dr [ "Gender" ] = Gender.Male ;
ds.Tables [ "Person" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Person" ].NewRow() ;
dr [ "Id" ] = 1 ;
dr [ "Name" ] = "Mary" ;
dr [ "Gender" ] = Gender.Female ;
ds.Tables [ "Person" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 0 ;
dr [ "PetType" ] = 0 ;
dr [ "Owner" ] = 0 ;
dr [ "Name" ] = "Spot" ;
dr [ "Gender" ] = Gender.Male ;
dr [ "Age" ] = 2 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 1 ;
dr [ "PetType" ] = 0 ;
dr [ "Owner" ] = 0 ;
dr [ "Name" ] = "Rover" ;
dr [ "Gender" ] = Gender.Male ;
dr [ "Age" ] = 5 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 2 ;
dr [ "PetType" ] = 1 ;
dr [ "Owner" ] = 0 ;
dr [ "Name" ] = "Fluffy" ;
dr [ "Gender" ] = Gender.Female ;
dr [ "Age" ] = 3 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 3 ;
dr [ "PetType" ] = 1 ;
dr [ "Owner" ] = 1 ;
dr [ "Name" ] = "Gilligan" ;
dr [ "Gender" ] = Gender.Male ;
dr [ "Age" ] = 4 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 4 ;
dr [ "PetType" ] = 1 ;
dr [ "Owner" ] = 1 ;
dr [ "Name" ] = "Ginger" ;
dr [ "Gender" ] = Gender.Female ;
dr [ "Age" ] = 4 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
return ;
}
private void Form1_Load ( object sender , System.EventArgs e )
{
System.Windows.Forms.TreeNode person ;
System.Windows.Forms.TreeNode pettype ;
System.Windows.Forms.TreeNode pet ;
foreach ( System.Data.DataRow personrow in ds.Tables [ "Person" ].Rows )
{
person = new System.Windows.Forms.TreeNode ( string.Format ( "{0} {1} ({2})" , (int) personrow [ "Id" ] , (string) personrow [ "Name" ] , personrow [ "Gender" ] .ToString() ) ) ;
person.Tag = personrow ;
foreach ( System.Data.DataRow pettyperow in ds.Tables [ "PetType" ].Rows )
{
pettype = new System.Windows.Forms.TreeNode ( (string) pettyperow [ "Type" ] + "s" ) ;
pettype.Tag = pettyperow ;
pettype.ForeColor = System.Drawing.Color.FromName ( (string) pettyperow [ "DisplayColor" ] ) ;
ds.Tables [ "Pet" ].DefaultView.RowFilter = string.Format ( "Owner={0} and PetType={1}" , personrow [ "Id" ] , pettyperow [ "Id" ] ) ;
foreach ( System.Data.DataRowView petrow in ds.Tables [ "Pet" ].DefaultView )
{
pet = new System.Windows.Forms.TreeNode ( string.Format ( "{0} {1} {2} year old {3}" , (int) petrow [ "Id" ] , (string) petrow [ "Name" ] , (int) petrow [ "Age" ] , petrow [ "Gender" ] .ToString() ) ) ;
pet.Tag = petrow ;
pet.ForeColor = pettype.ForeColor ;
pettype.Nodes.Add ( pet ) ;
}
person.Nodes.Add ( pettype ) ;
}
treeView1.Nodes.Add ( person ) ;
}
}
}
}
|
|
|
|
|
Hi friends!
I have some problems with GUI in C#.Net ,Can anybody solve these?
First ,How can I save the image from the PictureBox to the Harddrive…. Is it wrong method or not for save the any image ? like as
//Save file
private void savebt_Click(object sender, System.EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
filename =saveFileDialog1.FileName;
Stream filestream =File.OpenWrite(filename);
using(StreamWriter fwriter= new StreamWriter(filestream))
{ fwriter.Write(PictureBox.Image);}
}
}
Second , I use the following codes for drawing into the pictureBox2 by Pen
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
if (e.Button == MouseButtons.Left)
{ g.DrawEllipse(p, e.X, e.Y, 5, 7); }
}
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
if (e.Button == MouseButtons.Left)
{ g.DrawEllipse(p, e.X, e.Y, 5, 7); }
}
But there is a problem when I RUN the program and start the drawing if when I move the mouse fastly then such drawing break into small ellipse,I think you have understand
Third , I use follwing codes to draw the line into the pictureBox2 :
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{ Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
g.DrawEllipse(p, e.X, e.Y, 2, 2);
mx = e.X;
my = e.Y;
}
private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
g.DrawLine(p, mx, my, e.X, e.Y);
}
But I confuse for that
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
???????????????????????????????
}
I want when I move the mouse arrow onto the pictureBox2 ,then the line move with respect to the mouse and not draw untill UP the mouse button.
I am waiting for your kindly response
Thanks
|
|
|
|
|
Hi,
1.
to save an image, use Image.Save()
2.
dont draw in MouseDown or any other non-paint event handler;
all drawing should be done in the paint handler.
Hence, use data structures to describe your drawing, modify the data as you
like (e.g. in OnMouseDown), but draw it in OnPaint().
There are many benefits now:
- the drawing gets redrawn when necessary (e.g. on Resize, restore from
minimized, etc)
- the drawing can be saved by saving the data structures
- better code structure.
|
|
|
|
|
Hi,
My first problem ...50% solved ,i used your hint like as
[Code]
private void button10_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox2.Image.Save(saveFileDialog1.FileName);
}
}[/code]
But i amazed when i save the image from pictureBox2 (after draw the some lines onto the pictureBox2).......when i opened the saved picture then.........there is no editing means image still unchanged !!!!!!!!!
I want that i open the any image in my c#program ,edit the such image(draw some lines etc on the image)and then save such image but with changing............................
OnPaint()???? How i can use this? Can you give a example?
how can i replace the "pictureBox2_MouseDown" with
Onpaint() handler?
[code]private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
if (e.Button == MouseButtons.Left)
{ g.DrawEllipse(p, e.X, e.Y, 5, 7); }
}
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
if (e.Button == MouseButtons.Left)
{ g.DrawEllipse(p, e.X, e.Y, 5, 7); }
}[/code]
Thanks !
|
|
|
|
|
Hi all;
I have a windows desktop application in which I have set as a background image, a graphic that I whipped up. Its nothing fancey, just some gradient colors, shadows, glow, that sort of stuff. I have tried different formats, jpg, png, gif, bmp, and with every one, when the application starts, and when I focus to a different window, then come back to the main one, it seems to redraw the screen slowly. Each control will flash on the screen, total time is maybe 1.5 - 2 seconds as all the controls flash. If I put regular system colors back in, there is no issue. Is there anything I can do to speed this up? the graphic files are not that big, 9 KB for the jpb image, 6 for the GIF. The BMP is large, but it doesnt seem to make a difference which one I use, the results are the same.
Thanks
I should note that the backgrounds are set on group boxes, and a few on some buttons.
|
|
|
|
|
I'm looking for the best way to scan (go through) all the files on the computer (for search purposes etc.). i tried some ways but there's certain problems i couldn't find a solution to, such as a "no access" exception when it gets to the "system volume information" dir.
so...what's the best way to do it?
|
|
|
|
|
You can't get access to the System Volumn Information folder anyway. It belongs to the system and only the SYSTEM has any rights to what's in there.
Strangely enough, you're saying that you can't get into this folder when you try to build an index of all the data and files on the drive, but yet, that's exactly what's in that folder. The Indexing Service already does this for you and stores it's index information in that folder.
You might want to get a little primer by reading Heath Stewerts article on it here[^]. There's a link in the article to the documentation on MSDN. I highly suggest following it.
|
|
|
|
|
uhh..that's ASP.NET
and i didn't say i WANTED access to System volume information...it just lists that directory along with all the others and when it tries to access it, it raises an exception and terminates the whole operation =\
|
|
|
|
|
So catch the exception and skip that directory !
|
|
|
|
|
sharpiesharpie wrote: uhh..that's ASP.NET
uhh... the EXACT same techniques are used for every other file on the system, not just ASP.NET files. Next time, try reading the ENTIRE article and following the links in it.
sharpiesharpie wrote: and i didn't say i WANTED access to System volume information
I didn't say you did either.
sharpiesharpie wrote: it just lists that directory along with all the others and when it tries to access it, it raises an exception and terminates the whole operation =\
It terminates because your code isn't written properly to handle errors where your code can't go.
I told you, the Indexing Service already does this. All you have to do is apply the techniques found in that article and the MSDN documentation and you have a solution that's alomst pre-written.
|
|
|
|
|
I am trying to determine primary key in a table wher Table is fetched from sql server database, but following code is not returning me Primary Key.
private void GetPrimaryKeys(DataTable myTable)
{
DataColumn[] pkSource;
pkSource = myTable.PrimaryKey;
for (int i = 0; i < pkSource.Length; i++)
{
Console.Write(pkSource[0].ColumnName[i]);
}
}
|
|
|
|
|
Make sure that you mytable contains information about the existing table fetched from sql server
|
|
|
|
|
I have a decimal value that I need to evaluate in an IF statement however I'm getting an error that reads "Operator '>' cannot be applied to operands of type 'decimal' and 'double'". What am I doing wrong?
Here's my code:
------------------
decimal totalRecPct;
totalRecPct = Decimal.Divide(4,7);
if(totalRecPct > .10)
{
//perform process here
}
----------------
Thanks.
-Goalie35
|
|
|
|
|
you need to cast one value to the other type.
if(totalRecPct > Decimal(.10))
|
|
|
|
|