|
musefan wrote: string destDir = System.Environment.SpecialFolder.ApplicationData;//I guess this one is right
Actually, it's
string destDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
|
|
|
Hi,
I wanted to know how can I make a new object in a specific event,that can be public and visible to any other events in the same class?
I'll be thankful if anybody could guid me.
|
|
|
|
|
Do you mean an instance of an object? Or define an object such as a class? I am not sure what you mean - what are you trying to use it for?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I'm trying to use a MDI form.the cihld is a class,right?so whenever user trys to make a new child form (by pressing the new btn in the menustrip in the parent form),it makes it for the first time,but as soon as you close the child form and try to make a new one the error happens.that error is because I made the child object out of the event code block.the error says you have disposed an object (which is due to the object I made OUT OF EVENT) you can't use it any more.see,I know what's wrong but don't have the cure!here is a sample code block(in the parent form) :
new ChildTest myTest = new ChildTest()
public Form1()
{
InitializeComponent();
}
private void toolTest_Click(object sender, EventArgs e)
{
myTest.MdiParent = this;
myTest.Show();
}
private void toolBackColor_Click(object sender, EventArgs e)
{
myTest.BackColor = Color.Red;
}
|
|
|
|
|
pcsience wrote: //ChildTest myTest = new ChildTest();
Why you comment this line out, if you just make it a new instance, rather than a new declaration it should work...
myTest = new ChildTest();
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
hey man,
it did'nt do any good!!any more suggestions?see...I only need to define myTest in the toolTest_Click event in a way that toolBackColor_Click event can see it too.as you can see I wrote a code line in in comment type in toolTest_Click event,but that myTest is only visible in that event,not in the toolBackColor_Click.that's the main problem!!!
|
|
|
|
|
Firstly, what is this line supposed to do?
new ChildTest myTest = new ChildTest()
pcsience wrote: I know what's wrong
I don't think you do.
If you want the BackColor button to work for any MDIChild, you should not be referencing a specific form, rather you should be referencing the ActiveMDIChild property (testing it for null, of course).
Can I suggest that you study Creating MDI application using C# (Walkthrough)[^] from here on CP before continuing.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
ok,that line was wrongly typed here
new ChildTest myTest = new ChildTest() the correct one is
public ChildTest myTest = new ChildTest()
that's the point,once it has disposed an object (in this case the child form) it can't create another child form so that I can use ActiveMDIChild property!and I think that is because I created the child form object out of toolTest_Click event.when for the first time I run it,I can create a new child form but as soon as I close the child form and press the toolTest_Click the error occurs.which is in the
myTest.Show(); part.and it says Cannot access a disposed object. but if I just can make the object in the toolTest_Click event the error won't happen again,BUT other methods can't recognize it!
|
|
|
|
|
Closing the childform disposes it. The point of an MDI interface is that it allows you to have many child windows open, which is why I suggested using ActiveMDIChild.
If you want to use your toolTest_Click you must either test that ActiveMDIChild is not null and return if it is, or you must add myTest = new ChildTest() to the method. The problem with the last option, is that you will end up with lots of myTest forms open, just to test your methods. Alternatively don't close the first instance of ChildTest().
This is why I suggested that you read the article I gave the link for. Also the MDI Walkthroughs on MSDN are not bad, such as this one[^].
If you study either, or both of these, you will get a better understanding, because it is obvious that you are misunderstanding something about Windows Forms Programming in general and MDI in particular.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hey man,
just wanted to say thanks.it worked.you did help me find the way.
|
|
|
|
|
I'm building a very simple composite control and when use the designer to select a data source it crashes Visual Studio 2008.
Here is the code:
namespace WebControlDesigner {
[ToolboxData("<{0}:ControlWithTasks runat=\"server\"></{0}:ControlWithTasks>")]
public class ControlWithTasks : CompositeDataBoundControl {
public ControlWithTasks() : base() { }
[Category("Apearance")]
[DefaultValue("Your Birthday")]
public string Prompt {
get { return (string)ViewState["Prompt"] ?? "Your Birthday"; }
set { ViewState["Prompt"] = value; }
}
[Category("Data")]
[Bindable(true)]
public DateTime Birthday {
get { return (DateTime?)ViewState["Birthday"] ?? DateTime.Now; }
set { ViewState["Birthday"] = value; }
}
protected override int CreateChildControls(IEnumerable pDataSource, bool pBinding) {
base.CreateChildControls();
Label vLabel = new Label();
vLabel.Text = Prompt;
vLabel.ForeColor = Color.Red;
this.Controls.Add(vLabel);
Literal vLiteral = new Literal();
vLiteral.Text = ": ";
this.Controls.Add(vLiteral);
TextBox vTextBox = new TextBox();
vTextBox.ID = "TextBox1";
vTextBox.Text = Birthday.ToString();
this.Controls.Add(vTextBox);
return 0;
}
}
}
It's an extremely simple control, and builds without error.
Here is the page that consumes it:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="WebControlDesigner" Namespace="WebControlDesigner" TagPrefix="wcd" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<wcd:ControlWithTasks ID="ControlWithTasks1" runat="server">
</wcd:ControlWithTasks>
</div>
</form>
</body>
</html>
It renders perfectly and display the designer menu correctly but if I create a data source or try to select a existing one it crashes VS2008.
What is missing?
Please!! I need some help.
|
|
|
|
|
HI
I am confused about how i can use internet in C#.
every help would be appreciated.
thanx
kakarman
|
|
|
|
|
Well that depends what you what to use the internet for?
If you want to browse web pages and you are using C#.Net forms then there is a control called WebBrowser which has some properties and functions to allow web browsing, you could look into that
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
kakarman wrote: I am confused about how i can
kakarman wrote: every help would be appreciated.
Sure. See the way it works is, you find some materials designed to explain something and you study it. That typically means reading the material and thinking about it. This is what is sometimes called learning.
|
|
|
|
|
or fetching a page into a string like so[^].
|
|
|
|
|
Hi.....
I have combobox which gives table list.After selecting table from same then crystal report view must show table data.
I got problem with crystal report binding.I am using C#.net and in my code i m using "dataset1 Ds" which retrieve all values but cant show that data into crystalreport viewer.
kindly find my code below......
<pre>
private void cmb_type_SelectedIndexChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(cmb_type.SelectedIndex) == -1 && (Convert.ToString(cmb_type.SelectedValue) == "System.Data.DataRowView"))
{
return;
}
CrystalReport1 objRpt;
objRpt = new CrystalReport1();
String ConnStr = "Data Source=SHREE\\SQLEXPRESS;Initial Catalog=NandKumar;Integrated Security=True";
SqlConnection myConnection = new SqlConnection(ConnStr);
string Query1 = "Select * from " + cmb_type.Text ;
SqlDataAdapter adapter = new SqlDataAdapter(Query1, ConnStr);
DataSet1 Ds = new DataSet1();
adapter.Fill(Ds,"C"); // " + cmb_type.Text + "
if (Ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("No data Found", "Project Tracker Suite");
return;
}
// Upto this my code run- ok,i got problem from here...
objRpt.SetDataSource(Ds.Tables["C"].DefaultView);
CrystalDecisions.CrystalReports.Engine.TextObject root;
root = (CrystalDecisions.CrystalReports.Engine.TextObject)objRpt.ReportDefinition.ReportObjects["txtHeader"];
root.Text = "Sample Report With Parameter!!";
crystalReportViewer1.Visible = true;
crystalReportViewer1.ReportSource = objRpt;
}
}
|
|
|
|
|
hi friends
I want to know how to C# user interfaces invoke external tool kit like HTK 3.3 windows binary
please
|
|
|
|
|
Hi guys!
I'm writing a C# application that should use my cellphone's microphone as my pc microphone.
right now I'm using in the hand 32feet API to create the software but I'm not sure about in the hand's support for this one.
I'm looking for some example\ Explanation\ forum\ anything to start programming right(in C# - VERY IMPORTANT!).
just to mension - I've never did such thing and it's my first time programming for BT.
looking forward for your answers!
AMDO.
|
|
|
|
|
Ami Vaknin wrote: I've never did such thing and it's my first time programming for BT.
I've a feeling it could be your last too.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
yeah you must be right.
OK, now you can take your medicine.
good boy!....
go f*** yourself ya ben elef sharmutot.
|
|
|
|
|
When I drop an item into a ListView I get an out of memory exception... but... I have them on the same form.. within the same TabControl (different tabs though).
Basically I am saving the file... if the item is to be sent to M&R then I set the MR column (BIT) to True, and if not, then False. This way I can tell which ListView the item should show up in... But I get an error on the drag and dropping to the second listview (the M&R one)
private void listViewFiles_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
newFile = new OpenFileDialog();
newFile.FileName = file;
SaveFileThread(file, newFile.SafeFileName, false);
newFile.Dispose();
}
bwLoadFiles.RunWorkerAsync();
}
private void lstMRFiles_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
newFile = new OpenFileDialog();
newFile.FileName = file;
SaveFileThread(file, newFile.SafeFileName, true);
newFile.Dispose();
}
bwLoadFiles.RunWorkerAsync();
}
Here is what it is calling:
private void SaveFileThread(string Filename, string SafeFile, bool MR)
{
RegistryAccess reg = new RegistryAccess();
SqlConnection conn = new SqlConnection(reg.ReturnConnection);
SqlCommand cmd = new SqlCommand("SELECT * FROM Inventory_Files WHERE FilesID=@FilesID AND [Filename]=@Filename AND MR=@MR", conn);
try
{
cmd.Parameters.AddWithValue("@FilesID", txtTAG.Text);
cmd.Parameters.AddWithValue("@Filename", SafeFile);
cmd.Parameters.AddWithValue("@MR", MR);
conn.Open();
SqlDataReader myReader = cmd.ExecuteReader();
if (myReader.HasRows)
{
if (MR) Invoke(new FilesLabelDelegate(FilesLabel), new object[] { "Did not save. File already exist.", true });
else Invoke(new FilesLabelDelegate(FilesLabel), new object[] { "Did not save. File already exist.", false });
}
else
{
conn.Close();
FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read);
decimal Size = fs.Length;
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
fs.Close();
if (MR) Invoke(new FilesLabelDelegate(FilesLabel), new object[] { "Saving file.. Size: " + Math.Round((Size / 1024) / 1024, 2) + "MB", true });
else Invoke(new FilesLabelDelegate(FilesLabel), new object[] { "Saving file.. Size: " + Math.Round((Size / 1024) / 1024, 2) + "MB", false });
conn = new SqlConnection(reg.ReturnConnection);
cmd = new SqlCommand("INSERT INTO Inventory_Files (FilesID, Saved_File, Filename, File_Size, MR) VALUES (@FilesID, @File, @FileName, @Size, @MR)", conn);
cmd.Parameters.AddWithValue("@FilesID", txtTAG.Text);
cmd.Parameters.AddWithValue("@File", buffer);
cmd.Parameters.AddWithValue("@FileName", SafeFile);
cmd.Parameters.AddWithValue("@Size", Size);
cmd.Parameters.AddWithValue("@MR", MR);
conn.Open();
int Success = cmd.ExecuteNonQuery();
if (Success > 0)
{
if (MR) Invoke(new FilesLabelDelegate(FilesLabel), new object[] { "Saved file.", true });
else Invoke(new FilesLabelDelegate(FilesLabel), new object[] { "Saved file.", false });
}
}
}
catch (Exception ex) { new Errors(ex).ShowDialog(); }
finally { conn.Close(); }
}
|
|
|
|
|
I would suspect this line
Jacob Dixon wrote: byte[] buffer = new byte[fs.Length];
You're creating a (contiguous) byte array big enough to hold the contents of a file. Worse, you're doing it in parallel for multiple files. I can see how this can quickly blow up memory consumption.
Just to isolate the problem, does running SaveFileThread sequentially help?
|
|
|
|
|
ok so if I create the
byte[] buffer;
outside the try/catch/finally.. then in the try I can create the
buffer = new byte[fs.length];
then in the finally I can set:
byte[] = null;
IT only does one at a time.. waiting for this part to get done before moving to the next file..
I did get it working though.. I didn't set the ListView to AllowDrop... and since I had to entire form to AllowDrop to put an image into a picturebox it was capturing it there. Seems to be working fine now... but what i changed will help with memory since I'm setting it to null at the end?
|
|
|
|
|
Jacob Dixon wrote: but what i changed will help with memory since I'm setting it to null at the end?
No, it shouldn't make any difference. Even if you don't set it to null, the CLR and the GC know enough to figure out that the byte array has no references outside your method, and array will therefore get garbage collected.
If just one file gives you an OutOfMemoryException, you should try streaming the contents of the file i.e. loading smaller chunks repeatedly, rather than loading it in one big byte array. I don't know enough ADO.NET to figure out how to stream it to the database though.
|
|
|
|
|
Hi
I am currently working on a project that requires me to read excel files from an external application. I am using the ExcelReader library (Excel Reader[^])
This works fine for spreadsheets <10mb (Others have reported problems only from around 300mb. This might be due to my spreadsheets being heavily loaded with macros, but that is just a hunch).
So I need one of two things:
1. A different library, one that can open (large) workbooks, identify sheets and get specific cell values (in the correct format). Thats all
OR:
2. I need the ExcelReader library to be able to handle large files. (it is otherwise really handy, so if this can be done it would be great)
Here is a code snippet of the method where it bombs out
internal static Int32[] ReadArrayOfInt32(BinaryReader reader, int count)
{
Int32[] data = new Int32[count];
for (int i = 0; i < data.Length; i++)
{
data[i] = reader.ReadInt32(); //throws EndOfStream Exception
}
return data;
}
Anyone have any suggestions?
Thanks
|
|
|
|