|
Mycroft Holmes wrote: I presume I should dispose each event on each control when leaving the form!
If the Form will be Closed (i.e. Disposed) then it is not necessary.
Where I have used this method is for dynamically created controls, such as described by the OP. Where these controls are disposed but their parent control/form is still live, I detach the event handler.
I think the reasoning is that there will still be a reference to the disposed control, although convoluted, via the events mechanism. This will prevent it being Garbage Collected.
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.”
|
|
|
|
|
Im just not able to get this going, so hopefully you can help. The error I am getting is Method Name expected on "dataGridTicketInformation, new CustomRowEventArgs(dataGridTicketInformation"
I first specify the CustomRowEventArgs and the DoubleClick function
public class CustomRowEventArgs : EventArgs
{
DataGridView grid;
public DataGridView Grid
{
get { return grid; }
}
public CustomRowEventArgs(DataGridView dgv)
{
grid = dgv;
}
}
private void dataGridTicketInformation_DoubleClick(object sender, CustomRowEventArgs e)
{
MessageBox.Show("DoubleClick Sent");
}
Then after I dynamically build and load all the information into the datagrid I call the doubleclick function
dataGridTicketInformation.DoubleClick += new System.EventHandler(dataGridTicketInformation, new CustomRowEventArgs(dataGridTicketInformation));
|
|
|
|
|
OK.
This line:
dataGridTicketInformation.DoubleClick += new System.EventHandler(dataGridTicketInformation, new CustomRowEventArgs(dataGridTicketInformation));
should be:
dataGridTicketInformation.DoubleClick += new System.EventHandler(dataGridTicketInformation);
***** See below for where to put it
and it is not used to call the doubleclick function it is used to link each DataGridView with the dataGridTicketInformation_DoubleClick method you have written, so that when you doubleclick on any of your grids you will get your "DoubleClick Sent" messageBox. It should be part of the creation of each DataGridView the line should go
DataGridView dataGridTicketInformation = new System.Windows.Forms.DataGridView();
dataGridTicketInformation.Name = "dataGridView" + tabIndex.ToString();
dataGridTicketInformation.Size = new System.Drawing.Size(401, 201);
dataGridTicketInformation.Columns.Clear();
dataGridTicketInformation.Columns.Add("Name", "Name");
dataGridTicketInformation.Columns[0].Width = 301;
dataGridTicketInformation.Columns.Add("Data", "Data");
dataGridTicketInformation.Columns[1].Width = 100;
dataGridTicketInformation.Rows.Clear();
dataGridTicketInformation.DoubleClick += new System.EventHandler(dataGridTicketInformation);
Unless there is a need to pass some special data on double click the CustomRowEventArgs is not needed. Even if this need exists, I would concentrate on getting the plain old doubleclick functionality working first, so that you can get an understanding of how it works.
Make a separate post if you need help in implementing a CustomRowEventArgs.
Assuming that you do this, all that needs to happen for the doubleclick action to be triggered is for you to double-click any of the dataGridTicketInformation instances that your app creates at run-time.
When you get it working with your messageBox version of dataGridTicketInformation_DoubleClick , it is important that you use the
DataGridView dgv = (DataGridView)sender;
method I showed earlier, otherwise you will not be able to tell which dataGridTicketInformation made the call.
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.”
|
|
|
|
|
If I add that code I get a error on the EventHandler ('dataGridTicketInformation' is a 'variable' but is used like a 'method'). Any ideas?
dataGridTicketInformation.DoubleClick += new System.EventHandler(dataGridTicketInformation);
|
|
|
|
|
Sorry! My bad, over-eager with the cut and paste.
Should be
dataGridTicketInformation.DoubleClick += new System.EventHandler(dataGridTicketInformation_DoubleClick);
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.”
|
|
|
|
|
Hi.
How can we write a program for a Core 2 due CPU ?
I mean, a program that divides the process between cores !
Thanks
|
|
|
|
|
|
You can use multi-threading, but realize that the OS itself and the internal operations of .NET are already doing that. Also be aware that multi-threading for the sake of multi-threading may add complexity for no reason and cause your program to actually run slower.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I want to add numbers from 1 to 12 to clock..i got positions for lines..but i don't know how to add numbers using same positions as for lines..help plz!?
Thanks
|
|
|
|
|
I strongly recommend you sketch it out on a piece of paper. From there you should be able to work out a way of calculating the co-ordinates you need to draw the text at. A useful function (assuming you're using a Graphics class to draw) is Graphics.MeasureString , which will help you line things up properly. The rest will be a bit of trial and error.
|
|
|
|
|
so there is not such function that would add text to form with x and y coordinates?
|
|
|
|
|
Hi,
you can paint lines, rectangles, ovals, images and text strings using the Graphics class inside a Paint handler.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
It is excellent to try to work this out for yourself, but there are sooooooo many examples of Analogue Clock out on the web that you should really Google for any problems. If memory serves there is even an example on MSDN.
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.”
|
|
|
|
|
Hi,
I'm using C#.net 3.0 to develop an application on digital watermarking.I'm using FrameGrabber class which I have found on this site.What the class is doing-it is getting the constituent frames in the Bitmap format (*.bmp) from the given video file.Now the problem is that there is no way to stop the function in the middle of execution i.e. if I want to stop the function from extracting further more frames I have to shutdown the application.Now I want to put a function on Button(STOP) such that when I press the button it will stop the function from further execution and all the frames so far extracted should remain in the destined folder.Can anybody please tell me how to do this.
This is the code for Button- Extact frames
[code]
private void button43_Click(object sender, EventArgs e)//to extract frame
{
string outPath = txtExtBitmap.Text;//path of destination folder where the extracted frames are kept
System.IO.Directory.CreateDirectory(outPath);
if (fg != null)
{
foreach (FrameGrabber.Frame f in fg)
{
using (f)
{
picBoxFrame.Image = (Bitmap)f.Image.Clone();
f.Image.Save(System.IO.Path.Combine(outPath, "frame" + f.FrameIndex + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);//save each frame in *.bmp format
Application.DoEvents();
}
if (fg == null)
{
return;
}
}
}
[/code]
Thank You!!
|
|
|
|
|
You're going to have to move the code that iterates through each frame to a background thread (look into the BackgroundWorker component) and modify the loop so that it checks a flag to know that it has to stop.
Get rid of the Application.DoEvents call when you move the code to the background thread. Like using "Goto" in your code, it's the second reason why a kitten gets punched in the face every time it's used.
|
|
|
|
|
Dave Kreskowiak wrote: a kitten gets punched in the face
I wanna see that!
|
|
|
|
|
PIEBALDconsult wrote: I wanna see that!
As Dave said, use either Application.DoEvents or goto
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Got something against kittens??
|
|
|
|
|
Hi,
Thanks for your reply
I used this code but it is still showing error highlighting fThread.Interrupt() ---Object reference not set to an instance of an object.Now what changes should I do in order to make this code work
[code]
private void frameExtract()//function to extract frames
{
string outPath = txtExtBitmap.Text;
System.IO.Directory.CreateDirectory(outPath);
if (fg != null)
{
foreach (FrameGrabber.Frame f in fg)
{
using (f)
{
picBoxFrame.Image = (Bitmap)f.Image.Clone();
f.Image.Save(System.IO.Path.Combine(outPath, "frame" + f.FrameIndex + ".bmp"), System.Drawing.Imaging.ImageFormat.Bmp);
Application.DoEvents();
}
if (fg == null)
{
return;
}
}
}
}
public void ThreadProc()
{
try
{
MethodInvoker mi = new MethodInvoker(this.frameExtract);
this.BeginInvoke(mi);
}
catch (ThreadInterruptedException e)
{
Console.WriteLine("Interruption",e);
}
catch (Exception we)
{
Console.WriteLine("Exceptiom",we);
}
}
private void button43_Click(object sender, EventArgs e)//Extract button
{
fThread = new Thread(new ThreadStart(ThreadProc));
fThread.IsBackground = true;
fThread.Start();
}
private void button44_Click(object sender, EventArgs e)//Stop Button
{
fThread.Interrupt();
fThread = null;
}
[\code]
|
|
|
|
|
Payam Rastogi wrote: I used this code but it is still showing error highlighting fThread.Interrupt() ---Object reference not set to an instance of an object.
Of course! fThread only exists inside your button43 Client handler. The variable can't be seen anywhere else in your code.
And why are you calling Interrupt?? Inside your looping thread code you would check for a flag that says it should stop. You shouldn't be abruptly stopping the thread before it can do any cleanup work it needs to.
|
|
|
|
|
This is always a problem with long running synchronous (blocking) event handlers.
The easiest way of the top of my head:
Add a background worker component and set WorkerSupportsCancellation to true then call RunWorkerAsync() in the button_Click event handler. Put the code above in the DoWork event handler, then you can check the CancellationPending on each iteration.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
How could I show the total interest paid and the average interest gained each year?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project1
{
class Program
{
public static void Main()
{
Console.Write("Enter principal: ");
decimal p = Convert.ToDecimal(Console.ReadLine());
if (p < 0)
{
Console.WriteLine("Principal cannot be negative");
p = 0;
}
Console.Write("Enter interest rate: ");
decimal i = Convert.ToDecimal(Console.ReadLine());
if (i < 0)
{
Console.WriteLine("Interest cannot be negative");
i = 0;
}
Console.Write("Enter time (in years): ");
int years = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPrincipal = " + p
+ "\nInterest = " + i + "%"
+ "\nTime = " + years + " years\n");
Console.WriteLine("\n\nYear\tRate\t Amount\tInterest\tNew Amount");
Console.WriteLine("===========================================================");
int year = 1;
while (year <= years)
{
decimal interestPaid = p * (i / 100);
decimal amount = p + interestPaid;
p += interestPaid;
p = decimal.Round(p, 2);
interestPaid = decimal.Round(interestPaid, 2);
amount = decimal.Round(amount, 2);
Console.WriteLine(year + "\t" + i + "%\t" + ((p - interestPaid).ToString().PadLeft(10)) + "\t" + interestPaid.ToString().PadLeft(8) + "\t" + p.ToString().PadLeft(8));
year++;
}
}
}
}
|
|
|
|
|
yes
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I don't think the other answer you got really fit the question.
ctreed728 wrote: How could I show the total interest paid and the average interest gained each year?
By referring to your course notes, talking to your teacher if you get stuck, stepping through the code if you need to, and breaking down the task into small steps you can turn into code.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Hi All,
I'm just working on a WPF desktop database app and I may have a scenario that I think could benefit from the occasional forced garbage collection. The only reason I'm really venturing down this path is that my user base are pretty savvy types and memory is *always* at a premium.
When the app starts up it's consuming around 50Mb of RAM nothing to complain about. However, during certain searches on the database this memory usage can escalate to 150Mb+. Say search 1 returns 60,000 records from the Db and in this scenario the memory jumps to 150Mb and a short time later another seach might only return a few hundred samples. I'm seeing the memory still at around the 150Mb mark whereas I want this to be immediately reduced to reflect the required RAM needed to represent that smaller search result set.
Is it worth exploring a forced GC.Collect() . I've been doing plenty of reading and it seems like the message is a little mixed on this. Some people seem to use it regularly, some say never use it. Microsoft seem to say leave it up to the CG to decide, but as I illustrated above I want to free that RAM as quickly as possible.
Thanks,
|
|
|
|