|
You can use this code at your own risk. I wrote it without being really awake.
using (SaveFileDialog saveDialog = new SaveFileDialog())
{
saveDialog.AddExtension = true;
saveDialog.FileName = "Checkers Game";
saveDialog.InitialDirectory = @"C:\Documents and Settings\Bar\My Documents\";
saveDialog.OverwritePrompt = true;
saveDialog.Title = "Save game";
saveDialog.ValidateNames = true;
if (saveDialog.ShowDialog() == DialogResult.OK)
{
File.Copy(@"C:\Documents and Settings\Bar\My Documents\savegame.txt", saveDialog.FileName, true);
}
}
|
|
|
|
|
Code looks good, however spoon feeding is bad.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:39 AM
|
|
|
|
|
The FileDilaog classes only allow the user to select a path, they don't actually do anything with files.
An easy way to actually write or open a file is using the Filename property of the OpenFileDialog and SaveFileDialog and save that in a string variable.
Then you use File.ReadAllText() method to read a file and File.WriteAllText() method to write the text to a file.
These work even without giving the user a possibility to specify the location or name of the file.
Both methods have a string parameter called path , that's where you can put the path you just got from the FileDialogs (or a fixed path).
modified on Thursday, February 26, 2009 8:11 AM
|
|
|
|
|
Hello new member here on The Code Project but I have used the site many times to find answers for my programing questions but so far have had no luck finding an answer for my current issue.
As the title very simply says I have a program that contains alot of RTF fields (20+) all of which are placed right next to each other vertically. Everything appears correctly except that between a couple of the RTF fields there is a gap (maybe 1px tall) were two of them meet running the length of the field.
Although this is a minor issue it is one that I must solve.
Any help would be greatly appreciated. If more information is needed please feel free to ask and thank you in advance.
|
|
|
|
|
You're placing them on a form using code, or..? You should be able to just re size the fields left of the gap or set the location of the fields on the right side 1 pixel to the left.
I don't know anything about using RTF fields in C#, so maybe I'm way off in my understanding?
|
|
|
|
|
Thank you for the reply, the RTF fields are placed on the form using the designer. We have tried to shift them 1 pixel at a time but find then that they overlap by 1 pixel! In designer mode they ARE next to each other.
I understand that RTF fields are not used very often anymore (I'm actually not the programmer but I know enough to tell our programmer may have a few screws loose) but any ideas would still be appreciated.
|
|
|
|
|
|
I am creating a Cache Manager that will call a GetCacheItem method to get either a DataTable in cache or if the DataTable is not in cache the GetCacheItem method will make the SQL database call and then put the returned DataTable into cache. The parameters I want to pass to the GetCacheItem method are the cache item key and a delegate of type Func<tresult> with a delegate name of QueryExpression. The problem is that I want the Func<t> QueryExpression delegate to be used by several SQL select statments each with a different number of query parameters. How can I implement the Func<t> delegate to be able to take a different number of parameters each time it is called? Below is an example of what I have so far:
public object GetCacheItem(String sCacheKey, Func<object> QueryExpression)
{
object objCacheItem = null;
if (!CachingEnabled)
{
return objCacheItem;
}
if (CacheItem<object>(sCacheKey) != null)
{
return CacheItem<object>(sCacheKey);
}
else
{
lock (syncObject)
{
if (CacheItem<object>(sCacheKey) != null)
{
return CacheItem<object>(sCacheKey);
}
else
{
Object cacheItem = QueryExpression();
AddToCache<object>(sCacheKey, cacheItem);
return cacheItem;
}
}
}
}
</object></object></object></object></object></object>
NOTE: As you can see my Func<t> delegate only has a return argument and not the list of variable parameters. What do I need to do?
Thanks,
Steve
|
|
|
|
|
NOTE:
I used a dictionary to do this in calls before. The problem is that my boss wants to be able to make SQL calls like the following:
DAC_MANAGER.GetCustomers(string sName, string sAge)
and
DAC_MANAGER.GetEmployees(string id, string position, string payRate)
I talked to him about using dictionaries and he does not want to because this would mean changing every method in the DAC layer to use a dictionary.
|
|
|
|
|
helo... i have a client application which has a tcp listener on port 1000 and a server which connects to the same port.but the server should connect first to the client so when i try to connect Exception occurs like client not accepting the connection.
the cliet is listening in the netstat -an on the port 1000 and in the server when i send then the connection to the client is SYN_SENT and not established... will the windows firewall block these connections ..?
|
|
|
|
|
Yes.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
and if the client connects to the server first then will the firewall block the incomming connecton to the client ?
|
|
|
|
|
|
Hi I have a problem i hgaave a table in data grid view and i am updating data from data using a button. what i need to do is once the user update the data and click on update button i want to convert all string values to lower case. i am not using data table to populate my grid and i am updating using stored procedure. so i dnt know how to convert changed values to Lowercase before updating. can any one help me please.
Thanks
|
|
|
|
|
Hi I have a problem i hgaave a table in data grid view and i am updating data from data using a button. what i need to do is once the user update the data and click on update button i want to convert all string values to lower case. i am not using data table to populate my grid, is their any way that i can do that here is my code i am using to upgrade my grid
private void cmd_update_record_Click(object sender, EventArgs e)
{
if (dgRepair.RowCount == 0)
{
MessageBox.Show("No data available for update");
}
else
{
DataSet ChangedRepDataSet = new DataSet();
ChangedRepDataSet = ds_rep.GetChanges();
if (ChangedRepDataSet != null)
{
// Intializing object of Connectionclass to open connection
conn_obj = new ConnectionClass();
store_connection = conn_obj.connect();
// Sqlcommand object
SqlCommand cmdupdate;
cmdupdate = new SqlCommand();
cmdupdate.CommandType = CommandType.StoredProcedure;
cmdupdate.CommandText = "Update_Status_Grid";
//opening connection
cmdupdate.Connection = store_connection;
store_connection.Open();
//Adding Parameters for Repair table
cmdupdate.Parameters.Add("@OrgDescription", SqlDbType.VarChar, 100, "Description");
cmdupdate.Parameters["@OrgDescription"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@Description", SqlDbType.VarChar, 100, "Description");
cmdupdate.Parameters.Add("@OrgStatus", SqlDbType.VarChar, 15, "Status");
cmdupdate.Parameters["@OrgStatus"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@Status", SqlDbType.VarChar, 15, "Status");
cmdupdate.Parameters.Add("@OrgPartDes", SqlDbType.VarChar, 50, "PartDes");
cmdupdate.Parameters["@OrgPartDes"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@PartDes", SqlDbType.VarChar, 50, "PartDes");
cmdupdate.Parameters.Add("@OrgRepAction", SqlDbType.VarChar, 50, "RepAction");
cmdupdate.Parameters["@OrgRepAction"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@RepAction", SqlDbType.VarChar, 50, "RepAction");
cmdupdate.Parameters.Add("@OrgId", SqlDbType.BigInt ,1000, "Id");
cmdupdate.Parameters["@OrgId"].SourceVersion = DataRowVersion.Original;
//Adding the Parameters for invoice table
cmdupdate.Parameters.Add("@OrgRepCost", SqlDbType.Money, 1000, "RepCost");
cmdupdate.Parameters["@OrgRepCost"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@RepCost", SqlDbType.Money, 1000, "RepCost");
cmdupdate.Parameters.Add("@OrgPaymentPaid", SqlDbType.Money, 1000, "PaymentPaid");
cmdupdate.Parameters["@OrgPaymentPaid"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@PaymentPaid", SqlDbType.Money, 1000, "PaymentPaid");
da_rep.UpdateCommand = cmdupdate;
if (check == true)
{
try
{
da_rep.Update(ds_rep, "Repair");
ds_rep.AcceptChanges();
}
catch (Exception ex)
{
MessageBox.Show("Their is some problem in updating make sure you are entering right values " +
ex);
}
}
//}
//}
}
else
{
MessageBox.Show("no changes made");
}
//int modifiedRows = da_cus.Update(myChangedDataset);
//MessageBox.Show("Database has been updated successfully:" + no_of_rows_chang + " rows has been changed");
}
can any one help me
Thanks
|
|
|
|
|
First can you please use "CODE Block" tag from now-onwards, for your code. its really hard to read the code without that. If I understand correctly then,
Insterad of
cmdupdate.Parameters["@OrgStatus"].SourceVersion = DataRowVersion.Original;
You can use
cmdupdate.Parameters["@OrgStatus"].SourceVersion = DataRowVersion.Original.ToString().ToLower();
Whenever you are storing string values just use .ToString().ToLower() .
|
|
|
|
|
Thanks for the quick replay and thanks for the advice i will keep it in mind for next time. I tried what you suggest me but it is giving me error that can not convert from row version to string and also i am not using it pass parameter value.
I show you what i am trying
// passing value to the parameter
Parameter Type Column Name
cmdupdate.Parameters.Add("@OrgStatus", SqlDbType.VarChar, 15, "Status").ToString().
ToLower()
it does update the data base but do not convert the value into lower case.
|
|
|
|
|
I believe this can be done in numerous ways. One could be that you use ToLower-method on strings when you set the parameter values.
alwaysgull wrote: i am not using data table to populate my grid
But you seem to get the data to update from a dataset. Another option could be to either modify the data in the dataset or use computed columns. However, I didn't quite figure out why you use DataRowVersion.Original everywhere. Won't that lead to a situation where you update the same values back to the database.
|
|
|
|
|
|
If I remember correctly desktop.ini can help help.
|
|
|
|
|
Hi,
I have a TableLayoutPanel that has a couple of cells I filled with buttons, I can see there's a cell property for each button in that panel that I cant access from code, can you say, change it to change its location within the table??
Thanks guys!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
I am not sure about that but,
To change the location of your controls, you can use TableLayoutPanel.SetRow() And TableLayoutPanel.SetColumn() Method. Just pass your control and change the Row / Column.
|
|
|
|
|
I'm designing a small vector graphics app. Right now I'm writing code for painting a shape as it's being moved. For move operations, the shape is painted to a bitmap buffer so refreshes can be more effecient. Everything is working fine except when the drawing surface is scaled (zoomed).
The scaling factor is applied to the Graphics object when a paint message is called. That scaling factor is also used to generate a scaled "move bitmap" for the shape. For example, if the physical size of the shape is: 100 x 100 and the scaling factor is 50% then the move bitmap will be 50 x 50. The bitmap is then drawn as unscaled.
The problem is that the DrawImageUnscaled() method is not working! I get the same scaled results as if I were calling the DrawImage() method. This is rendering the scaled "move bitmap" to an additionaly scaled size!
Has anyone experienced this before?
//Code sample
private void initMoveBitmap()
{
//if the scaling factor is .50 the GetScaledBounds will produce a 50x50 on a 100x100 size
Rectangle r = shape.GetScaledBounds();
bmpMove = new Bitmap(r.Width, r.Height);
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmpMove);
gr.TranslateTransform(-r.X, -r.Y);
gr.ScaleTransform(scale, scale);
paint_move_bitmap(gr);
gr.Dispose();
gr = null;
}
public void PaintShape(Graphics g)
{
//scenario: the graphics object has a scaling factor of .50
if (bmpMove != null)
//produces no difference from the DrawImage() method
graphics.DrawImageUnscaled(bmpMove, pntBmpPos);
else
//paint the shape.. (code excluded)
}
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
Hi Richard,
let me say for starters I never used DrawImageUnscaled; however this is how I understand the Graphics class: there are two different reasons why DrawImage may scale an image:
1. the transformation stuff (properties and methods relating to Matrix and ScaleTransform);
2. the parameters specifying a destination rectangle, and either the entire source image or a specified rectangular part of it.
AFAIK DrawImageUnscaled removes the second reason by ignoring the width and height if you specify one,
but I don't expect it to ignore the first reason. I expect the ScaleTransform/Matrix to rescale everything, like a Xerox copier could, supporting things such as putting several pages of a document on a single sheet of print.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:39 AM
|
|
|
|
|
Hi everyone,
Any idea why might the key_down_even of a form may be inactive?? I'm running a simple form with a tabControl and even when I set the focus back to the form, it doesnt capture the key strokes while it works fine on an empty form!
Please help
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|